sendMessage method

  1. @override
Future sendMessage({
  1. required String message,
  2. dynamic args,
})
override

This method will be used to send the message to the external service and return the message to the application.

Implementation

@override
Future sendMessage({required String message, args}) async {
  final url =
      "$_url/public/api/v1/inboxes/$_inbox_identifier/contacts/$_contact_identifier/conversations/$_conversation_id/messages";
  logger.d("Sending message: $url");
  final response = await http.post(
    Uri.parse(url),
    headers: {
      "Content-Type": "application/json",
    },
    body: jsonEncode({
      "content": message,
    }),
  );

  if (response.statusCode == 200) {
    return jsonDecode(response.body);
  } else {
    throw Exception('Failed to load message');
  }
}