Chat Widget V1


Getting Started

Chat Widget is a JSSDK (hereafter referred to as Chat widget) that allows embedding into your own website, it comes in handy whenever contacts want to contact you, more detailed configuration and usage documents are here. This document mainly focuses on JSSDK related content.

Chat Widget Methods

Open chat widget

webchat.selfHostedApp.open()

Close chat widget

webchat.selfHostedApp.close()

Set context

The following information should be taken into account when setting the context of the chat widget:

  • Does not support complex schema, it only currently supports the key value and the value type, which can only be a string or number.
  • It is only passed to Talkdesk Studio when a conversation is first created.
  • Calling this method to update an ongoing conversation cannot be synchronized to the conversation app context card.
webchat.setContextParam({ "var1": "value1", "var2": "value2", "var3": 100 })

Set the default value of Initial Screen form

When you enable the Initial Screen function in Admin, if you need to add some default values ​​to the form, the field name passed in can be seen in the admin chat touchpoint

webchat.setCustomFieldDefaultValues({ "field_email1": "[[email protected]](mailto:[email protected])","field_number1": "+1" })

Chat Widget Events

Initialization completed

webchat.init(configs).then(function() {
  // Some things you want to do after Chat JSSDK is initialized
})

When chat is opened

webchat.onOpen = function () {
  // Some things you want to do after chat is opened
}

When chat is closed

webchat.onClose = function () {
  // Some things you want to do after chat is closed
}

When the conversation starts

webchat.onConversationStart = function () {
  // Some things you want to do after the conversation start
}

Chat Widget Snippet Code Configuration

Field nameTypeIs requiredDescription
windowThe browser's built-in window reading itemYesBrowser built-in window object
documentThe browser's built-in document reading itemYesBrowser built-in document object
nodeStringYesThe target dom node ID to which chat ui is mounted (currently, this parameter value must be tdWebchat)
propsSee props configuration below for detailsYesMainly responsible for controlling function switches
configsSee configs configuration below for detailsYesMainly responsible for setting chat style

props configuration

Field nameTypeIs requiredDefault valueDescription
touchpointIdstringYesChat touchpoint unique identification ID, used to obtain chat jssdk configuration
accountIdstringNoFor historical reasons, please set it to null or empty string by default.
regionenumYesThe area of ​​the Talkdesk endpoints gateway used by chat.
The currently supported enumeration values are: td-us-1 td-eu-1 td-ca-1 td-usfed-1
languageCodeenumNoen-USInternationalized language for chat initialization
The current supported enumeration values ​​are: en-US pt-PT es-ES de-DE fr-FR it-IT pt-BR

configs configuration

Field nameTypeIs requiredDefault valueDescription
enableEmojibooleanNoTrueControl for emoji, hidden or displayed.
enableValidationbooleanNoFalseControl for validate for initial screen from the email or phone number input.
enableUserInputbooleanNoTrueControl for Send button and input, hidden or displayed.
enableAttachmentsbooleanTrueen-USControl for attachment button, hidden or displayed.
enableResponsiveLayoutbooleanNoTrueControl whether the automatic full-screen capability is enabled.
languageCodeenmusNoen-USControl which language the chat uses, higher than props param settings.
The currently supported enumeration values ​​are: en-US pt-PT es-ES de-DE fr-FR it-IT pt-BR
stylesobjectNoSee configs.styles configuration below for details

configs.styles configuration

Customizing the widget launch:

Field nameTypeDefault valueDescription
chatThemeColorstring# 1E0044Color of the launcher background and the header.
chatHoverThemeColorstring# 1A223FColor of the launcher background and the header.
chatIconstringhttps://qa-cdn-talkdesk.talkdeskdev.com/cdn-assets/latest/talkdesk/product/app-icons/sms.svgThe icon of the launcher.

Note: Best format: SVG, although it supports other formats such as PNG and JPG. For a round shape, it should have a transparent background.
triggerButtonWidthstring35pxWidth of the icon of the launcher.

Note: It won’t exceed the launcher’s size; therefore, its maximum value is 64 px.
triggerButtonHeightstring35pxHeight of the icon of the launcher.

Note: It won’t exceed the launcher’s size; therefore, its maximum value is 64 px.
triggerButtonPositionRightstring30pxDistance of the launcher to the right side of the window.
triggerButtonPositionBottomstring40pxDistance of the launcher to the bottom of the window.

Customizing the widget window:

Field nameDefault valueTypeDescription
chatContainerWidthstring335pxWidth when Chat is maximized
chatContainerHeightstring600pxHeight when Chat is maximized
chatPositionBottomstring20pxThe distance from the bottom of the screen when Chat is maximized
chatThemeMainFontstringRoboto-Regular, sans-serifFont of the subtitle, input box placeholder, chat messages, and notifications.

