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 }

Initialization

  • 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

    config

    API keys and other configuration of type KindlySDKConfig.

Public functions

  • 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().delegate to 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

    theme

    The theme to be applied to the chat. This theme will override any theme retrieved from Kindly’s settings.

  • 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

    background

    Background color for the chat interface.

    botMessageBackground

    Background color for bot message bubbles.

    botMessageText

    Text color for bot messages.

    buttonBackground

    Background color for buttons.

    buttonOutline

    Outline color for buttons.

    buttonSelectedBackground

    Background color for selected buttons.

    buttonText

    Text color for buttons.

    defaultShadow

    Default shadow color.

    inputBackground

    Background color for the input field.

    inputCursor

    Color for the input cursor.

    inputText

    Text color for the input field.

    navBarBackground

    Background color for the navigation bar.

    navBarText

    Text color for the navigation bar.

    userMessageBackground

    Background color for user message bubbles.

    userMessageText

    Text 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

    languageCode

    Optional language code to use for this chat session. If provided, it will override the language set during SDK start.

    triggerDialogueId

    Optional 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

    languageCode

    Optional language code to use for this chat session. If provided, it will override the language set during SDK start.

    triggerDialogueId

    Optional 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

    languageCode

    The 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

    context

    context 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

    context

    context 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

    deviceToken

    The device token to be set. It is of type Data.

  • Sets the device token.

    Declaration

    Swift

    class func setAPNSDeviceToken(_ deviceToken: String)

    Parameters

    deviceToken

    The 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) -> Bool

    Parameters

    token

    The authentication token to be saved.

  • Saves the authentication token in the Keychain.

    Declaration

    Swift

    @discardableResult
    func saveAuthToken(_ token: String) -> Bool

    Parameters

    token

    The 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

    userInfo

    The user information dictionary that contains data related to the notification.

  • Handles the received notification.

    Declaration

    Swift

    class func notificationReceived(_ notification: UNNotification)

    Parameters

    notification

    The notification that was received.

  • Handles the received notification response.

    Declaration

    Swift

    class func notificationResponseReceived(_ response: UNNotificationResponse)

    Parameters

    response

    The notification response that was received.

  • Checks if the notification is from Kindly.

    Declaration

    Swift

    class func isKindlyNotification(_ userInfo: [AnyHashable : Any]) -> Bool

    Parameters

    userInfo

    The 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

    id

    The dialogue ID to trigger.

  • Handles a Kindly deep link URL. Supported format: kindly://chat/dialogue/{id}

    Declaration

    Swift

    @discardableResult
    class func handleURL(_ url: URL) -> Bool

    Parameters

    url

    The URL to handle.

    Return Value

    true if the URL was recognized and handled, false otherwise.

  • Undocumented

    Declaration

    Swift

    class func play()

Internal Testing Methods (Not exposed to clients)

  • 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)