Skip to main content
Version: 5.9.0

Displaying the chat

User authorization

Before opening the chat, authorize the user:

var chatUser = ChatUser(identifier: "Identifier", name: "Full name")

chatCenterSDK.authorize(user: chatUser)
Additional user data

If the data is known upfront, pass it to the constructor: ChatUser(identifier:name:data:) accepts data: [String: String]? for display in the operator workplace.

If the data becomes known later, update it via chatUser.updateData(data:). The method is marked mutating, so chatUser must be declared as var. See User management for details.

Custom authorization

For integrations with a custom authorization mechanism, authorize accepts a second parameter auth: ChatAuth (default — ChatAuth()). The parameters are agreed during integration — see User management.

identifier requirements

The identifier must be unique, permanent and resistant to guessing — avoid using phone numbers, emails or other identifiers that uniquely identify the user. If you have to use them, strictly apply RSA encryption.

For questions, contact support@edna.io

Message prefill (optional)

Before opening the chat, you can set text to be prefilled in the input field:

chatCenterSDK.prefill(message: "Question about order #12345")

The text is inserted once on the next call to getChat().

Opening the chat

Get the chat controller via getChat() — it throws, so call it inside do/catch:

do {
let chatController = try chatCenterSDK.getChat()
navigationController?.pushViewController(chatController, animated: true)
} catch {
// In a real app, use your own logger instead of print
print("Failed to open chat: \(error)")
}

Alternative using Result for separate success/failure handling:

let result = Result { try chatCenterSDK.getChat() }

switch result {
case let .success(chatController):
navigationController?.pushViewController(chatController, animated: true)
case let .failure(error):
// Error handling (e.g., user not authorized)
print("error: \(error)")
}

Opening on push notification

getChat(userInfo:) accepts a push notification payload and opens the chat bound to it:

do {
let chatController = try chatCenterSDK.getChat(userInfo: pushUserInfo)
navigationController?.pushViewController(chatController, animated: true)
} catch {
print("Failed to open chat: \(error)")
}

The full push handling scenario (including the case when the chat is already displayed) is in Notifications.

Each getChat() call returns a new controller

The SDK creates a new UIViewController on every call. Do not call getChat() again for an already-displayed screen — the new controller becomes the active receiver of updates, and the old one stops receiving events.

Navigation is inherited from the container

Navigation elements in the chat are taken from the parent container, so place the controller inside its own UINavigationController (or create a dedicated one for the chat screen).

What's next