Note: It supports web-safe fonts. If you wish to use a non-supported font, we recommend pre-installing the font on your website.

Customizing the widget header:

Field nameDefault valueTypeDescription
chatTitleIconstring32pxThe icon of the header left.
chatTitleIconWidthstring32pxWidth of the icon of the header left.
chatTitleIconHeightstring# 1E0044Height of the icon of the header left.
chatThemeColorstringTalkdesk ChatColor of the launcher background and the header.
chatTitlestringTitle of the header.
chatTitleTextColorstringPowered by TalkdeskFont color of the title of the header.
chatCloseButtonColorstring# ffffffColor of the close chat conversation button.
chatMinimizeButtonColorstring# ffffffColor of the minimize widget button.

Customizing the initial screen:

Field nameTypeDefault valueDescription
welcomeMessageBackgroundColorstring# 4D356ABackground color of the welcome message.
welcomeMessageTitleFontFamilystringRoboto-Regular, sans-serifFont of the title of the welcome message.
welcomeMessageTitleFontSizestring24pxFont size of the title of the welcome message.
welcomeMessageTitleColorstring# ffffffFont color of the title of the welcome message.
welcomeMessageContentFontFamilystringRoboto-Regular, sans-serifFont of the content of the welcome message.
welcomeMessageContentFontSizestring16xFont size of the content of the welcome message.
welcomeMessageContentColorstring# ffffffFont color of the content of the welcome message.
customMessageNoBubbleFontFamilystringRoboto-Regular, sans-serifFont of the custom message with no bubble.
customMessageNoBubbleFontSizestring14pxFont size of the custom message with no bubble.
customMessageNoBubbleColorstring# 202830Font color of the custom message with no bubble.
customMessageBackgroundColorstring# F2F4F5Background color of the custom message with bubble.
customMessageFontFamilystringRoboto-Regular, sans-serifFont of the custom message with bubble.
customMessageFontSizestring14pxFont size of the custom message with bubble.
customMessageColorstring# 202830Font color of the custom message with bubble.
customFieldLabelFontFamilystringRoboto-Regular, sans-serifFont of the label of a custom field.
customFieldLabelFontSizestring14pxFont size of the label of a custom field.
customFieldLabelColorstring# 202830Font color of the label of a custom field.
customFieldInputFontFamilystringRoboto-Regular, sans-serifFont of the input text of a custom field.
customFieldInputFontSizestring14pxFont size of the input text of a custom field.
customFieldInputColorstring# 202830Font color of the input text of a custom field.
customFieldInputBackgroundColorstring# ffffffBackground color of a custom field.
customFieldInputPlaceholderstringTypePartial placeholder of a custom field.
customDropdownLabelFontFamilystringRoboto-Regular, sans-serifFont of the label of a custom dropdown.
customDropdownLabelFontSizestring14pxFont size of the label of a custom dropdown.
customDropdownLabelColorstring# 202830Font color of the label of a custom dropdown.
customDropdownInputFontFamilystringRoboto-Regular, sans-serifFont of the input text of a custom dropdown.
customDropdownInputFontSizestring14pxFont size of the input text of a custom dropdown.
customDropdownInputColorstring# 202830Font color of the input text of a custom dropdown.
customDropdownInputBackgroundColorstring# ffffffBackground color of a custom dropdown.
customDropdownInputPlaceholderstringSelectPartial placeholder of a custom dropdown.
customButtonFontFamilystringRoboto-Regular, sans-serifFont of the label of a custom button.
customButtonFontSizestring14pxFont size of the label of a custom button.
customButtonColorstring# 003FBDFont size of the label of a custom button.
customButtonBackgroundColorstring# ffffffBackground color of a custom button.
customButtonColorstring# 003FBDFont color of the label of a custom button
customButtonBackgroundColorstring# ffffffBackground color of a custom button.
customButtonBorderColorstring# 003FBDBorder color of a custom button.
customButtonHeightstring32pxHeight of a custom button.
customFieldPhoneDescriptionstringInclude the country code, avoid spaces and/or symbols (e.g. +1123456789)Phone number input Prompt user description

Note: This item will only be displayed if configs.enableValidation is set to true. see 4.6 for details.
customFieldPhoneInvalidFormatMessagestringPlease type a valid phone numberPrompt message when phone number input fails verification

Note: This item will only be displayed if configs.enableValidation is set to true. see 4.6 for details.
customFieldEmailInvalidFormatMessagestring14pxPrompt message when email input fails verification.Prompt message when phone number input fails verification

