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"]

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.


Fetch Opportunity:

Assign Opportunity Stage:

7. Update the BOT.

Package.xml to retrieve the BOT:
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="">

Context Variable to BOT to store Tracking Number from Chat Transcript:
Add the below to the retrieved BOT and deploy it.

        <label>Tracking Number</label>

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.