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

  • Release version: Washingtondc
  • Updated May 15, 2024
  • 1 minute to read
  • 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 1. 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 2. 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
      }
    }