This guide explains how to integrate Sendbird Chat with Salesforce Einstein Bots using Salesforce Connector. Because Einstein Bots are part of the customer service supported by Salesforce Service Cloud, you must integrate Sendbird Chat with Salesforce Service Cloud first. See our Docs on Salesforce Service Cloud integration before continuing with the bot integration.
Add Einstein Bot as a Connected App to Salesforce to allow the bots to authenticate themselves and use Salesforce APIs and standard protocols.
Go to Setup Home > App Manager and select New Connected App in the top-right corner of the screen.
Fill in all the required fields of the Basic Information section.
Connected App Name: Enter any value of your choice.
API name: This is automatically generated once you enter Connected App Name.
Contact email: Enter an email address for the app.
Move on to the API (Enable OAuth Settings) section. Check and fill in each field according to the following instructions and Save.
Check the box next to Enable OAuth Settings.
Callback URL: Enter https://login.salesforce.com/services/oauth2/callback.
Selected OAuth Scopes: Add Access chatbot services (chatbot_api) and Perform requests at any time (refresh_token, offline_access) to Selected OAuth Scopes.
Check the box next to Require Secret for Web Server Flow.
Check the box next to Require Secret for Refresh Token Flow.
Check the box next to Enable Client Credentials Flow.
Creating a new Connected App on Salesforce can take up to 10 minutes.
Once the Connected App is created, click Continue. You will return to the Manage Connected Apps page. In that page, click Manage Consumer Details. Copy the Consumer Key and the Consumer Secret on the side because they are required when when saving bot data to a Sendbird__c object in Step 3.
Click the Edit Policies button at the top of the page. Then, on the dropdown list next to Permitted Users, select Admin approved users are pre-authorized as shown in the image below.
Scroll down to the Client Credentials Flow section, search and add the user you created in Step 1.
Now configure Einstein Bots on Salesforce to integrate with Sendbird Chat. To learn more about the basics and details of Einstein Bots on a design level, see Salesforce’s cookbook on Einstein Bots.
You can see a list of bots you've created in Setup Home > Einstein > Einstein Platform > Einstein Bots on Salesforce. Here, select a bot to integrate and turn it on to make API calls.
Choose the name of your Einstein Bot.
Then, Einstein Bot Builder will appear. In the top-left corner of the screen, on the Dialog dropdown list, select Overview.
Scroll down to the Connections section and select Add in the top-right corner of the section.
Select API for Connection and search the name of Einstein Bot you will integrate in Connected App. Copy the Runtime Base URL on the side because the URL is needed when saving bot data to a Sendbird__c object in the following section.
Once you return to the Einstein Bots page, make sure that API is activated for the bot. You can find the information in the Connections column of the My Bots table.
Click the Setup button in the top-right corner of your screen and you will find the Developer Console.
Set values of the following properties in a Sendbird__c object.
Property name
Type
Description
Einstein_Bot_enabled__c
boolean
Determines whether to enable the Einstein Bot feature. The value should be set to true.
Einstein_Bot_ID__c
string
Specifies the ID of Einstein Bot to integrate. To find the ID, go to Setup Home > Einstein > Einstein Platform > Einstein Bots > My Bots and click your bot name.
Einstein_Bot_Runtime_Base_URL__c
string
Specifies the Runtime Base URL of your Einstein bot. To find the URL, go to Setup Home > Einstein > Einstein Platform > Einstein Bots > My Bots and click your bot name. In the top-left corner of the screen, on the Dialog dropdown list, select Overview. At the Connections section, select Edit to see the URL.
Einstein_Bot_Client_ID__c
string
Specifies the client ID of the Einstein Bot Connected App. In Salesforce, it’s referred to as Consumer Key.
Einstein_Bot_Client_Secret__c
string
Specifies the client secret for Einstein bot connected app. It’s referred to as Consumer Secret.
Once you've created the object, select the Query Editor tab at the bottom of the Developer Console window and execute the following query.
SELECT FIELDS(ALL) FROM Sendbird__c WHERE Name='SB-0000' LIMIT 1
Then a Sendbird__c object like below will be created.
Note: Sendbird can only recognize a Sendbird__c object whose Name is set to SB-0000. If you entered a wrong value to the object, correct the value of the cell directly on the Console instead of running the code multiple times and creating more objects.
To send an HTTP request to and from Salesforce, your Sendbird API request URL must be registered as a Remote Site on Salesforce. Einstein Bots are considered an external service on Salesforce as well, so the bot should also be added to Remote Site Settings.
On Salesforce Service Cloud's Setup Home, type Remote Site Settings in the Quick Find search bar. Or go to Setup Home > Security > Remote Site Settings in the left menu bar.
Select New Remote Site at the top of the Remote Site table.
Fill in each field according to the following instructions and Save.
Remote Site Name: Enter EinsteinBots.
Remote Site URL: Enter your Einstein_Bot_Runtime_Base_URL__c you copied in the Bot Connections API section.
Salesforce Service Cloud doesn’t provide a client-side SDK and a dedicated server that can process the API requests or Sendbird Chat's callback. Use AWS’s Lambda, your own server, or create an API endpoint in Apex to make and receive API calls. In this guide, you can see how to create a public endpoint in Apex for a quick and easy implementation. If you've created a public endpoint during the integration process for Salesforce Service Cloud, you can use the same Site URL.
On Salesforce Service Cloud, go to Setup > User Interface > Sites and Domains > Sites in the left menu bar. If you already have a site domain you can use, select Site Label of your choice and skip to #5. If you don’t have a site yet, choose Sites Terms of Use first and then click Register My Salesforce Site Domain.
Click the New button at the top of the Sites table.
Fill in and check each item according to the following instructions and Save.
Site Label: Enter a name of your choice.
Site Name: This is automatically generated once you’ve entered Site Label.
Active Site Home Page: Choose any site from the search list. This won’t affect the behavior of the Site.
Check the box next to Active.
Check the box next to Lightning Features for Guest Users.
Check the box next to Enable Content Sniffing Protection.
Check the box next to Enable Browser Cross Site Scripting Protection.
Check the box next to Referrer URL Protection.
Check the box next to Redirect to Custom Domain.
Check the box next to Cache public Visualforce pages.
Note: Make sure to leave Default Web Address empty.
Once done, you'll see Site Details of the new site you’ve created. Select Public Access Settings at the top of the Site Details page.
Select Enable Apex Class Access at the top of the table. This will land you to the Enabled Apex Class Access section. Then click the Edit button next to the section title.
Select WebhookController from Available Apex Classes and add it to Enabled Apex Classes.
Save and you will see the controller added as an accessible class.
Now you can send a message to the Apex REST API server you’ve created using the following sample. Copy the Site URL from the Sites list because it's needed when turning on Salesforce integration on Sendbird Dashboard in Step 6.
Step 5: Grant access to Connected Apps and Sendbird__c
Go to Apps > App Manager and find the name of Einstein Bot you've created in Step 2. Then click the down arrowhead button at the end of the row and click Manage.
Scroll down to Profiles and select Manage Profiles.
From the list, select two profiles: the user you've created in Step 1 and Apex REST endpoint Sites you've created in Step 4. The label for integration user would read as Salesforce API Only System Integrations while the label for Site as {SITE_NAME} Profile.
Enable Sendbird Chat webhook to access a Sendbird__c object
Einstein Bots use the Sendbird Chat webhook, which is considered as a guest user in Salesforce. You'll need to grant the webhook access to the Sendbird__c data.
Go to Security > Sharing Settings.
In the Manage sharing settings for tab dropdown list, select Sendbird.
Scroll down to Sendbird Sharing Rules and and click the New button next to the title.
Fill in each field according to the following instructions and Save.
Step 1: Rule Name: Enter Sendbird Sharing Rule for Label. Rule name is automatically generated.
Step 2: Select your rule type: Select Guest user access, based on criteria.
Step 3: Select which records to be shared: Select Name and equals for Field and Operator, respectively, and enter SB-0000 for Value.
Step 4: Select the users to share with: Select {your_site_name} Site Guest User for Share with.
Step 5: Select the level of access for the users: Select Read only for Access Level.
Step 6: Enable Einstein Bots on Sendbird Dashboard
On Sendbird Dashboard, go to Settings > Chat > Integrations and click Salesforce.
You will find the Einstein Bots settings in the Add-on services box under API token. Fill in each field according to the following instructions.
Apex REST endpoint: Copy and paste the Apex REST endpoint URL you’ve created in Step 4. The URL can be found in the Sites page on Salesforce. An example can be https://{YOUR_SALESFORCE_SITE_URL}/services/apexrest/webhook/.
Einstein Bots: Turn on this option to use Einstein Bots with Sendbird Chat.
Click the Save button.
You can now receive Sendbird's group channel events through the Apex REST endpoint.
Step 7: Set up a Queue and Assignment Rules for Einstein Bots
In Salesforce Service Cloud, each issue raised by customers or agents is called Case and Cases are queued and assigned to its members according to Assignment Rules. Create a Queue and Assignment Rules for the Cases that utilizes Sendbird Support Chat.
This guide demonstrates the basic requirements for the integration. To learn more about how to customize Queues and Assignment Rules, see Salesforce guide.
To assign Cases connected to Sendbird Chat to agents, you must create a dedicated Queue and Assignment Rules for them.
Go to Setup Home > Administration > Users > Queues the left menu bar or search Queues in Quick Find.
Click on the New button at the top of the Queues table.
Fill in each field according to the following instructions and Save.
Label: Set the Label of this new queue to Einstein Bot Queue as shown in the image below. The value of Label must be Einstein Bot Queue. Otherwise, conversations through Sendbird Chat SDK won’t properly show in the Cases.
Queue Name: Once Label is entered, Queue Name is automatically generated.
Supported Objects: Select Case in Available Objects and add it to Selected Objects.
Queue Members: Leave Selected Members of this queue empty to prevent Cases from being assigned to human agents.
You can create assignment rules for a case under Setup Home > Feature Settings > Service > Case Assignment Rules and click on the New button. After you create your rule, select it from the assignment rules list and add rule entries as shown in the image below. Sendbird Chat for Salesforce Service Cloud utilizes a Case object’s custom field to differentiate conversations between a chatbot and a live agent.
Go to Setup Home > Feature Settings > Service > Case Assignment Rules in the left menu bar or search Case Assignment Rules in Quick Find.
Click the New button at the top of the Assignment Rules table.
Enter a name for the new assignment rule and Save. You will return to the Case Assignment Rules page. Select the rule you just created.
Click the New button in the Rule Entries section.
Enter a new rule entry as shown in the image below and Save.
Step 1: Set Sort Order to 1. The order of Einstein Bot Queue must precede other Queues for human agents so that bots can take new Cases first.
Step 2: Salesforce Connector utilizes a Case object’s custom field to differentiate conversations by a chatbot and a human agent. Select Case: Is Einstein Bot Case and equals for Field and Operator. Then enter true in Value as shown below.
Step 3: Select the queue to apply this Assignment Rule to. Select Queue in the dropdown menu and search Einstein Bot Queue you just created in the previous section.
Note: Make sure that the Sort Order of your Einstein Bot Queue comes before the Sendbird Chat Queue you've created for human agents.
Step 8: Client-side implementation for Einstein Bots
Once you’ve set up both Sendbird Dashboard and Einstein Bots on Salesforce, implement the following codes to send and receive messages from Einstein Bots on your app.
For the implementation of general chat features such as loading a list of group channels, entering a channel, and sending messages, see our Sendbird Chat Docs.
Bot messages are similar to regular user messages but can be distinguished by the following properties. Use the fields to handle messages from Einstein Bots.
Property name
Type
Description
data
string
Additional message information. This is a stringified JSON format of message response from Einstein Bot API. You can parse the value to get the message.
user_id
string
The unique ID of the message sender. The value of this property for Einstein Bot is set to einstein-bot. You can edit Einstein Bots' user profile on Sendbird Dashboard.
Einstein Bots send four types of messages: text, choices, escalate, and sessionEnded. These message data are stringified and stored in the message's data field.
textchoicesescalatesessionEnded
{
"id": "76074ef7-9f7b-406e-8c26-f74541c1dca3",
"schedule": {
"responseDelayMilliseconds": 1200
},
"type": "text",
"text": "Hi, I’m Bot123, a digital assistant."
}
Messages can be sent from Sendbird Chat SDK or through Platform API. In order for the Sendbird server to recognize those message objects, the messages’ custom_type must be set to EINSTEIN_BOT_START_SESSION. The following is an example of the initiating message object in JSON format.
{
"type": "MESG",
"message_id": 3879686875,
"message": "I want to talk to a bot.",
"custom_type": "EINSTEIN_BOT_START_SESSION",
"data": "",
"created_at": 1671702626160,
"channel_url": "sendbird_group_channel_78300127_b52e9db99fe00accbfc96e7bbc7118cd1d1a9701",
/* Other message properties below ...*/
}
Salesforce Connector internally makes Einstein Bots API calls and responses from the bot API are saved as a message in a group channel. The following is a message example in JSON format.
{
"type": "MESG",
"message_id": 3879687532,
"message": "Hello, world!",
"data": "{\"type\":\"text\",\"text\":\"Hello, world!\",\"id\":\"55a65869-eec3-4560-bd7b-13a66f43a4f2\"}", // The message data received from the Einstein Bot API is stringified in the `data` field.
"custom_type": "",
"created_at": 1671702629183,
"channel_url": "sendbird_group_channel_78300127_b52e9db99fe00accbfc96e7bbc7118cd1d1a9701",
"user": {
"user_id": "einstein-bot",
"nickname": "Einstein Bot",
"is_active": true
/* Other user properties... */
},
"mention_type": "users",
/* Other message properties... */
}
To end a chat with Einstein Bots, set the message’s custom_type to EINSTEIN_BOT_END_SESSION and send it to the channel. The following is an example of the ending message object in JSON format.