NowChatConfiguration - Android

  • Release version: Xanadu
  • Updated August 1, 2024
  • 5 minutes to read
  • The NowChatConfiguration class enables you to configure options on a chat session, such as showing a prompt before closing a chat window, disabling features while using chat, applying different conversation options when using chat, and configuring UI components in NowChat.

    NowChatConfiguration - AttachmentUploadButton(isVisible: Boolean = true)

    Defines the UI configurations to apply to the upload attachment button that appears next to the text input while talking with a live agent.

    AttachmentUploadButton is a subclass of the NowChatConfiguration class.

    Table 1. Parameters
    Name Type Description
    isVisible Boolean Flag that indicates the visibility of the upload attachment button.
    Valid values:
    • true: Upload attachment button is visible.
    • false: Upload attachment button is hidden.

    Default: true

    Table 2. Returns
    Type Description
    Object UI configuration object.

    The following code example shows how to hide the AttachmentUploadButton.

    suspend fun launchChat() {
      val chatService = getNowChatService()
    
      val chatConfiguration = NowChatConfiguration(
        uiConfiguration = NowChatConfiguration.UIConfiguration(
          attachmentUploadButton = NowChatConfiguration.AttachmentUploadButton(isVisible = false)
        )
      )
     
      chatService?.start(activity, chatConfiguration)
    }

    NowChatConfiguration - CloseButton(icon: Drawable?)

    Defines the configuration of the close button used for back navigation on the NowChat toolbar. You then pass this object into the NowChatConfiguration() method to configure the close button to use within the chat session.

    CloseButton() is a subclass of the NowChatConfiguration class.

    Table 3. Parameters
    Name Type Description
    icon Drawable? Drawable object to use for the close (back) button.

    You can use the ContextCompat.getDrawable() method to obtain this drawable object.

    For example:
    val myDrawable = ContextCompat.getDrawable(activity, R.drawable.my_drawable)

    To use the default drawable, pass null.

    Default: NowChat back button

    Table 4. Returns
    Type Description
    Object Close button configuration object.

    The following code example shows how to set a custom icon for the close button on the NowChat toolbar.

    suspend fun launchChat() {
      val chatService = getNowChatService()
     
      //Drawable to use instead of the default NowChat back button.
      val myDrawable = ContextCompat.getDrawable(activity, R.drawable.my_drawable)
    
      val chatConfiguration = NowChatConfiguration(
        uiConfiguration = NowChatConfiguration.UIConfiguration(
          closeButton = NowChatConfiguration.CloseButton(
            icon = myDrawable
          )
        )
      )
    
      chatService?.start(activity, chatConfiguration)
    }

    NowChatConfiguration - UIConfiguration(closeButton: CloseButton? = null, attachmentUploadButton: AttachmentUploadButton? = null)

    Creates and returns a UIConfiguration object based on the passed parameters. You then pass this object into the NowChatConfiguration() constructor to configure UI components in NowChat.

    UIConfiguration is a subclass of the NowChatConfiguration class.

    Table 5. Parameters
    Name Type Description
    closeButton CloseButton? Configuration for the CloseButton that appears on the NowChat toolbar and is used for back navigation.

    Call the NowChatConfiguration - CloseButton(icon: Drawable?) subclass to define the value of this parameter.

    For example:
    val chatConfiguration = NowChatConfiguration( 
      uiConfiguration = NowChatConfiguration.UIConfiguration( 
        closeButton = NowChatConfiguration.CloseButton( 
          icon = myDrawable
      )
    )
    attachmentUploadButton AttachmentUploadButton? Configuration for the AttachmentUploadButton that is shown next to the text input while talking with a live agent.

    Call the NowChatConfiguration - AttachmentUploadButton(isVisible: Boolean = true) subclass to define the value of this parameter.

    For example:
    val chatConfiguration = NowChatConfiguration( 
      uiConfiguration = NowChatConfiguration.UIConfiguration(
        attachmentUploadButton = NowChatConfiguration.AttachmentUploadButton(isVisible = false)
      ) 
    )
    Table 6. Returns
    Type Description
    Object UI configuration object.

    The following code example shows how to call the UIConfiguration subclass to set the icon for the closeButton and to hide the attachment upload button.

    suspend fun launchChat() {
      val chatService = getNowChatService() 
         
      //Drawable to use instead of the default NowChat back button. 
      val myDrawable = ContextCompat.getDrawable(activity, R.drawable.my_drawable) 
     
      val chatConfiguration = NowChatConfiguration( 
        uiConfiguration = NowChatConfiguration.UIConfiguration( 
          closeButton = NowChatConfiguration.CloseButton( 
            icon = myDrawable 
          ), 
          attachmentUploadButton = NowChatConfiguration.AttachmentUploadButton(isVisible = false)
        ) 
      ) 
     
      chatService?.start(activity, chatConfiguration) 
    } 

    NowChatConfiguration - NowChatConfiguration(closePrompt: ClosePrompt? = null, disabledFeatures: List<Feature>? = null, conversationOptions: List<ConversationOption>? = null, uiConfiguration: UIConfiguration? = null)

    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, apply different conversation options when using chat, and configure UI components in NowChat.

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

    Call the NowChatConfiguration.ClosePrompt() subclass to define the value of this parameter.

    For example:
    closePrompt = NowChatConfiguration.ClosePrompt(
      header = null,
      message = "Are you sure you want to leave?",
      acceptButtonTitle = "Yes",
      declineButtonTitle = "No"
    )

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

    disabledFeatures List<NowChatConfiguration.

    Feature>

    List of chat features to disable within the current chat session.

    Valid value:

    START_NEW_CONVERSATION: Hide/disable the StartNew Conversation button that appears in a chat window.

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

    For example:
    disabledFeatures = listOf(NowChatConfiguration.Feature.START_NEW_CONVERSATION)

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

    conversationOptions List<Conversation

    Option>?

    List of conversation options to apply to NowChat.
    Valid values:
    • END_CONVERSATION_ON_EXIT: Ongoing conversation is terminated when exiting the NowChat window.
    • FORCE_NEW_CONVERSATION: Forces a new chat conversation when NowChat starts.

    The available conversation options are defined in the NowChatConfiguration.ConversationOption enum class.

    For example:
    conversationOptions = listOf(NowChatConfiguration.ConversationOption.FORCE_NEW_CONVERSATION),

    If you don't want to apply any options, pass null.

    uiConfiguration UIConfiguration? UIConfiguration values to use to configure UI components in NowChat.
    Valid values:
    • attachmentUploadButton: Configuration for the AttachmentUploadButton that is shown next to the text input while talking with a live agent.
    • closeButton: Configuration for the CloseButton used for back navigation on the NowChat toolbar.
    For example:
    uiConfiguration = NowChatConfiguration.UIConfiguration(
      closeButton = NowChatConfiguration.CloseButton(
        icon = myDrawable
      ),
      attachmentUploadButton = NowChatConfiguration.AttachmentUploadButton(isVisible = false)
    )

    To use the default configuration, pass null.

    Table 8. Returns
    Type Description
    NowChatConfiguration Returns a NowChatConfiguration object that you can pass when calling the NowChatService - start(activity: Activity, themeColors: NowChatTheme = object: NowChatTheme{}, contextData: Map<String, Any> = mapOf(), chatConfiguration: NowChatConfiguration? = null) method.

    The following code example shows how to call this method.

    suspend fun launchChat() {
      val chatService = getNowChatService()
     
      //Drawable to use instead of the default NowChat back button.
      val myDrawable = ContextCompat.getDrawable(activity, R.drawable.my_drawable)
         
      val chatConfiguration = NowChatConfiguration(
        closePrompt = NowChatConfiguration.ClosePrompt(
          header = null,
          message = "Are you sure you want to leave?",
          acceptButtonTitle = "Yes",
          declineButtonTitle = "No"
        ),
        disabledFeatures = listOf(NowChatConfiguration.Feature.START_NEW_CONVERSATION),
        conversationOptions = listOf(NowChatConfiguration.ConversationOption.FORCE_NEW_CONVERSATION),
        uiConfiguration = NowChatConfiguration.UIConfiguration(
          closeButton = NowChatConfiguration.CloseButton(
            icon = myDrawable
          ),
          attachmentUploadButton = NowChatConfiguration.AttachmentUploadButton(isVisible = false)
        )
      )
    
      chatService?.start(activity, chatConfiguration)
    }

    NowChatConfiguration - 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 NowChatConfiguration() method to configure the close prompt options within the chat session.

    Table 9. 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 null.

    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.

    If you don't want to display a secondary button, pass null.

    Table 10. Returns
    Type Description
    Object Prompt to display before closing the associated chat window.

    The following code example shows how to call this method to configure the close prompt.

    suspend fun launchChat() {
      val chatService = getNowChatService()
     
      val chatConfiguration = NowChatConfiguration(
        closePrompt = NowChatConfiguration.ClosePrompt(
          header = null,
          message = "Are you sure you want to leave?",
          acceptButtonTitle = "Yes",
          declineButtonTitle = "No"
        )
      )
      chatService?.start(activity, chatConfiguration)
    }