Note: This item will only be displayed if configs.enableValidation is set to true. see 4.6 for details.

Note: This item will only be displayed if configs.enableValidation is set to true. see 4.6 for details.

Customizing the conversation


Field nameTypeDefault valueDescription
userTextColorstring# ffffffFont color of a message sent by a visitor.
userBackgroundColorstring# 5405BDBackground color of a message sent by a visitor.
botTextColorstring# 00000Agent or VA agent message bubble font color.
botBackgroundColorstring# F2F4F5Background color of a message sent by an agent or a bot.
userAnchorTextColorstring# E1CCFEFont color of an unvisited hyperlink sent by a visitor.
userAnchorTextColorVisitedstring# B681FC# 5405BDFont color of a visited hyperlink sent by an agent or a bot.
botAnchorTextColorstring# 3232D6# 3232D6Font color of an unvisited hyperlink sent by an agent or a bot.
botAnchorTextColorVisitedstring# 5405BD# 5405BDFont color of a visited hyperlink sent by an agent or a bot.
botIconVerticalAlignstringtopPlacement of the agent avatar towards the message bubble. It can be ‘top’ or ‘bottom’.
avatarForegroundColorstring# 5C6784Foreground color of the default agent avatar.
avatarBackgroundColorstring# EDF4FCBackground color of the default agent avatar.
avatarBorderColorstring# EDF4FCBorder color of the default agent avatar.
botIconHeightstring32pxHeight of the agent avatar.
botIconWidthstring32pxWidth of the agent avatar.
botIconstringCustom agent avatar.

Note: It overrides all the default agent avatar properties.
userInputSeparatorColorstring# DFDFDFColor of the separator above the input box.
userInputHeightstring56pxMinimum height of user message input box.
chatPlaceholderstringType a message...Placeholder of the input box.
buttonTextColorstring# 005cdeSet the font color of all VA Buttons and buttons in the carousel component.
buttonHoverTextColor# 005cdeSet the font color of all VA Buttons and buttons in the carousel component when the mouse is moved into it.
buttonBackgroundColorstringrgb(237, 244, 252)Set the background color of all VA Buttons and buttons in the carousel component.
buttonHoverBackgroundColorstringrgb(237, 244, 252)Set the background color of all VA Buttons and buttons in the carousel component when the mouse is moved into it.
replyTextColorstring# 005cdeSet the font color of all VA quick replay buttons.
replyHoverTextColorstring# edf4fcSet the font color of all VA quick replay buttons when the mouse is moved into them.
replyBorderColorstring# 005cdeSet the border color of all VA quick replay buttons.
replyBackgroundColorstringtransparentSet the background color of all VA quick replay buttons.
endedChatMessagestringEnd chatSystem message text displayed at the end of the conversation.
startChatButtonTextColorstring# ffffffStart new conversation button font color.
startChatButtonHoverTextColorstring# ffffffThe font color of the Start New Conversation button when the mouse is moved into it.
startChatButtonBorderColorstring# 1e0044Start new conversation button border color.
startChatButtonHoverBorderColorstring# 1e0044The color of the border when the mouse is moved into the Start New Conversation button.
startChatButtonBackgroundColorstring# 1e0044Start new conversation button background color
startChatButtonHoverBackgroundColorstring# 1e0044The background color of the Start New Conversation button when the mouse is moved into it.
startChatButtonLabelstringStart new chatDisplay copy in Start New Conversation button.

Customizing the close conversation dialog for contacts

Field nameTypeDefault valueDescription
chatDialogBoxIconColorstring# AEB3B8Color of the icon of the dialog box.
chatDialogBoxFontFamilystringRoboto-Regular, sans-serifFont of the message of the dialog box.
chatDialogBoxFontSizestring16pxFont size of the message of the dialog box.
chatDialogBoxFontColorstring# 202830Font color of the message of the dialog box.
chatConfirmButtonFontFamilystringRoboto-Regular, sans-serifFont of the confirm button of the dialog box.
chatConfirmButtonFontSizestring14pxFont size of the confirm button of the dialog box.
chatConfirmButtonFontColorstring# ffffffFont color of the confirm button of the dialog box.
chatConfirmButtonBackgroundColorstring# 3E048BBackground color of the confirm button of the dialog box.
chatCancelButtonFontFamilystringRoboto-Regular, sans-serifFont of the cancel button of the dialog box.
chatCancelButtonFontSizestring14pxFont size of the cancel button of the dialog box.
chatCancelButtonFontColorstring# F2F4F5Font color of the cancel button of the dialog box.
chatDialogBoxEndChatstringAre you sure you want to end this chat?Message of the dialog box when the contact person tries to end the conversation.
chatConfirmButtonEndChatstringYes, end chatLabel of the confirm button of the dialog box when the contact person tries to end the conversation.
chatCancelButtonEndChatstringCancelLabel of the cancel button of the dialog box when the contact person tries to end the conversation.
chatDialogBoxRetryEndChatstringThere was an error while ending the chatMessage of the dialog box when an error occurs while attempting to end the conversation.
chatConfirmButtonRetryEndChatstringTry againLabel of the confirm button of the dialog box when an error occurs while attempting to end the conversation.
chatCancelButtonRetryEndChatstringDismissLabel of the cancel button of the dialog box when an error occurs while attempting to end the conversation.

