createNewConversation method

  1. @override
Future<SolevatoConversation> 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<SolevatoConversation> createNewConversation(
    String inboxIdentifier, String contactIdentifier) async {
  try {
    CancelToken cancelToken = CancelToken();

    final createResponse = await _dio.post(
        "/public/api/v1/inboxes/$inboxIdentifier/contacts/$contactIdentifier/conversations",
        cancelToken: cancelToken);

    if ((createResponse.statusCode ?? 0).isBetween(199, 300)) {
      //creating contact successful continue with request
      final newConversation =
          SolevatoConversation.fromJson(createResponse.data);
      return newConversation;
    } else {
      throw SolevatoClientException(
          createResponse.statusMessage ?? "unknown error",
          SolevatoClientExceptionType.CREATE_CONVERSATION_FAILED);
    }
  } on DioError catch (e) {
    throw SolevatoClientException(
        e.message, SolevatoClientExceptionType.CREATE_CONVERSATION_FAILED);
  }
}