UnbluVisitorApi

public class UnbluVisitorApi : UnbluCoreApi

The API to use to access unblu suite functionality like showing, opening conversations

Before calling any other function #configureApi should be called inside the AppDelegate.

Use the constants of UnbluEventApi to register for events and access their user info data

A typical flow for the usage would be:

AppDelegate#application() {
   UnbluVisitorApi.instance.configureApi(UnbluApiConfiguration(unbluBaseUrl: "<base-url>", apiKey: "<apiKey>"))

   //register for general errors and/or also other events
   NotificationCenter.default.addObserver(self, selector: #selector(AppDelegate.handleErrorEvent(notification:)), name: Notification.Name.UnbluError, object: nil)

   //start the api. This could also be done later when it is needed, but it will take a while until the api is ready
   UnbluVisitorApi.instance.initApi(success: {<success handling>}, failure: {<error handling>})
}
SomeViewController#showConversations() {
   //the conversations should be shown
   UnbluVisitorApi.instance.showUi(visible: true)
}
  • The instance of the UnbluVisitorApi

    Declaration

    Swift

    public static let instance: UnbluVisitorApi
  • Starts a new conversation with the given conversation type. If the UI was already shown, it will open the conversation in the UI. If it was not, a call to #showUi is needed to show the conversation.

    This is an asynchronous call. Use the callbacks to check for success / failure.

    Declaration

    Swift

    public func startConversation(conversationType: ConversationType, success: ((String) -> Void)? = nil, failure: ((UnbluApiInitConversationError) -> Void)? = nil)

    Parameters

    conversationType

    The initial type of the new conversation.

    success

    Optional callback that will be called with the conversationId after the conversation was started and is display (if there is a UI).

    failure

    Optional callback if there was problem to start the conversation.

  • Joins an unblu co-browsing session that was started by an agent. This is an asynchronous call. Use the callbacks to check for success / failure.

    Declaration

    Swift

    public func joinConversation(pin: String, success: ((String) -> Void)? = nil, failure: ((UnbluApiInitConversationError) -> Void)? = nil)

    Parameters

    pin

    The pin of the conversation which shall be joined. (The pin is provided by the agent desk.)

    success

    Optional callback that will be called with the conversationId once the conversation was successfully joined.

    failure

    Optional callback that will be called if the conversation could not be joined.

  • Checks if at least one agent is available for co-browsing / chat.

    This is an asynchronous call. Use the callbacks to check for success / failure.

    Declaration

    Swift

    public func isAgentAvailable(success: @escaping ((Bool) -> Void), failure: ((UnbluApiNotInitializedError) -> Void)? = nil)

    Parameters

    success

    Callback that will be called with true if at least one agent is available, false otherwise.

    failure

    Optional callback that will be called on failure.