Integrate with Salesforce Einstein Bots
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.
Step 1: Create a user and grant the permission set
First, create a new user that will operate as a bot and register their information to Connected Apps. The user's information is used when authenticating Einstein Bots. Then, create and grant a permission set for the user so that Support Chat Connector can acquire permissions for sObject
, required by the Salesforce's policy.
-
On Salesforce Service Cloud, go to Setup > Users > New User.
-
Fill in all the required fields in the Basic Information section.
-
Last Name: Enter
Sendbird Connected App User
. -
Alias: Enter
SBUser
. -
Email: Enter an email address for the bot.
-
Username: Enter an email address to be used as a Username. This address must be different from the one used in Email.
-
Role: Select < None Specified > from the dropdown list.
-
Nickname: This is automatically generated.
-
User License: Select Salesforce Integration from the dropdown list.
-
Profile: Select Salesforce API Only System Integrations from the dropdown list.
-
Save to create a user.
-
Now, go to Setup > Users > Permission Sets and create a permission set for
sObject
. Click the New button at the top-left corner of the table and fill out the required fields. Then Save.
-
Label: Enter
Sendbird Connected App with sObject
. -
API Name: This is automatically generated.
-
Once the set is created, you will see a list of Salesforce apps of which you can configure the permission settings for
sObject
. Go to Object Settings under the Apps section. Then, select Cases and click Edit. -
Under Object Permissions, check the box next to Read and Edit for Enabled. Click Save.
-
Go back to Object Settings and click Work Type Groups. Check the box next to Read and Edit for Enabled and click Save.
-
Now you can assign the permission set to the user you've created in #2. Go to Setup > Users > Users, select Sendbird Connected App User from the list, and scroll down to the Permission Set License Assignments section. Click Edit Assignments, scroll down to the Salesforce API Integration section, and check the box for Enabled. Click Save.
-
Scroll down to the Permission Set Assignments section and click Edit Assignments. Add Sendbird Connected App and Sendbird Connected App with sObject to Enabled Permission Sets. Click Save.
-
Go to Setup > Users > Profiles and select Salesforce API Only System Integrations from the list. Scroll down to the Enabled Apex Class Access section and click Edit. Add sendbird.WebhookController to Enabled Apex Classes and click Save.
Step 2: Create a Connected App
Add the Einstein Bot as a Connected App to Salesforce so that the bot can authenticate themselves and use Salesforce APIs and standard protocols.
-
Go to Setup > Apps > 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
Sendbird Connected App
-
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), Manage user data via APIs(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 see to the Manage Connected Apps page for the new app. In that page, click Manage Consumer Details. Copy and save the Consumer Key and the Consumer Secret because they're required when saving bot data to a
Sendbird__Setting__c
object in the following step. -
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've created in Step 1.
-
Click Save at the bottom of the page.
-
Click Manage Profiles button at the Profiles section. Select Salesforce API Only System Integrations and Save.
Step 3: Configure the Einstein Bots settings
Now configure the Einstein Bot settings on Salesforce for integration with Sendbird Chat. To learn more about the basics and details of Einstein Bots on a design level, see Salesforce’s cookbook.
Bot Connections API
You can see a list of bots you've created in Setup > 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, select Overview on the Dialog dropdown list.
-
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 and save the Runtime Base URL because the URL is needed when saving bot data to a
Sendbird__Setting__c
object in the next 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.
Update the Sendbird__Setting__c
object
Update the properties related to the Einstein Bot in the Sendbird__Setting__c
object using Salesforce's Developer Console. To learn more, see our documentation on how to create a Sendbird__Setting__c
object.
-
Click the Setup button in the top-right corner of your screen and open Developer Console.
-
Set the values of the following properties in a
Sendbird__Setting__c
object.
Property name | Type | Description |
---|---|---|
Sendbird__EnableEinsteinBots__c | boolean | Determines whether to enable the Einstein Bot feature. The value should be set to |
Sendbird__EinsteinBotsId__c | string | Specifies the ID of Einstein Bot to integrate. To find the ID, go to Setup > Einstein > Einstein Platform > Einstein Bots and click your bot name in the My Bots tab. |
Sendbird__EinsteinBotsRuntimeBaseUrl__c | string | Specifies the Runtime Base URL of your Einstein bot. To find the URL, go to Setup > Einstein > Einstein Platform > Einstein Bots and click your bot name in the My Bots tab. 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. |
Sendbird__ConnectedAppClientId__c | string | Specifies the client ID of the Einstein Bot Connected App. In Salesforce, it’s referred to as Consumer Key. |
Sendbird__ConnectedAppClientSecret__c | string | Specifies the client secret for Einstein bot connected app. It’s referred to as Consumer Secret. |
- Once you've updated the object, select the Query Editor tab at the bottom of the Developer Console window and execute the following query.
- Then a
Sendbird__Setting__c
object like below will show.
Note: If there are multiple objects, Sendbird uses the oldest
Sendbird__Setting__c
object.
Register a Remote Site for Einstein Bots
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 > 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
Sendbird__EinsteinBotsRuntimeBaseUrl__c
you copied in the Bot Connections API section. -
Active: Check the box next to Active.
Step 4: Enable Einstein Bots on Sendbird Dashboard
You can turn on and off the integrated Einstein Bot on Sendbird Dashboard according to your business needs.
- 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.
-
Instance URL: You can find it from Settings > Company Settings > My Domain on Salesforce. The URL should be in the format of
https://[your-domain].my.salesforce.com
. -
Client ID: Specifies the client ID of the connected app. In Salesforce, it’s referred to as Consumer Key.
-
Client Secret: Specifies the client secret of the connected app. It’s referred to as Consumer Secret.
-
Einstein Bots: Turn on this option to use Einstein Bots with Sendbird Chat.
Step 5: 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 Einstein Bot integrated with Sendbird Chat.
This guide demonstrates the basic requirements for the integration. To learn more about how to customize Queues and Assignment Rules, see Salesforce guide.
Create a Queue
To assign Cases connected to Sendbird Chat to Einstein Bots, you must create a dedicated Queue and Assignment Rules for them.
-
Go to Setup > 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. -
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.
Add Case Assignment Rule Entry
Sendbird Chat integrated with Salesforce Service Cloud utilizes a Case object’s custom field to differentiate conversations between a chatbot and a live agent. You can create Assignment Rules applicable for those Einstein Bot Cases under Setup > Feature Settings > Service > Case Assignment Rules. After you create a new rule, select it from the list and add Rule Entries as shown in the image below.
-
Go to Setup > 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 name 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, such asSendbird Chat Queue
you've created 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, respectively. 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.
Step 6: Configure the sharing settings for the bots
In order for the bots to actually see and access the cases in queue, cases need to be shared with them. To do so, create a sharing rule for bots in the Sharing Settings page.
-
Go to Security > Sharing Settings under Security in the left menu bar. Or you can search the menu in the search box.
-
Select Cases for the Manage sharing settings for menu.
-
In the Sharing Rules section, click New to create a rule for the bots.
-
Fill out the following fields:
- Step 1: Rule Name: specify an unique label and its name will be automatically generated.
- Step 2: Select your rule type: select Based on criteria.
- Step 3: Select which records to be shared: set the value of each field as follows:
- Field: Is Einstein Bot Case
- Operator: Equals
- Value: True
- Step 4: Select the users to share with: share with Public Groups and All internal users.
- Step 5: Select the level of access for the users: set to Read only.
- Click Save.
Step 7: Client-side implementation for Einstein Bots
Once you’ve set up the integration environment on both Sendbird Dashboard and Salesforce, implement the following codes to send and receive messages for the Einstein Bots on the client 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
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 |
Message types
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.
Start a chat with Einstein Bot
Messages can be sent from Sendbird Chat SDK or through Platform API. In order for the Sendbird server to recognize message objects for Einstein Bots, 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.
Receive messages from Einstein Bots
Salesforce Connector internally makes Einstein Bots API calls and the responses from the bot API are saved as a message in a group channel. The following is a message example in JSON format.
End a chat with Einstein Bots
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.