From Bright Pattern Documentation
Jump to: navigation, search
(Marked this version for translation)
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
<translate>
+
 
= How to Pass JavaScript Variables Through Web HTML Snippet = <!--T:1-->
+
= How to Pass JavaScript Variables Through Web HTML Snippet =  
 
As you learned in our tutorial, [[Tutorials-for-admins/Chat/HowtoUsetheChatWidgetHTMLSnippet |  How to Use the Web HTML Snippet]], the web HTML snippet is the code that defines your chat widget's configuration.
 
As you learned in our tutorial, [[Tutorials-for-admins/Chat/HowtoUsetheChatWidgetHTMLSnippet |  How to Use the Web HTML Snippet]], the web HTML snippet is the code that defines your chat widget's configuration.
  
<!--T:2-->
 
 
The snippet contains the formatting and style of your configured chat widget, the path to your chat application, the mobile/web API endpoint, the URL of your contact center, and a path to the chat. You can edit the snippet to pass some standard variables through the chat, such as first_name, last_name, email, and phone_number. It is also possible to pass custom variables through the snippet.
 
The snippet contains the formatting and style of your configured chat widget, the path to your chat application, the mobile/web API endpoint, the URL of your contact center, and a path to the chat. You can edit the snippet to pass some standard variables through the chat, such as first_name, last_name, email, and phone_number. It is also possible to pass custom variables through the snippet.
  
<!--T:3-->
 
 
In this article, you will learn how to format such custom variables in the snippet.
 
In this article, you will learn how to format such custom variables in the snippet.
  
== Procedure == <!--T:4-->
+
== Procedure ==  
 
=== Step 1: Locate your chat scenario entry ===
 
=== Step 1: Locate your chat scenario entry ===
 
# In Contact Center Administrator, go to ''Configuration > Scenario Entries > Messaging/Chat'' and Select the desired chat scenario entry to view its properties.<br /><br />[[File:Scenario-Entries-Messaging-53.PNG|thumb|800px|center|Configuration > Scenario Entries > Messaging/Chat]]<br /><br />
 
# In Contact Center Administrator, go to ''Configuration > Scenario Entries > Messaging/Chat'' and Select the desired chat scenario entry to view its properties.<br /><br />[[File:Scenario-Entries-Messaging-53.PNG|thumb|800px|center|Configuration > Scenario Entries > Messaging/Chat]]<br /><br />
Line 15: Line 13:
 
# The ''HTML Snippet for Web Page'' dialog will open.<br /><br />[[File:Chat-Confg16.PNG|thumb|800px|center|HTML Snippet for Web Page dialog]]<br /><br />
 
# The ''HTML Snippet for Web Page'' dialog will open.<br /><br />[[File:Chat-Confg16.PNG|thumb|800px|center|HTML Snippet for Web Page dialog]]<br /><br />
  
=== Step 2: Enter your contact center's hostname and copy snippet === <!--T:5-->
+
=== Step 2: Enter your contact center's hostname and copy snippet ===  
 
# In the field '''Specify client web server hostname''', enter your contact center’s name (i.e., “example.brightpattern.com”). This action will populate the snippet with the hostname, making it ready to be copied.<br /><br />
 
# In the field '''Specify client web server hostname''', enter your contact center’s name (i.e., “example.brightpattern.com”). This action will populate the snippet with the hostname, making it ready to be copied.<br /><br />
 
# Click '''Copy to clipboard''' to copy the snippet.<br /><br />
 
# Click '''Copy to clipboard''' to copy the snippet.<br /><br />
Line 21: Line 19:
  
  
  <!--T:6-->
+
   
 
<!-- You have to put this piece of JavaScript code into your web page
 
<!-- You have to put this piece of JavaScript code into your web page
 
  Note: Use <!DOCTYPE html> on the page where snippet located for better rendering
 
  Note: Use <!DOCTYPE html> on the page where snippet located for better rendering
  -->
+
  --><syntaxhighlight lang="html">
