KindlyChatClient

public final class KindlyChatClient : Loggable

iOS SDK for connecting and interacting with the Kindly Chat API.

  • Undocumented

    Declaration

    Swift

    public static var shared: KindlyChatClient!
  • Undocumented

    Declaration

    Swift

    public static var config: KindlySDKConfig { get set }
  • Undocumented

    Declaration

    Swift

    public static var connectionState: ChatConnectionState { get }
  • 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

  • The current state of the chat connection.

    Declaration

    Swift

    static var isChatDisplayed: Bool { get }
  • Undocumented

    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.

  • Undocumented

    Declaration

    Swift

    static var enableCrashReporting: Bool { get set }
  • Start the Kindly Chat SDK.

    Declaration

    Swift

    class func start(botKey: String, 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 with the provided language code, and presents it from the root view controller.

    Declaration

    Swift

    class func displayChat(languageCode: String?, triggerDialogueId: String? = nil)

    Parameters

    languageCode

    The language code to be used in the chat interface. If not provided, the default language will be used.

  • 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 with the provided language code, and presents it from the root view controller.

    Declaration

    Swift

    func displayChat(languageCode: String? = nil, triggerDialogueId: String? = nil)

    Parameters

    languageCode

    The language code to be used in the chat interface. If not provided, the default language will be used.

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

  • Undocumented

    Declaration

    Swift

    class func triggerDialogue(id: String)
  • 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

    public static func _forceConnectionState(_ state: ChatConnectionState)