Content Security Policy (CSP)

When a website has a Content Security Policy (CSP) enabled, it restricts the types of content that can be loaded on the site. To ensure that chat functionalities run properly, specific sources must be whitelisted. Below is a description of the CSP configuration needed for Talkdesk regions, including td-us-1, td-eu-1, td-ca-1, and td-usfed-1, to ensure chat functions properly on the website.

TD RegionCSP Rules
td-us-1script-src 'self' https://talkdeskchatsdk.talkdeskapp.com;
connect-src 'self' https://api.talkdeskapp.com wss://tsock.us1.twilio.com https://mcs.us1.twilio.com https://*.dynatrace.com;
img-src 'self' data: blob: https://talkdeskchatsdk.talkdeskapp.com https://qa-cdn-talkdesk.talkdeskdev.com https://media.us1.twilio.com;
video-src 'self' data: blob: https://media.us1.twilio.com;
audio-src 'self' data: blob: https://media.us1.twilio.com;
frame-src 'self' https://api.talkdeskapp.com;
font-src 'self' https://talkdeskchatsdk.talkdeskapp.com;
td-eu-1script-src 'self' https://talkdeskchatsdk.talkdeskapp.com;
connect-src 'self' https://api.talkdeskapp.eu wss://tsock.ie1.twilio.com https://mcs.ie1.twilio.com https://*.dynatrace.com;
img-src 'self' data: blob: https://talkdeskchatsdk.talkdeskapp.com https://qa-cdn-talkdesk.talkdeskdev.com https://media.ie1.twilio.com;
video-src 'self' data: blob: https://media.ie1.twilio.com;
audio-src 'self' data: blob: https://media.ie1.twilio.com;
frame-src 'self' https://api.talkdeskapp.eu;
font-src 'self' https://talkdeskchatsdk.talkdeskapp.com;
td-ca-1script-src 'self' https://talkdeskchatsdk.talkdeskapp.com;
connect-src 'self' https://api.talkdeskappca.com wss://tsock.us1.twilio.com https://mcs.us1.twilio.com https://*.dynatrace.com;
img-src 'self' data: blob: https://talkdeskchatsdk.talkdeskapp.com https://qa-cdn-talkdesk.talkdeskdev.com https://media.us1.twilio.com;
video-src 'self' data: blob: https://media.us1.twilio.com;
audio-src 'self' data: blob: https://media.us1.twilio.com;
frame-src 'self' https://api.talkdeskappca.com;
font-src 'self' https://talkdeskchatsdk.talkdeskapp.com;
td-usfed-1script-src 'self' https://talkdeskchatsdk.talkdeskapp.com;
connect-src 'self' https://api.talkdeskapp-pubsec.com wss://tsock.us1.twilio.com https://mcs.us1.twilio.com https://*.dynatrace.com;
img-src 'self' data: blob: https://talkdeskchatsdk.talkdeskapp.com https://qa-cdn-talkdesk.talkdeskdev.com https://media.us1.twilio.com;
video-src 'self' data: blob: https://media.us1.twilio.com;
audio-src 'self' data: blob: https://media.us1.twilio.com;
frame-src 'self' https://api.talkdeskapp-pubsec.com;
font-src 'self' https://talkdeskchatsdk.talkdeskapp.com;

CSP Domain Description

Below is the description of the purpose of CSP domains. Each of these domains plays a crucial role in enabling chat services by specifying trusted sources from which content can be loaded, ensuring both functionality and security for users in their respective regions.

