BotsManager

public final class BotsManager : NSObject

This is the initialization point from where various services and public methods can be accessed. It initiates the services using the BotsConfiguration.

  • Set the class conforming to the BotsEventListener to this variable in order to receive the corresponding callbacks.

    Declaration

    Swift

    public weak var botsEventListener: BotsEventListener?
  • Set the class conforming to the BotsMessageServiceDelegate to this variable in order to modify message payloads using the delegate API.

    Declaration

    Swift

    public weak var delegate: BotsMessageServiceDelegate?
  • Set the class conforming to the SpeechEventListener to this variable in order to receive the corresponding callbacks.

    Declaration

    Swift

    public weak var speechEventListener: SpeechEventListener?
  • Set the class conforming to the AuthenticationTokenProvider to this variable in order to generate the authentication token when required.

    Declaration

    Swift

    public weak var authenticationTokenProvider: AuthenticationTokenProvider?
  • Returns the Version.

    Declaration

    Swift

    public let Version: String
  • The bots configuration settings for tha app.

    Declaration

    Swift

    public var botsConfiguration: BotsConfiguration? { get }
  • Returns a shared instance of BotsManager.

    Declaration

    Swift

    public class func shared() -> BotsManager

    Return Value

    a shared instance of BotsManager class.

  • Initializes sdk and establish connection with bot.

    Declaration

    Swift

    public func initialize(botsConfiguration: BotsConfiguration, completionHandler: @escaping (ConnectionStatus, Error?) -> ())

    Parameters

    botsConfiguration

    BotsConfiguration object with the required feature flag values.

    completionHandler

    A callback which is called after websocket connection/disconnection, with the ConnectionStatus and an Error? object if the websocket connection fails or disconnects.

  • Disables the SDK backend and removes the BotsViewController instance from the navigation controller. To enable the functioning of all API methods, the user is required to call the initialize method in BotsManager and also initialize a new BotsViewController instance to enable the SDK UI.

    Declaration

    Swift

    public func destroy()
  • Establish a connection to the chat server if not already made or if a new connection is to be made with new channel properties. If no explicit botsConfiguration object is passed, it will use the channel details from the one used during initialization of the SDK for establishing the connection.

    Declaration

    Swift

    public func connect(botsConfiguration: BotsConfiguration? = nil)
  • Disconnect an existing connection to chat server.

    Declaration

    Swift

    public func disconnect()
  • Sends post back message to bot.

    Declaration

    Swift

    public func sendPostback(actionObject: BotsAction)

    Parameters

    actionObject

    an object of a class which conforms to the BotsAction protocol like BotsUrlAction, BotsLocationAction, BotsCallAction, BotsPostbackAction

  • Declaration

    Swift

    public func submitForm(formData: BotsFormSubmissionMessagePayload)
  • Establish connection to the speech server and start recording user’s voice message.

    Declaration

    Swift

    public func startVoiceRecording()
  • Stops recording user’s voice message.

    Declaration

    Swift

    public func stopVoiceRecording()
  • Checks if the voice recording has started or not.

    Declaration

    Swift

    public func isRecording() -> Bool?

    Return Value

    true if the recording has started, false if it is not and nil if the SDK is not initialized.

  • Sends a text message to bot.

    Declaration

    Swift

    public func send(message: UserMessage)

    Parameters

    message

    an object of a class which conforms to the UserMessage protocol, which currently includes only UserTextMessage.

  • Sends the user typing status to chat server so that typing indicator can be shown on agent side.

    Declaration

    Swift

    public func sendUserTypingStatus(status: TypingStatus, text: String? = nil)

    Parameters

    text

    Text being typed by the user.

    text

    Text being typed by the user.

  • Sends a text message and metadata to bot

    Declaration

    Swift

    public func send(message: UserMessage, json: [String : Any])

    Parameters

    message

    an object of a class which conforms to the UserMessage protocol, which currently includes only UserTextMessage.

    json

    metadata to be sent to bot.

  • Sends user profile to bot.

    Declaration

    Swift

    public func updateUser(profile: [String : Any])

    Parameters

    profile

    user profile to be sent to the bot.

  • Declaration

    Swift

    public func sendDeviceToken(deviceToken: String)
  • Declaration

    Swift

    public func endChat()
  • Sends attachment to bot.

    Declaration

    Swift

    public func sendAttachment(message: BotsAttachmentMessage)

    Parameters

    message

    an object of the BotsAttachmentMessage class initialized with the attached file to be sent to bot.

  • Uploads attachment to chat server.

    Declaration

    Swift

    public func uploadAttachment(file: FileWrapper)

    Parameters

    file

    the attachment file in the form of a FileWrapper object to be uploaded to chat server.

  • Returns the list of conversation messages.

    Note

    the channelId and userId is set in the BotsConfiguration you have initially created.

    Declaration

    Swift

    public func getConversationHistory(userId: String, channelId: String) -> [Message]?

    Parameters

    userId

    the userId for which you want the list of conversations.

    channelId

    the channelId for the given userId for which you want the list of conversations.

    Return Value

    the list of Messages for the given userId and channelId

  • Saves a message to the app persistence store which can be accessed via the fetchData(userId: channelId: ) method. This method should only be utilized when using the app in headless mode, i.e. not using the SDK UI.

    Declaration

    Swift

    public func saveMessage(messagePayloadString: String, type: String, timeStamp: Date)

    Parameters

    messagePayloadString

    the messagePayload value of the conversation json payload.

    type

    a type variable to distinguish different type of messages so that it can be rendered in a certain way on the UI when accessed from the fetched method.

    timestamp

    the timestamp of the message.

  • Deletes all the conversation messages corresponding to a userId and channelId.

    Declaration

    Swift

    public func clearConversationHistory(userId: String, channelId: String)

    Parameters

    userId

    the userId for which you want to delete all the conversations.

    channelId

    the channelId for the given userId for which you want to delete all the conversations.

  • Dynamically injects a custom TTS service.

    Declaration

    Swift

    public func setTTSService(ttsService: TTSService)

    Parameters

    ttsService

    instance of class conforing to TTSService protocol

  • Speaks the passed text

    Declaration

    Swift

    public func speakTTS(text: String)

    Parameters

    text

    the text to be spoken

  • Parses and speaks the content of the passed Message

    Declaration

    Swift

    public func speakTTS(message: BotsMessage)

    Parameters

    message

    the skill message to be spoken

  • Cancels any ongoing TTS utterance

    Declaration

    Swift

    public func cancelTTS()
  • Returns whether any active TTS is being performed

    Declaration

    Swift

    public func isTTSSpeaking() -> Bool

    Return Value

    true if bot audio response is ongoing, false otherwise.

  • Speaks the passed text

    Declaration

    Swift

    @available(*, deprecated, renamed: "speakTTS")
    public func startSpeechSynthesis(text: String)

    Parameters

    text

    the text to be spoken

  • Parses and speaks the content of the passed Message

    Declaration

    Swift

    @available(*, deprecated, renamed: "speakTTS")
    public func startSpeechSynthesis(message: BotsMessage)

    Parameters

    message

    the skill message to be spoken

  • Cancels any ongoing TTS utterance

    Declaration

    Swift

    @available(*, deprecated, renamed: "cancelTTS")
    public func stopSpeechSynthesis()
  • Returns whether any active TTS is being performed

    Declaration

    Swift

    @available(*, deprecated, renamed: "isTTSSpeaking")
    public func isSpeaking() -> Bool

    Return Value

    true if bot audio response is ongoing, false otherwise.

  • Gives the current connection status

    Declaration

    Swift

    public func getConnectionStatus() -> ConnectionStatus?

    Return Value

    a ConnectionStatus object among .connecting, .connected, .disconnected, and nil if the SDK is not initialized.

  • Sets the primary chat language. Detect langauge is set if “und” is passed as primary language.

    Declaration

    Swift

    public func setPrimaryLanguage(primaryLanguage: String?)

    Parameters

    primaryLanguage

    The language tag to be set as primary language. This must be among the supported languages.

  • Sets the speech locale

    Declaration

    Swift

    public func setSpeechLocale(locale: String)

    Parameters

    locale

    the locale string to which you want to set as the speech locale.

  • Sets the speechSynthesisVoicePreferences

    Declaration

    Swift

    public func setSpeechSynthesisVoicePreferences(speechSynthesisVoicePreferences: [SpeechSynthesisVoice])

    Parameters

    speechSynthesisVoices

    the locale string to which you want to set as the speech locale. Takes a preference list of the (language-locale, voice_name) pair for the voice for speech synthesis. For eg. (“en-US”, “Fred”). First, an exact match is searched for the pair of language-locale and voice name. If no match is find found, then the Apple API tries to find the best match voice for the given locale. If no preference is provided, the default voice would be used.

  • Updates the share menu item list. If nothing is passed, the existing share menu items are returned in the form of a tuple. If a tuple of available menu items and custom items is passed, it is updated in the configuration settings and nil is returned.

    Declaration

    Swift

    public func shareMenuItems(shareMenuItems: ([ShareMenuItem], [ShareMenuCustomItem])? = nil) -> ([ShareMenuItem], [ShareMenuCustomItem])?

    Parameters

    shareMenuItems

    the tuple of the list of available menu items and custom menu items to be displayed in the share menu.

    Return Value

    the existing share menu configuration tuple if no input is passed, nil otherwise.