NowChatOptions - iOS

  • Release version: Xanadu
  • Updated August 1, 2024
  • 2 minutes to read
  • The NowChatOptions class enables you to configure options, such as showing a prompt before closing a chat window or disable features while using chat, on a chat session.

    NowChatOptions - ClosePrompt(header: String?, message: String, acceptButtonTitle: String, declineButtonTitle: String)

    Creates and returns a ClosePrompt object based on the passed parameters. You then pass this object into the NowChatOptions() method to configure the close prompt options within a chat session.

    Table 1. Parameters
    Name Type Description
    header String Text to display on the prompt's header.

    If you don't want to display a prompt header, pass "nil".

    message String Text to display as the prompt's main text.
    acceptButtonTitle String Text to display on the prompt's primary button for closing the chat window.
    declineButtonTitle String Text to display on the prompt's secondary button that dismisses the prompt.

    The following code example shows how to call this function.

    func makeChatScreen() -> UIViewController? {
      guard let chatService = chatService else { return nil }
      let closePrompt = NowChatOptions.ClosePrompt(
        header: "Close Window",
        message: "Are you sure you want to close the chat window?",
        acceptButtonTitle: "Yes",
        declineButtonTitle: "No")
    
      let disabledFeatures = [.startNewConversation]
        
      let chatOptions = NowChatOptions(closePrompt: closePrompt,
        disabledFeatures: disabledFeatures,
        forceNewConversation: true)
        
      let result = chatService.makeChatUI(theme: CarrascoChatTheme(chatColors: ChatColors()), chatOptions: chatOptions)
        
      switch result {
      case .success(let chatViewController):
        return chatViewController
      case .failure(let error):
        return nil
      }
    }

    NowChatOptions - NowChatOptions(closePrompt: ClosePrompt?, disabledFeatures: [Feature]?, forceNewConversation: Bool)

    Configures options for the current chat session. This method enables you to show a prompt before closing a chat window, disable features while using chat, and force a new chat conversation when the chat service starts.

    Table 2. Parameters
    Name Type Description
    closePrompt ClosePrompt object Prompt to display before closing the associated chat window.

    If you don't want to display a close prompt, pass "nil".

    disabledFeatures [Feature] List of chat features to disable within the current chat session.
    Valid value:
    • startNewConversation: Hide/disable the StartNew Conversation button that appears in a chat window.

    The available chat features are defined in the NowChatOptions.Feature enum class.

    If you don't want to disable any features, pass "nil".

    forceNewConversation Boolean Flag that indicates whether to force a new chat conversation when the chat session starts. Any current conversations are closed.
    Valid values:
    • true: Start a new chat conversation; a new chat window opens.
    • false: Don't start a new chat conversation; use the existing chat window.

    Default: false

    Table 3. Returns
    Type Description
    chatOptions Returns a chatOptions object that you can pass in the NowChatService - makeChatUI(theme: NowChatThemeable, chatOptions: NowChatOptions? = nil) -> Result<UIViewController, NowChatServiceError>) method.

    The following code example shows how to call this function.

    func makeChatScreen() -> UIViewController? {
      guard let chatService = chatService else { return nil }
      let closePrompt = NowChatOptions.ClosePrompt(
        header: "Close Window",
        message: "Are you sure you want to close the chat window?",
        acceptButtonTitle: "Yes",
        declineButtonTitle: "No")
    
      let disabledFeatures = [.startNewConversation]
        
      let chatOptions = NowChatOptions(closePrompt: closePrompt,
        disabledFeatures: disabledFeatures,
        forceNewConversation: true)
        
      let result = chatService.makeChatUI(theme: CarrascoChatTheme(chatColors: ChatColors()), chatOptions: chatOptions)
        
      switch result {
      case .success(let chatViewController):
        return chatViewController
      case .failure(let error):
        return nil
      }
    }