Using Hidden Pre-Chat Hidden fields, we can pass data to the Omni-Channel Flow. Next, in the Omni-Channel Flow, we can update the Messaging Session record with the Pre-Chat Hidden Fields. Finally, using Context Variable in the Einstein BOT, we can use Context Variable and map it to a Custom Variable in the Dialog and use it.
1. Create a Custom Field in the Salesforce Messaging Session object. This field will be used to create a Context Variable on the Einstein BOT.
2. Create a Custom Parameter and do the Parameter Mappings.
3. Enable the Pre-Chat and add the Hidden Pre-Chat field.
4. Use setHiddenPrechatFields to pass the Hidden Pre-Chat field value.
Sample Code for setHiddenPrechatFields:
window.addEventListener( "onEmbeddedMessagingReady", () => {
console.log( "Inside Prechat API!!" );
embeddedservice_bootstrap.prechatAPI.setHiddenPrechatFields( {
"Site" : window.location.href
} );
} );
5. Create Custom and Context variable in the Einstein BOT.
6. In the Einstein BOT Context Variable, map the Messaging Session custom field.
7. In the Einstein BOT Dialog, use Set Variable element to map the Context Variable value to the Custom Variable. Message component on the Einstein BOT can be use to display the Custom Variable value.
Output: