createNewConversation method

  1. @override
Future<ChatwootConversation> createNewConversation(
  1. String inboxIdentifier,
  2. String contactIdentifier
)
override

Creates a new conversation for inbox with inboxIdentifier and contact with source id contactIdentifier

Implementation

@override
Future<ChatwootConversation> createNewConversation(
    String inboxIdentifier, String contactIdentifier) async {
  try {
    final createResponse = await dio.post(
        "/public/api/v1/inboxes/$inboxIdentifier/contacts/$contactIdentifier/conversations");
    if ((createResponse.statusCode ?? 0).isBetween(199, 300)) {
      //creating contact successful continue with request
      final newConversation =
          ChatwootConversation.fromJson(createResponse.data);
      return newConversation;
    } else {
      throw ChatwootClientException(
          createResponse.statusMessage ?? "unknown error",
          ChatwootClientExceptionType.CREATE_CONVERSATION_FAILED);
    }
  } on DioError catch (e) {
    throw ChatwootClientException(
        e.message, ChatwootClientExceptionType.CREATE_CONVERSATION_FAILED);
  }
}