<link type="text/css" rel="stylesheet" href="https://example.brightpattern.com/clientweb/chat-client-v4/css/form.css">
+
<link type="text/css" rel="stylesheet" href="https://example.brightpattern.com/clientweb/chat-client-v4/css/form.css">
<script type="text/javascript">
+
<script type="text/javascript">
    SERVICE_PATTERN_CHAT_CONFIG = {
+
SERVICE_PATTERN_CHAT_CONFIG = {  
        appId: '94066',
+
appId: '94066',  
        apiUrl: 'https://example.brightpattern.com/clientweb/api/v1',
+
apiUrl: 'https://example.brightpattern.com/clientweb/api/v1',  
        tenantUrl: 'five.brightpattern.com',
+
tenantUrl: 'five.brightpattern.com',  
        chatPath: 'https://example.brightpattern.com/clientweb/chat-client-v4/'
+
chatPath: 'https://example.brightpattern.com/clientweb/chat-client-v4/'  
+
/*  
        /*      
+
// Default customer data, it can be collected on current site's context  
        // Default customer data, it can be collected on current site's context
+
first_name: ,
        first_name: '',
+
last_name: ,  
        last_name: '',
+
email: ,  
        email: '',
+
phone_number: */  
        phone_number: ''
+
};
*/
+
</script>
    };
+
<script src="https://example.brightpattern.com/clientweb/chat-client-v4/js/init.js"></script>
</script>
+
</syntaxhighlight>
<script src="https://example.brightpattern.com/clientweb/chat-client-v4/js/init.js"></script>  
 
  
=== Step 3: Edit default customer data parameters === <!--T:7-->
+
=== Step 3: Edit default customer data parameters ===  
 
Notice that in the code comments, some customer data parameters are given: first_name, last_name, email, and phone_number. This customer information is the default set of data collected from the chat's pre-chat form and is passed to the system during the chat interaction.<ref>Note that default variables like "name" can be passed without using parameters declaration.</ref>
 
Notice that in the code comments, some customer data parameters are given: first_name, last_name, email, and phone_number. This customer information is the default set of data collected from the chat's pre-chat form and is passed to the system during the chat interaction.<ref>Note that default variables like "name" can be passed without using parameters declaration.</ref>
  
<!--T:8-->
 
 
To pass custom variables through the chat, simply replace this:
 
To pass custom variables through the chat, simply replace this:
  
       <!--T:9-->
+
       <syntaxhighlight lang="javascript">
/*      
+
/*  
        // Default customer data, it can be collected on current site's context
+
// Default customer data, it can be collected on current site's context  
        first_name: '',
+
first_name: ,  
        last_name: '',
+
last_name: ,  
        email: '',
+
email: ,  
        phone_number: ''
+
phone_number:  
*/
+
*/
 
+
</syntaxhighlight>With the following, where "variable_name" is the name of your variable, and "Value" is the value:<syntaxhighlight lang="javascript">
<!--T:10-->
 
With the following, where "variable_name" is the name of your variable, and "Value" is the value:
 
 
 
<!--T:11-->
 
 
parameters:{
 
parameters:{
variable_name: 'Value',
+
    variable_name: 'Value',
}
+
}
 
+
</syntaxhighlight>
<!--T:12-->
+
 
For example:
 
For example:
  
<!--T:13-->
+
<syntaxhighlight lang="html">
<syntaxhighlight lang="javascript">
 
 
  <link type="text/css" rel="stylesheet" href="https://example.brightpattern.com/clientweb/chat-client-v4/css/form.css">
 
  <link type="text/css" rel="stylesheet" href="https://example.brightpattern.com/clientweb/chat-client-v4/css/form.css">
 
  <script type="text/javascript">
 
  <script type="text/javascript">
Line 79: Line 70:
 
         tenantUrl: 'example.brightpattern.com',
 
         tenantUrl: 'example.brightpattern.com',
 
         chatPath: 'https://example.brightpattern.com/clientweb/chat-client-v4/',
 
         chatPath: 'https://example.brightpattern.com/clientweb/chat-client-v4/',
parameters:{
+
        parameters:{
test_var: 'Hello World',
+
            test_var: 'Hello World',  
 
 
}
 
}
 
     };
 
     };
Line 89: Line 79:
  
  
<!--T:14-->
 
 
'''Note:''' You should use either the default customer data parameters '''or''' your own parameters, but not both. Customer parameters use variable ''$(item.externalChatData)'' to collect all customer data from the pre-chat form. If you include both default and custom parameters, you will have duplicate entries of first_name, last_name, email, and phone_number.
 
'''Note:''' You should use either the default customer data parameters '''or''' your own parameters, but not both. Customer parameters use variable ''$(item.externalChatData)'' to collect all customer data from the pre-chat form. If you include both default and custom parameters, you will have duplicate entries of first_name, last_name, email, and phone_number.
  
<!--T:15-->
 
 
For more information, see the ''Scenario Builder Reference Guide'', section [[Scenario-builder-reference-guide/VariablesandExpressions/Variables |  Variables]].
 
