### shared
The central object for managing non-UI Kustomer chat related activities
## Listeners
All currently registered [`KUSChatListeners
`](🔗).
### addChatListener(_:)
Register a `KusChatListener
` to the Core SDK to receive chat events.
### removeChatListener(_:)
Unregister a [`KUSChatListener
`](🔗) using its unique `String
` identifier.
### removeAllChatListeners()
Removes all registered [`KUSChatListener
`](🔗)s from the Core SDK.
### listenForTyping(conversationId:)
Begins listening for typing events.
### stopListeningForTyping(conversationId:)
Stops listening for typing events.
## Reading data
### getConversations(completion:)
Fetch all conversations for the current customer. Warning: this function will eagerly fetch all conversations for the active user and may be slow to complete for users with a large conversation history. For more efficient loading use `getConversationPage
`.
### getConversationPage(page:pageSize:completion:)
Fetch a page of conversations for the current customer.
### getConversations()
This function is removed in version 2.7.0. Use `
getConversations(completion:)
` instead.
All conversations for the current customer.
Immediately returns last known list of conversations for the current customer from the SDK’s persistent offline storage.
### getConversation(conversationId:completion:)
Calls the completion with a `Result
` containing the `KUSConversation
` object for the given id in the success case, or an error in the failure case.
### getConversation(conversationId:)
This function is removed in version 2.7.0. Use `
getConversation(conversationId:completion:)
` instead.
Returns a `KUSConversation
` object for the given id. Returns nil if the ID is not found.
### chatMessages(conversationId:)
This function is removed in version 2.7.0. Use `
getChatMessages(conversationId:completion:)
` instead.
Immediately returns last known list of messages for a conversation. Use a KUSChatListener to be notified when new messages come in.
### getChatMessages(conversationId:completion:)
Gets the messages for a conversation using a network call to Pubnub history (up to 30 days).
### getHistoricChatMessages(conversationId:completion:)
Gets the messages for a conversation from Kustomer API. Warning: this function will eagerly fetch all pages of messages for the given conversation. To fetch messages in pages use `getChatMessagesBefore
`.
### getChatMessagesBefore(timestamp:conversationId:count:completion:)
Gets the chat messages for a conversation before a given timestamp. Note: the array of messages in the completion will be sorted in reverse chronological order.
### getInitialMessages(assistantId:startDialog:completion:)
Gets the initial messages for the active chat assistant, to be displayed right away. You can then call `createConversation
` to create a chat assistant conversation on the backend once the user replies to an initial message. The active assistant id and start dialog will be used if the parameters are not provided.
### getUnreadCount(completion:)
Fetches the unread count and calls the completion with a `Result
` containing the unread count in the success case or an error in the failure case. Use a KUSChatListener to be notified when the unread count changes.
### unreadCount()
This function is removed in version 2.7.0. Use `
getUnreadCount(completion:)
` instead.
Immediately returns the current customer’s unread count. Use a KUSChatListener to be notified when this changes.
### getOpenConversationCount(completion:)
Fetches the open conversation count and calls the completion with a `Result
` containing the count in the success case or an error in the failure case.
### openConversationCount()
This function is removed in version 2.7.0. Use `
getOpenConversationCount(completion:)
` instead.
### currentCustomer()
This function is removed in version 2.7.0 Use `
customerExists()
` instead.
Information about the current customer. Value is persisted across application restarts.
Is `nil
` if you have not successfully called `logIn(...)
` **and** there are no anonymous chats.
Anonymous chats are chats created by users who have not called `logIn(...)
`.
After `logOut(...)
` this becomes `nil
`.
### customerExists()
Returns `true
` if there is a current Customer (either anonymous or logged-in) in the Kustomer system.
### getChatSettings()
Returns chat settings. Does not attempt to load or update them from the REST API.
### isChatAvailable(_:)
Check the “turned on/off” status of your chat within Business Hours and outside of Holidays settings asynchronously. For example, if chat is turned off or outside of business hours, you may want to turn off the button or deflect customers to contact an email).
If you change your business hours or holidays in the admin panel, you must restart the app to see the new values.
## Writing data
### createConversation(firstCustomerMessage:completion:)
Creates a conversation with a message, action, mll node, image, or file url (one of these must be provided). Title and descriptors for the conversation can also be included.
### sendChatMessage(action:conversationId:completion:)
Reply to a message from a chat assistant using an action (action == a quick reply button)
### sendChatMessage(action:completion:)
This function is removed in version 2.7.0. Use `
sendChatMessage(action:conversationId:completion:)
` instead.
Reply to a message from a chat assistant using an action (action == a quick reply button)
### sendChatMessage(text:assistant:conversationId:completion:)
Sends a text message as a reply to a chat assistant question.
For non-conversational-assistant conversations, use `
sendChatMessage(text:String, conversationId:String, completion: @escaping ((KError?) -> Void))
` instead.
### sendChatMessage(text:assistant:completion:)
This function is removed in version 2.7.0. Use `
sendChatMessage(text:assistant:conversationId:completion:)
` instead.
Sends a text message as a reply to a chat assistant question.
### sendChatMessage(mllNode:conversationId:completion:)
Reply to a message from a chat assistant using an MLL node
### sendChatMessage(mllNode:completion:)
This function is removed in version 2.7.0. Use `
sendChatMessage(mllNode:conversationId:completion:)
` instead.
Reply to a message from a chat assistant using an MLL node
### sendChatMessage(image:conversationId:completion:)
Posts a message containing an image to a conversation.
### sendChatMessage(fileUrl:conversationId:completion:)
Posts a message containing a file or video to a conversation.
### createAssistant(id:after:error:afterCreateConversation:)
**Deprecated:** Use `
getInitialMessages
` to get the initial assistant messages to display, and `createConversation
` to create the conversation when the user responds to an initial assistant message. This function will not work as of version 2.7.0
Creates a new `KUSAssistant
`. Fetches the properties needed to use this assistant. Gets a list of `initialMessages
` that are the same format as `KUSChatMessage
`. A conversation (`KUSConversation
`) on our system (that shows up on the Kustomer website) is not created. A `KUSConversation
` is only created after you submit a message using this assistant.
### endConversation(conversationId:completion:)
Ends an existing conversation.
### reloadChatSettings(_:)
Reloads chat settings and business schedules from our REST API. If the network call fails, returns an error.
### describeConversation(conversationId:attributes:_:)
Attach custom attributes to the user’s most recent conversation (or the first one they create).
See [Describe Conversation](🔗).
These key-value pairs must be activated on the Conversation Klass via the admin portal. This can be done by an admin via **Settings > Platform Settings > Klasses > Conversation**.
Example:
### describeCurrentCustomer(phone: email:phones:emails:facebook:instagram:twitter:linkedIn:custom:_:)
Attach custom attributes to the customer.
See [Describe Customer](🔗).
Attached key-value pairs via the `
custom
` property must be enabled on the Customer Klass via the admin portal. This can be done by an admin via Settings > Platform Settings > Klasses > Customer, and works the same way as `describeConversation
`
### markRead(conversationId:)
Marks a conversation as read as of right now. Any message received for this conversation after this will be treated as unread, until marked read again. This function should be called whenever the user closes the chat view for a conversation.
### markRead(conversationId:messageIds)
Marks a conversation as read as of right now, and marks the message IDs as read so they show up as Seen on the agent timeline. Any message received for this conversation after this will be treated as unread, until marked read again. This function should be called in place of `markRead(conversationId:)
` to avoid redundant network calls when the IDs of the unread messages are known. For example, when a message arrives to an open conversation.
### submitSatisfactionForm(conversationSatisfactionId:)
Submits the user's response to a satisfaction form.
Parameter | Description |
`conversationSatisfactionId ` | ID for the CSAT item. This will be in the `KUSSatisfaction ` object passed in `onSatisfactionEventReceived `. |
`response ` | Holds the data to be submitted in response to the form. |
`conversationId ` | ID for the conversation associated with the CSAT. |
`completion ` | To be invoked on success or failure submitting the form |
## Identifying
See [Log in and authentication](🔗).
### identify(jwt:_:)
**Deprecated:**See [Log in and authentication](🔗).