CSP DomainsDescription
https://talkdeskchatsdk.talkdeskapp.comTalkDesk Chat Widget JSSDK remote host
https://qa-cdn-talkdesk.talkdeskdev.comTalkDesk Chat Widget JSSDK default remote image host
https://api.talkdeskapp.comTalkDesk Gateway US region host
https://api.talkdeskapp.euTalkDesk Gateway EU region host
https://api.talkdeskappca.comTalkDesk Gateway CA region host
https://api.talkdeskapp-pubsec.comTalkDesk Gateway FedRAMP region host (This is a special area that non-FedRAMP customers do not need to configure)
https://*.dynatrace.com TalkDesk Chat Widget JSSDK log reporting gateway, used to record error logs
wss://tsock.us1.twilio.comConversation WebSocket channel in td-us-1 or td-ca-1
wss://tsock.ie1.twilio.comConversation WebSocket channel in td-eu-1
https://mcs.us1.twilio.comChat attachment service in td-us-1 or td-ca-1
https://mcs.ie1.twilio.comChat attachment service in td-eu-1
https://media.us1.twilio.comChat preview attachment service in td-us-1 or td-ca-1
https://media.ie1.twilio.comChat preview attachment service in td-eu-1
data:Chat Widget JSSDK sometimes displays local files, so this host is needed
blob:Chat Widget JSSDK sometimes displays local files, so this host is needed

Chat widget scenario best practice cases

Default to Hide Chat Launch Icon, Use Customer's Website Button to Open Chat

When customers need to hide the minimized icon of TD chat and then use a button or link on their website to trigger the maximized TD chat, the following is an example of the integration code.

+<button onclick="webchat && webchat.selfHostedApp.open()">click to show chat</button>
+<button onclick="webchat && webchat.selfHostedApp.close()">click to hide chat</button>

+<a id="show-link">click to show chat</a>
+<a id="hide-link">click to hide chat</a>

+<!--custom js code to trigger td chat-->
+<script>
+  document.getElementById("show-link").onclick = function () {
+    webchat && (webchat.selfHostedApp.open())
+  }
+  document.getElementById("hide-link").onclick = function () {
+    webchat && (webchat.selfHostedApp.close())
+  }
+</script>

<!-- Start of Talkdesk Code -->
    <script>
      var webchat;
      (function(window, document, node, props, configs) {
        if (window.TalkdeskChatSDK) {
          console.error("TalkdeskChatSDK already included");
          return;
        }
        var divContainer = document.createElement("div");
        divContainer.id = node;
        document.body.appendChild(divContainer);
        var src = "https://talkdeskchatsdk.talkdeskapp.com/talkdeskchatsdk.js";
        var script = document.createElement("script");
        var firstScriptTag = document.getElementsByTagName("script")[0];
        script.type = "text/javascript";
        script.charset = "UTF-8";
        script.id = "tdwebchatscript";
        script.src = src;
        script.async = true;
        firstScriptTag.parentNode.insertBefore(script, firstScriptTag);
        script.onload = function() {
          webchat = TalkdeskChatSDK(node, props);
          webchat.init(configs);
          /*
           * Send custom data from your website to TalkDesk!
           * If you would like to do it, you need to remove the following commented code and
           * modify the webchat.setContextParam parameters to pass in the data you need.
           */
           /*function setContext() {
             webchat.setContextParam({ "var1": "value1", "var2": "value2", "var3": 100 })
           }
           // Send data when the chat conversation is initiated
           webchat.onConversationStart = function() {
             setContext()
           }
           // Send data when the chat widget is open
           webchat.onOpenWebchat = function() {
             setContext()
           }*/
        };
      })(
        window,
        document,
        "tdWebchat",
        { touchpointId: "<customer touchpointId>", accountId: "", region: "<customer td region>" },
        { 
          enableValidation: false, 
          enableEmoji: true, 
          enableUserInput: true, 
          enableAttachments: true,
+         styles: {
+           // hidden lanuch chat icon
+           triggerButtonPositionBottom: "-65px",
+           triggerButtonPositionRight: "-65px",
+         },
        }
      );
    </script>
<!-- End of Talkdesk Code -->

Open Chat Widget Automatically on Page Load

The customer needs to automatically open TD chat every time the contact person visits the website. The following is an example of the integration code:

