KindlyChatClient
public final class KindlyChatClient : Loggable
iOS SDK for connecting and interacting with the Kindly Chat API.
-
The shared singleton instance of the Kindly Chat SDK. Available after calling
start().Declaration
Swift
public static var shared: KindlyChatClient! -
The SDK configuration for permissions, auth callbacks, and form settings.
Declaration
Swift
public static var config: KindlySDKConfig { get set } -
The current connection state of the SDK.
Declaration
Swift
public static var connectionState: ChatConnectionState { get } -
Whether the input field is currently hidden
Declaration
Swift
public static var inputFieldHidden: Bool { get set } -
A static delegate that gets or sets the delegate of the shared instance of
KindlyChatClient.Declaration
Swift
public static var delegate: KindlyChatClientDelegate! { get set }
-
Initialize Kindly Chat SDK.
In most cases, you will only want to have one instance of
KindlyChatClient. Our “Getting started” guide covers this topic and gives you instructions on how to configure the SDK.Declaration
Swift
public init(config: CoreSDKConfig, behaviorType: BehaviorTypeEnum)Parameters
configAPI keys and other configuration of type
KindlySDKConfig.
-
Unified event publisher for all Kindly events (matches web API pattern) Subscribe to this to receive all events: load, message, buttonClick, ui, state
Declaration
Swift
static var events: AnyPublisher<KindlyEvent, Never> { get } -
Unified state publisher that emits state change events Subscribe to this to get real-time updates of: isChatDisplayed, isConnected, isStarted, isSocketConnected
Declaration
Swift
static var state: AnyPublisher<KindlyEventState, Never> { get } -
The shared notification delegate for handling Kindly push notifications. Assign this to
UNUserNotificationCenter.current().delegateto let the SDK process incoming notifications.Declaration
Swift
static var notificationDelegate: NotificationDelegate { get } -
The current state of the SDK.
Declaration
Swift
static var verboseLogging: Bool { get set } -
Sets a custom theme for the chat.
Declaration
Swift
static func setCustomTheme(_ theme: Theme)Parameters
themeThe theme to be applied to the chat. This theme will override any theme retrieved from Kindly’s settings.
-
setCustomTheme(background:botMessageBackground: botMessageText: buttonBackground: buttonOutline: buttonSelectedBackground: buttonText: defaultShadow: inputBackground: inputCursor: inputText: navBarBackground: navBarText: userMessageBackground: userMessageText: ) Sets a custom theme for the chat using the CustomTheme struct.
Declaration
Swift
static func setCustomTheme( background: UIColor? = nil, botMessageBackground: UIColor? = nil, botMessageText: UIColor? = nil, buttonBackground: UIColor? = nil, buttonOutline: UIColor? = nil, buttonSelectedBackground: UIColor? = nil, buttonText: UIColor? = nil, defaultShadow: UIColor? = nil, inputBackground: UIColor? = nil, inputCursor: UIColor? = nil, inputText: UIColor? = nil, navBarBackground: UIColor? = nil, navBarText: UIColor? = nil, userMessageBackground: UIColor? = nil, userMessageText: UIColor? = nil )Parameters
backgroundBackground color for the chat interface.
botMessageBackgroundBackground color for bot message bubbles.
botMessageTextText color for bot messages.
buttonBackgroundBackground color for buttons.
buttonOutlineOutline color for buttons.
buttonSelectedBackgroundBackground color for selected buttons.
buttonTextText color for buttons.
defaultShadowDefault shadow color.
inputBackgroundBackground color for the input field.
inputCursorColor for the input cursor.
inputTextText color for the input field.
navBarBackgroundBackground color for the navigation bar.
navBarTextText color for the navigation bar.
userMessageBackgroundBackground color for user message bubbles.
userMessageTextText color for user messages.
-
Clears any custom theme that has been set and reverts to the API theme or default theme.
Declaration
Swift
static func clearCustomTheme() -
Whether the SDK should send crash reports via Sentry. Defaults to
true.Declaration
Swift
static var enableCrashReporting: Bool { get set } -
Start the Kindly Chat SDK. The SDK will automatically use .native behavior for optimal performance and compliance.
Declaration
Swift
class func start(botKey: String, languageCode: String = "en", authTokenCallback: AuthTokenCallback? = nil) -
This function is used to display the chat interface. It first checks if there is a key window available, and if there is a root view controller. If both conditions are met, it creates a new instance of KindlyChatNavigationController.
Declaration
Swift
class func displayChat(languageCode: String? = nil, triggerDialogueId: String? = nil)Parameters
languageCodeOptional language code to use for this chat session. If provided, it will override the language set during SDK start.
triggerDialogueIdOptional dialogue ID to trigger after connection.
-
This function is used to display the chat interface. It first checks if there is a key window available, and if there is a root view controller. If both conditions are met, it creates a new instance of KindlyChatNavigationController.
Declaration
Swift
func displayChat(languageCode: String? = nil, triggerDialogueId: String? = nil)Parameters
languageCodeOptional language code to use for this chat session. If provided, it will override the language set during SDK start.
triggerDialogueIdOptional dialogue ID to trigger after connection.
-
Update the language for the current SDK session. This will be used for all subsequent chat connections.
Declaration
Swift
class func setLanguage(_ languageCode: String) -> Promise<Void>Parameters
languageCodeThe language code to use (e.g., “en”, “lt”, “sv”)
Return Value
Promise that resolves when language change is complete
-
Set the current context that will be set in the next message or click request
Declaration
Swift
class func setNewContext(_ context: [String : String])Parameters
contextcontext to be set
-
Set the current context that will be set in the next message or click request
Declaration
Swift
func setNewContext(_ context: [String : String])Parameters
contextcontext to be set
-
Clear the currently set context
Declaration
Swift
class func clearNewContext() -
Clear the currently set context
Declaration
Swift
func clearNewContext() -
Sets the device token.
Declaration
Swift
class func setAPNSDeviceToken(_ deviceToken: Data)Parameters
deviceTokenThe device token to be set. It is of type Data.
-
Sets the device token.
Declaration
Swift
class func setAPNSDeviceToken(_ deviceToken: String)Parameters
deviceTokenThe device token to be set. It is of type String.
-
Saves the authentication token in the Keychain.
Declaration
Swift
@discardableResult class func saveAuthToken(_ token: String) -> BoolParameters
tokenThe authentication token to be saved.
-
Saves the authentication token in the Keychain.
Declaration
Swift
@discardableResult func saveAuthToken(_ token: String) -> BoolParameters
tokenThe authentication token to be saved.
-
This function is used to close the chat by dismissing the kindlyChatNavigationController.
Declaration
Swift
class func closeChat() -
This function is used to close the chat by dismissing the kindlyChatNavigationController.
Declaration
Swift
func closeChat() -
Ends the active chat session.
Messages, token and current connection will be cleared. This will call the “user left” API in Kindly Chat.
Note
Please note that the Chat UI will be dismissed after using this function.Declaration
Swift
class func endChat() -> Promise<Void> -
Completely kills the SDK and clears all state. After calling this method, start() must be called again before using any other SDK functions. This is more destructive than endChat() which only disconnects the chat session.
Declaration
Swift
class func kill() -> Promise<Void> -
Ends the active chat session.
Messages, token and current connection will be cleared. This will call the “user left” API in Kindly Chat.
Note
Please note that the Chat UI will be dismissed after using this function.Declaration
Swift
func endChat() -> Promise<Void> -
Handles the received notification.
Declaration
Swift
class func notificationReceived(_ userInfo: [AnyHashable : Any])Parameters
userInfoThe user information dictionary that contains data related to the notification.
-
Handles the received notification.
Declaration
Swift
class func notificationReceived(_ notification: UNNotification)Parameters
notificationThe notification that was received.
-
Handles the received notification response.
Declaration
Swift
class func notificationResponseReceived(_ response: UNNotificationResponse)Parameters
responseThe notification response that was received.
-
Checks if the notification is from Kindly.
Declaration
Swift
class func isKindlyNotification(_ userInfo: [AnyHashable : Any]) -> BoolParameters
userInfoThe user information dictionary from the notification.
Return Value
A boolean indicating whether the notification is from Kindly.
-
Triggers a specific dialogue by its ID. The SDK must be connected before calling this method.
Declaration
Swift
class func triggerDialogue(id: String)Parameters
idThe dialogue ID to trigger.
-
Handles a Kindly deep link URL. Supported format:
kindly://chat/dialogue/{id}Declaration
Swift
@discardableResult class func handleURL(_ url: URL) -> BoolParameters
urlThe URL to handle.
Return Value
trueif the URL was recognized and handled,falseotherwise. -
Undocumented
Declaration
Swift
class func play()
-
Force a connection state for testing purposes. This method is only available in DEBUG builds.
Warning
This is for internal testing only and should never be used in production.Declaration
Swift
static func _forceConnectionState(_ state: ChatConnectionState)
View on GitHub