Open conversation by id

Opens a conversation based on the conversationId.

You can open a conversation by the conversation id if the id is valid and belongs to a current customer in your Kustomer organization. If a conversation id is not valid, an error will be returned.

Kustomer.openConversation(id: "ID", completion: { result in
  switch result {
    case .success(let conversation):
      print(conversation.id)
    case .failure(let error):
      print(error)
  }
})

Use a callback with the conversation id

You can also use a callback to associate custom attributes with the conversation.

For example, you can open a new conversation and get a callback when the customer sends their first message as in the following:

Kustomer.openNewConversation(afterCreateConversation: { convo in
    print("Conversation \(convo.id) was created")
  }
)

Kustomer creates a new conversation after the customer sends their first message.

In the following example, we use the convo.id to associate custom attributes to that new conversation with describeConversation. The code displays initialMessages first. After the customer replies for the first time and creates a new conversation, the code automatically calls the afterCreateConversation callback.

Kustomer.openNewConversation(
   initialMessages: ["Hello!", "Welcome to a new chat!"],
   afterCreateConversation: { convo in
      // Describe the conversation
      Kustomer.chatProvider.describeConversation(conversationId: convo.id!, attributes: ["favoriteColorStr": "PINK"], { result in
         switch result {
           case .success:
             print("success")
           case .failure(let error):
             print(error.localizedDescription)
    }
  })})

📘

Use ChatProvider to add listeners for new conversations

You can also add listeners for newly created conversations within the SDK using ChatProvider from the Kustomer Core SDK.

To learn more, see Build your own UI.


Did this page help you?