<!-- Start of Talkdesk Code -->
    <script>
      var webchat;
      (function(window, document, node, props, configs) {
        if (window.TalkdeskChatSDK) {
          console.error("TalkdeskChatSDK already included");
          return;
        }
        var divContainer = document.createElement("div");
        divContainer.id = node;
        document.body.appendChild(divContainer);
        var src = "https://talkdeskchatsdk.talkdeskapp.com/talkdeskchatsdk.js";
        var script = document.createElement("script");
        var firstScriptTag = document.getElementsByTagName("script")[0];
        script.type = "text/javascript";
        script.charset = "UTF-8";
        script.id = "tdwebchatscript";
        script.src = src;
        script.async = true;
        firstScriptTag.parentNode.insertBefore(script, firstScriptTag);
        script.onload = function() {
          webchat = TalkdeskChatSDK(node, props);
-         webchat.init(configs)
+         webchat.init(configs).then(function() {
+           webchat.selfHostedApp.open()
+         });
          /*
           * Send custom data from your website to TalkDesk!
           * If you would like to do it, you need to remove the following commented code and
           * modify the webchat.setContextParam parameters to pass in the data you need.
           */
           /*function setContext() {
             webchat.setContextParam({ "var1": "value1", "var2": "value2", "var3": 100 })
           }
           // Send data when the chat conversation is initiated
           webchat.onConversationStart = function() {
             setContext()
           }
           // Send data when the chat widget is open
           webchat.onOpenWebchat = function() {
             setContext()
           }*/
        };
      })(
        window,
        document,
        "tdWebchat",
        { touchpointId: "<customer touchpointId>", accountId: "", region: "<customer td region>" },
        { enableValidation: false, enableEmoji: true, enableUserInput: true, enableAttachments: true }
      );
    </script>
<!-- End of Talkdesk Code -->

Show or Hide Attachments or Emojis in Chat

If the customer website integrates Chat and needs to turn off attachments or emoticon functions, you can modify these configuration items to turn them on and off.

<!-- Start of Talkdesk Code -->
    <script>
      var webchat;
      (function(window, document, node, props, configs) {
        if (window.TalkdeskChatSDK) {
          console.error("TalkdeskChatSDK already included");
          return;
        }
        var divContainer = document.createElement("div");
        divContainer.id = node;
        document.body.appendChild(divContainer);
        var src = "https://talkdeskchatsdk.talkdeskapp.com/talkdeskchatsdk.js";
        var script = document.createElement("script");
        var firstScriptTag = document.getElementsByTagName("script")[0];
        script.type = "text/javascript";
        script.charset = "UTF-8";
        script.id = "tdwebchatscript";
        script.src = src;
        script.async = true;
        firstScriptTag.parentNode.insertBefore(script, firstScriptTag);
        script.onload = function() {
          webchat = TalkdeskChatSDK(node, props);
          webchat.init(configs);
          /*
           * Send custom data from your website to TalkDesk!
           * If you would like to do it, you need to remove the following commented code and
           * modify the webchat.setContextParam parameters to pass in the data you need.
           */
           /*function setContext() {
             webchat.setContextParam({ "var1": "value1", "var2": "value2", "var3": 100 })
           }
           // Send data when the chat conversation is initiated
           webchat.onConversationStart = function() {
             setContext()
           }
           // Send data when the chat widget is open
           webchat.onOpenWebchat = function() {
             setContext()
           }*/
        };
      })(
        window,
        document,
        "tdWebchat",
        { touchpointId: "<customer touchpointId>", accountId: "", region: "<customer td region>" },
        { 
          enableValidation: false,
+         enableEmoji: true, // if set the value is false then emoji disable
          enableUserInput: true, 
+         enableAttachments: true // if set the value is false then attachment disable
        }
      );
    </script>
<!-- End of Talkdesk Code -->

Manage Automatic Fullscreen Mode in Chat

If we enable the responsive layout when the screen width is lower than 600px or the height is lower than 620px, the chat widget will be resized to full screen, and if we disable the responsive layout, we’ll not set a full screen for the chat widget at any time.

<!-- Start of Talkdesk Code -->
    <script>
      var webchat;
      (function(window, document, node, props, configs) {
        if (window.TalkdeskChatSDK) {
          console.error("TalkdeskChatSDK already included");
          return;
        }
        var divContainer = document.createElement("div");
        divContainer.id = node;
        document.body.appendChild(divContainer);
        var src = "https://talkdeskchatsdk.talkdeskapp.com/talkdeskchatsdk.js";
        var script = document.createElement("script");
        var firstScriptTag = document.getElementsByTagName("script")[0];
        script.type = "text/javascript";
        script.charset = "UTF-8";
        script.id = "tdwebchatscript";
        script.src = src;
        script.async = true;
        firstScriptTag.parentNode.insertBefore(script, firstScriptTag);
        script.onload = function() {
          webchat = TalkdeskChatSDK(node, props);
          webchat.init(configs);
          /*
           * Send custom data from your website to TalkDesk!
           * If you would like to do it, you need to remove the following commented code and
           * modify the webchat.setContextParam parameters to pass in the data you need.
           */
           /*function setContext() {
             webchat.setContextParam({ "var1": "value1", "var2": "value2", "var3": 100 })
           }
           // Send data when the chat conversation is initiated
           webchat.onConversationStart = function() {
             setContext()
           }
           // Send data when the chat widget is open
           webchat.onOpenWebchat = function() {
             setContext()
           }*/
        };
      })(
        window,
        document,
        "tdWebchat",
        { touchpointId: "<customer touchpointId>", accountId: "", region: "<customer td region>" },
        { 
          enableValidation: false,
          enableEmoji: true,
          enableUserInput: true, 
          enableAttachments: true,
+         enableResponsiveLayout: true // if the value is set to false, then responsive layout feature will be disable
        }
      );
    </script>