For more information, see the ''Scenario Builder Reference Guide'', section [[Scenario-builder-reference-guide/VariablesandExpressions/Variables |  Variables]].
  
=== Step 4: Paste the snippet into your HTML file === <!--T:16-->
+
=== Step 4: Paste the snippet into your HTML file ===  
 
Once you are done with step 3, paste the snippet into your HTML for use on your webpage.
 
Once you are done with step 3, paste the snippet into your HTML for use on your webpage.
  
  
<!--T:17-->
 
 
<references />
 
<references />
 
 
 
 
 
</translate>
 

Latest revision as of 05:12, 15 November 2024

• 日本語
• 5.19 • 5.3 • 5.8


How to Pass JavaScript Variables Through Web HTML Snippet

As you learned in our tutorial, How to Use the Web HTML Snippet, the web HTML snippet is the code that defines your chat widget's configuration.

The snippet contains the formatting and style of your configured chat widget, the path to your chat application, the mobile/web API endpoint, the URL of your contact center, and a path to the chat. You can edit the snippet to pass some standard variables through the chat, such as first_name, last_name, email, and phone_number. It is also possible to pass custom variables through the snippet.

In this article, you will learn how to format such custom variables in the snippet.

Procedure

Step 1: Locate your chat scenario entry

  1. In Contact Center Administrator, go to Configuration > Scenario Entries > Messaging/Chat and Select the desired chat scenario entry to view its properties.

    Configuration > Scenario Entries > Messaging/Chat


  2. In the Properties tab, under Web HTML snippet, click the HTML snippet button.

  3. The HTML Snippet for Web Page dialog will open.

    HTML Snippet for Web Page dialog


Step 2: Enter your contact center's hostname and copy snippet

  1. In the field Specify client web server hostname, enter your contact center’s name (i.e., “example.brightpattern.com”). This action will populate the snippet with the hostname, making it ready to be copied.

  2. Click Copy to clipboard to copy the snippet.

  3. It looks like this:


<link type="text/css" rel="stylesheet" href="https://example.brightpattern.com/clientweb/chat-client-v4/css/form.css">
<script type="text/javascript">
SERVICE_PATTERN_CHAT_CONFIG = { 
	appId: '94066', 
	apiUrl: 'https://example.brightpattern.com/clientweb/api/v1', 
	tenantUrl: 'five.brightpattern.com', 
	chatPath: 'https://example.brightpattern.com/clientweb/chat-client-v4/' 
	/* 
		// Default customer data, it can be collected on current site's context 
		first_name: ,
		last_name: , 
		email: , 
		phone_number: */ 
};
</script>
<script src="https://example.brightpattern.com/clientweb/chat-client-v4/js/init.js"></script>

Step 3: Edit default customer data parameters

Notice that in the code comments, some customer data parameters are given: first_name, last_name, email, and phone_number. This customer information is the default set of data collected from the chat's pre-chat form and is passed to the system during the chat interaction.[1]

To pass custom variables through the chat, simply replace this:

/* 
// Default customer data, it can be collected on current site's context 
first_name: , 
last_name: , 
email: , 
phone_number: 
*/

With the following, where "variable_name" is the name of your variable, and "Value" is the value:

parameters:{
    variable_name: 'Value',
}

For example:

 <link type="text/css" rel="stylesheet" href="https://example.brightpattern.com/clientweb/chat-client-v4/css/form.css">
 <script type="text/javascript">
    SERVICE_PATTERN_CHAT_CONFIG = {
        appId: '70a6624585ef2b0981fed84fcd12d4db',
        apiUrl: 'https://example.brightpattern.com/clientweb/api/v1',
        tenantUrl: 'example.brightpattern.com',
        chatPath: 'https://example.brightpattern.com/clientweb/chat-client-v4/',
        parameters:{
            test_var: 'Hello World', 
		 }
    };
 </script>
 <script src="https://example.brightpattern.com/clientweb/chat-client-v4/js/init.js"></script>


Note: You should use either the default customer data parameters or your own parameters, but not both. Customer parameters use variable $(item.externalChatData) to collect all customer data from the pre-chat form. If you include both default and custom parameters, you will have duplicate entries of first_name, last_name, email, and phone_number.

For more information, see the Scenario Builder Reference Guide, section Variables.

Step 4: Paste the snippet into your HTML file

Once you are done with step 3, paste the snippet into your HTML for use on your webpage.


  1. Note that default variables like "name" can be passed without using parameters declaration.
< Previous | Next >