Pass data from Chat to Einstein BOT in Salesforce

Pass data from Chat to Einstein BOT in Salesforce

embedded_svc.settings.extraPrechatFormDetails can be used to pass data from Chat to Einstein BOT in Salesforce.

Note:

This Blog Post is applicable only for Chat feature and not for Messaging feature.

1. Create a custom field in the Chat Transcript object/entity.

2. Add the following code to your existing Chat Snippet Code.

embedded_svc.settings.extraPrechatFormDetails = [ {
	"label" : "Site",
	"value" : window.location.href,
	"transcriptFields" : [ "Chat_Site__c" ]
} ];

3. Extract your Einstein BOT. Following package.xml can be used.

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

4. Add the following code and deploy the BOT.

<contextVariables>
    <contextVariableMappings>
        <SObjectType>LiveChatTranscript</SObjectType>
        <fieldName>LiveChatTranscript.Chat_Site__c</fieldName>
        <messageType>WebChat</messageType>
    </contextVariableMappings>
    <dataType>Text</dataType>
    <developerName>Chat_Site_Context</developerName>
    <label>Chat Site Context</label>
</contextVariables>

5. Create a Custom Variable in the Einstein BOT.

6. Use Set Variable element to set the value to the Custom Variable. Use the Custom Variable to display it on the screen using Message component to test.

Output:

Leave a Reply