<!-- End of Talkdesk Code -->

It may not be good to simply disable the full-screen capability. For example, the automatic full-screen capability is still needed on some mobile devices, but you can not use it on a PC. The following is an example.

<!-- Start of Talkdesk Code -->
    <script>
      var webchat;
      (function(window, document, node, props, configs) {
        if (window.TalkdeskChatSDK) {
          console.error("TalkdeskChatSDK already included");
          return;
        }
        var divContainer = document.createElement("div");
        divContainer.id = node;
        document.body.appendChild(divContainer);
        var src = "https://talkdeskchatsdk.talkdeskapp.com/talkdeskchatsdk.js";
        var script = document.createElement("script");
        var firstScriptTag = document.getElementsByTagName("script")[0];
        script.type = "text/javascript";
        script.charset = "UTF-8";
        script.id = "tdwebchatscript";
        script.src = src;
        script.async = true;
        firstScriptTag.parentNode.insertBefore(script, firstScriptTag);
        script.onload = function() {
          webchat = TalkdeskChatSDK(node, props);
          webchat.init(configs);
          /*
           * Send custom data from your website to TalkDesk!
           * If you would like to do it, you need to remove the following commented code and
           * modify the webchat.setContextParam parameters to pass in the data you need.
           */
           /*function setContext() {
             webchat.setContextParam({ "var1": "value1", "var2": "value2", "var3": 100 })
           }
           // Send data when the chat conversation is initiated
           webchat.onConversationStart = function() {
             setContext()
           }
           // Send data when the chat widget is open
           webchat.onOpenWebchat = function() {
             setContext()
           }*/
        };
      })(
        window,
        document,
        "tdWebchat",
        { touchpointId: "<customer touchpointId>", accountId: "", region: "<customer td region>" },
        { 
          enableValidation: false,
          enableEmoji: true,
          enableUserInput: true, 
          enableAttachments: true,
+         enableResponsiveLayout: /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(window.navigator.userAgent),
        }
      );
    </script>
<!-- End of Talkdesk Code -->

Pass Custom Context to TalkDesk Studio when Conversationstart

If the customer website has some values ​​that need to be passed to the conversation app, this can be achieved using the following integrated code in the context card on the right.

📘

Note

If you really need to display it in the Conversations app context card, you also need to set the mapping relationship in the ChatDesk studio context panel associated with Chat.Below is an example of setting a screenshot

Step 1:Click the 'add' button

Step 2: Add the context you need to Talkdesk Studio

Step 3: Select the context items you need

<!-- Start of Talkdesk Code -->
    <script>
      var webchat;
      (function(window, document, node, props, configs) {
        if (window.TalkdeskChatSDK) {
          console.error("TalkdeskChatSDK already included");
          return;
        }
        var divContainer = document.createElement("div");
        divContainer.id = node;
        document.body.appendChild(divContainer);
        var src = "https://talkdeskchatsdk.talkdeskapp.com/talkdeskchatsdk.js";
        var script = document.createElement("script");
        var firstScriptTag = document.getElementsByTagName("script")[0];
        script.type = "text/javascript";
        script.charset = "UTF-8";
        script.id = "tdwebchatscript";
        script.src = src;
        script.async = true;
        firstScriptTag.parentNode.insertBefore(script, firstScriptTag);
        script.onload = function() {
          webchat = TalkdeskChatSDK(node, props);
          webchat.init(configs);
          /*
           * Send custom data from your website to TalkDesk!
           * If you would like to do it, you need to remove the following commented code and
           * modify the webchat.setContextParam parameters to pass in the data you need.
           */
-          /*function setContext() {          
+          function setContext() {
+            // You can modify the object parameters and values ​​in the following methods
             webchat.setContextParam({ "var1": "value1", "var2": "value2", "var3": 100 })
           }
           // Send data when the chat conversation is initiated
           webchat.onConversationStart = function() {
             setContext()
           }
           // Send data when the chat widget is open
           webchat.onOpenWebchat = function() {
             setContext()
-          }*/
+          }
       };
      })(
        window,
        document,
        "tdWebchat",
        { touchpointId: "<customer touchpointId>", accountId: "", region: "<customer td region>" },
        { enableValidation: false, enableEmoji: true, enableUserInput: true, enableAttachments: true }
      );
    </script>
