createMessage method

  1. @override
Future<ChatwootMessage> createMessage(
  1. ChatwootNewMessageRequest request
)
override

Sends message to chatwoot inbox

Implementation

@override
Future<ChatwootMessage> createMessage(
    ChatwootNewMessageRequest request) async {
  try {
    final createResponse = await _dio.post(
        "/public/api/v1/inboxes/${ChatwootClientApiInterceptor.INTERCEPTOR_INBOX_IDENTIFIER_PLACEHOLDER}/contacts/${ChatwootClientApiInterceptor.INTERCEPTOR_CONTACT_IDENTIFIER_PLACEHOLDER}/conversations/${ChatwootClientApiInterceptor.INTERCEPTOR_CONVERSATION_IDENTIFIER_PLACEHOLDER}/messages",
        data: request.toJson());
    if ((createResponse.statusCode ?? 0).isBetween(199, 300)) {
      return ChatwootMessage.fromJson(createResponse.data);
    } else {
      throw ChatwootClientException(
          createResponse.statusMessage ?? "unknown error",
          ChatwootClientExceptionType.SEND_MESSAGE_FAILED);
    }
  } on DioException catch (e) {
    throw ChatwootClientException(
        e.message ?? "", ChatwootClientExceptionType.SEND_MESSAGE_FAILED);
  }
}