How to pass Pre-Chat data from Chat to Einstein Bot in Salesforce?

How to pass Pre-Chat data from Chat to Einstein Bot in Salesforce?

1.  Create a custom field in Case object to get the values from Pre-Chat.

2. Create a custom field in Chat Transcript object to store the values from Pre-Chat.

3. Create a custom field in Opportunity object to fetch the opportunity record based on the Tracking Number from Pre-Chat and show the Status to the Chat Visitor.

4. Add the Custom Field created in Step 1 to the Embedded Service Deployment.

5. Add the below code to your Embedded Service Code. This is will store the Tracking Number from Pre-Chat to the Chat Transcript record.

embedded_svc.settings.extraPrechatFormDetails = [ {
	"label" : "Tracking Number",
	"transcriptFields" : [ "Tracking_Number__c" ]
} ];

Note:

If you are using Experience/Community Cloud, you have to add it to your Snippet JavaScript Static Resource.

6. Create a Simple Flow to fetch Opportunity Stage based on Tracking Number.

Variables:

Fetch Opportunity:

Assign Opportunity Stage:

7. Update the BOT.

Package.xml to retrieve the BOT:

<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<types>
<members>Chat_Bot</members>
<name>Bot</name>
</types>
<types>
<members>*</members>
<name>MlDomain</name>
</types>
<version>52.0</version>
</Package>

Context Variable to BOT to store Tracking Number from Chat Transcript:

Add the below to the retrieved BOT and deploy it.

<contextVariables>
	<contextVariableMappings>
		<SObjectType>LiveChatTranscript</SObjectType>
		<fieldName>LiveChatTranscript.Tracking_Number__c</fieldName>
		<messageType>WebChat</messageType>
	</contextVariableMappings>
	<dataType>Text</dataType>
	<developerName>TrackingNumber</developerName>
	<label>Tracking Number</label>
</contextVariables>

Create Variables in the BOT and check the Context Variable:

Create a Dialog to handle when Tracking Number is Entered:

Welcome Dialog Updates:

a. Set Variable Rule to store the Tracking Number from Chat Transcript to Tracking Number variable.

b. Another Rule action to check if Tracking Number is entered and calling the Dialog to check the Opportunity Status.

Output:

Leave a Reply