sendMessage method
Implementation
@override
Future<ChatMessage> sendMessage(ChatMessage message) async {
var jsonData = {
"participants": ["U78853", "H4040"],
"conversationId": "61436",
"mimeType": "text/plain",
"body": message.body,
"sender": "U78853",
"trackId": message.trackId,
"type": "conversation",
"clientId": "U78853-E970F891-096A-4ECD-B0E3-08FB2C787FA3",
};
print(jsonData);
try {
final response = await _api.postWithHeaders(
AppRoutes.sendMessage, jsonData,
token:
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjY1MDE1LCJpYXQiOjE3MzcwMDQyMzJ9.GnAHuyeMLOn5oJj8pT51a9mV8S6c4zEZs6cohmRKuGw");
print(response.data);
return message;
} on DioException catch (e) {
if (e.response?.statusCode == HttpStatus.badRequest) {
final errorData = e.response!.data;
final errorMessage = errorData['message'] ?? 'An error occurred';
throw BadRequest(errorMessage);
} else {
throw Exception(e.message);
}
}
}