createNewContact method

  1. @override
Future<ChatwootContact> createNewContact(
  1. String inboxIdentifier,
  2. ChatwootUser? user
)
override

Creates new contact for inbox with inboxIdentifier and passes user body to be linked to created contact

Implementation

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