<!-- End of Talkdesk Code -->

Create and Identify a Contact Automatically

Integrated customers can call the setContextParam method provided by our jssdk on their website to pass the contact person's phone number or email. It must be passed using the td_contact_person_identification field, which currently only supports email or phone number. The following is an example of the integrated code.

<!-- Start of Talkdesk Code -->
    <script>
      var webchat;
      (function(window, document, node, props, configs) {
        if (window.TalkdeskChatSDK) {
          console.error("TalkdeskChatSDK already included");
          return;
        }
        var divContainer = document.createElement("div");
        divContainer.id = node;
        document.body.appendChild(divContainer);
        var src = "https://talkdeskchatsdk.talkdeskapp.com/talkdeskchatsdk.js";
        var script = document.createElement("script");
        var firstScriptTag = document.getElementsByTagName("script")[0];
        script.type = "text/javascript";
        script.charset = "UTF-8";
        script.id = "tdwebchatscript";
        script.src = src;
        script.async = true;
        firstScriptTag.parentNode.insertBefore(script, firstScriptTag);
        script.onload = function() {
          webchat = TalkdeskChatSDK(node, props);
          webchat.init(configs);
          /*
           * Send custom data from your website to TalkDesk!
           * If you would like to do it, you need to remove the following commented code and
           * modify the webchat.setContextParam parameters to pass in the data you need.
           */
-          /*function setContext() {        
+          function setContext() {
             webchat.setContextParam({
+             // Here, the unique identifier of the contact person is passed to talkdesk. Currently, only phone numbers and email addresses are supported. Please choose one to pass.
+              "td_contact_person_identification": "[email protected]"
             })
           }
           // Send data when the chat conversation is initiated
           webchat.onConversationStart = function() {
             setContext()
           }
           // Send data when the chat widget is open
           webchat.onOpenWebchat = function() {
             setContext()
-          }*/
+          }
        };
      })(
        window,
        document,
        "tdWebchat",
        { touchpointId: "<customer touchpointId>", accountId: "", region: "<customer td region>" },
        { enableValidation: false, enableEmoji: true, enableUserInput: true, enableAttachments: true }
      );
    </script>
<!-- End of Talkdesk Code -->

Set Default Values ​​for the Initial Screen Form

The field name is generated in the channel's chat touchpoint initial screen form:

If default values are set for all fields, the chat will automatically skip the initial screen form stage and be automatically passed to the TalkDesk system when the conversation starts.

<!-- Start of Talkdesk Code -->
    <script>
      var webchat;
      (function(window, document, node, props, configs) {
        if (window.TalkdeskChatSDK) {
          console.error("TalkdeskChatSDK already included");
          return;
        }
        var divContainer = document.createElement("div");
        divContainer.id = node;
        document.body.appendChild(divContainer);
        var src = "https://talkdeskchatsdk.talkdeskapp.com/talkdeskchatsdk.js";
        var script = document.createElement("script");
        var firstScriptTag = document.getElementsByTagName("script")[0];
        script.type = "text/javascript";
        script.charset = "UTF-8";
        script.id = "tdwebchatscript";
        script.src = src;
        script.async = true;
        firstScriptTag.parentNode.insertBefore(script, firstScriptTag);
        script.onload = function() {
          webchat = TalkdeskChatSDK(node, props);
          webchat.init(configs);
+         // Note: Set the default value of the Initial screen form here. If default values ​​are set for all fields, Talkdesk Chat will automatically skip the Initial screen stage and go directly to the conversation ui.          
+         webchat.setCustomFieldDefaultValues({
+           "field_email1": "[email protected]",
+           "field_number1": "+1",
+         });
          /*
           * Send custom data from your website to TalkDesk!
           * If you would like to do it, you need to remove the following commented code and
           * modify the webchat.setContextParam parameters to pass in the data you need.
           */
           /*function setContext() {
             webchat.setContextParam({ "var1": "value1", "var2": "value2", "var3": 100 })
           }
           // Send data when the chat conversation is initiated
           webchat.onConversationStart = function() {
             setContext()
           }
           // Send data when the chat widget is open
           webchat.onOpenWebchat = function() {
             setContext()
           }*/
        };
      })(
        window,
        document,
        "tdWebchat",
        { touchpointId: "<customer touchpointId>", accountId: "", region: "<customer td region>" },
        { enableValidation: false, enableEmoji: true, enableUserInput: true, enableAttachments: true }
      );
    </script>
<!-- End of Talkdesk Code -->