Chat SDK API Documentation

Starting a chat session requires initializing the Chat with your Zendesk Chat API key, which can be found in the Chat dashboard. Ask a Chat admin for the key if you don’t have access to the dashboard. Starting a chat session takes the previously created ChatAPIConfig object containing the relevant Chat session information.

Using the providers

You must initialize the Chat instance before working with the Chat APIs. You can optionally preconfigure your chat setup via the ChatAPIConfiguration, and provide a queue to dispatch chat operations on (default is main queue).

Chat.initialize(accountKey: accountKey, queue: .main)

Once the Chat instance is initialized, you can start using the providers.

Using the UI Layer

You must also import the MessagingSDK and MessagingAPI, to leverage the ChatUI. The MessagingSDK allows Zendesk product SDKs to work seamlessly in a unified messaging interface. The MessagingSDK must be initialized with a product engine eg. the Chat Engine.

Once the MessagingSDK is initialized successfully, the conversation screen can be presented.

import ChatSDK
import ChatProvidersSDK
import MessagingSDK
import MessagingAPI

func presentUI() throws {
    let chatConfig = ChatConfiguration()
    chatConfig.isPreChatFormEnabled = true
    chatConfig.isOfflineFormEnabled = true

    let apiConfig = ChatAPIConfiguration()
    apiConfig.department = "department_id"
    apiConfig.visitorInfo = VisitorInfo(name: "name", email: "email@test.com", phoneNumber: "123456")

    // Initialize Chat instance
    Chat.initialize(accountKey: accountKey, queue: .main)
    Chat.instance?.configuration = apiConfig

    // Create UI Engine
    let chatEngine = try ChatEngine.engine()
    let vc = try Messaging.instance.buildUI(engines: [chatEngine], configs: [chatConfig])

    self.navigationController?.pushViewController(vc, animated: true)
}

Providers

ChatProvider

Provides methods for interacting with and retrieving information about the current session and active chat. For a complete list of of methods, see the ChatProvider class.

ConnectionProvider

Provides methods for connecting and observing the connection state of the chat sessions. For a complete list of ConnectionProvider methods, see the ConnectionProvider class.

ProfileProvider

Provides methods for interacting with the visitor profile, such as adding notes, tags, and visitorInfo. For a complete list of ProfileProvider methods, see the ProfileProvider class.

PushNotificationsProvider

Provides methods for interacting with push notifications and for registering and unregistering push notification token. For a complete list of PushNotificationProvider methods, see the PushNotificationsProvider class.

For more help on setting up Chat push notifications, see the help centre guide.

Models

Here is a breakdown of the important Chat models, that can be used throughout your app.

 Chat Log

The ChatLog models are models that are sent and received from the visitor. They can be observed through the chatProvider.observeChatState() method.

ChatLog Models

ChatLog Enums