Support Chat Guide v1
Support Chat
Version 1

Integrate with Salesforce Einstein Bots

Copy link

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

Copy link

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.

  1. On Salesforce Service Cloud, go to Setup > Users > New User.

  2. 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.


  1. Save to create a user.

  2. 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.


  1. 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.

  2. Under Object Permissions, check the box next to Read and Edit for Enabled. Click Save.

  3. Go back to Object Settings and click Work Type Groups. Check the box next to Read and Edit for Enabled and click Save.

  4. 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.

  5. 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.

  6. 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

Copy link

Add the Einstein Bot as a Connected App to Salesforce so that the bot can authenticate themselves and use Salesforce APIs and standard protocols.

  1. Go to Setup > Apps > App Manager and select New Connected App in the top-right corner of the screen.

  2. 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.


  1. 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.

  1. Creating a new Connected App on Salesforce can take up to 10 minutes.

  2. 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.

  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.

  1. Scroll down to the Client Credentials Flow section. Search and add the user you've created in Step 1.

  1. Click Save at the bottom of the page.

  2. Click Manage Profiles button at the Profiles section. Select Salesforce API Only System Integrations and Save.


Step 3: Configure the Einstein Bots settings

Copy link

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

Copy link

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.

  1. Choose the name of your Einstein Bot.

  2. Then, Einstein Bot Builder will appear. In the top-left corner of the screen, select Overview on the Dialog dropdown list.

  3. Scroll down to the Connections section and select Add in the top-right corner of the section.

  4. 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.

  1. 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

Copy link

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.

  1. Click the Setup button in the top-right corner of your screen and open Developer Console.

  2. Set the values of the following properties in a Sendbird__Setting__c object.

Property nameTypeDescription

Sendbird__EnableEinsteinBots__c

boolean

Determines whether to enable the Einstein Bot feature. The value should be set to true.

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.


  1. Once you've updated 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__Setting__c LIMIT 1
  1. 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

Copy link

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.

  1. 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.

  2. Select New Remote Site at the top of the Remote Site table.

  3. 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

Copy link

You can turn on and off the integrated Einstein Bot on Sendbird Dashboard according to your business needs.

  1. On Sendbird Dashboard, go to Settings > Chat > Integrations and click Salesforce.

  1. 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

Copy link

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

Copy link

To assign Cases connected to Sendbird Chat to Einstein Bots, you must create a dedicated Queue and Assignment Rules for them.

  1. Go to Setup > Users > Queues the left menu bar or search Queues in Quick Find.

  2. Click on the New button at the top of the Queues table.

  3. 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

Copy link

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.

  1. Go to Setup > Feature Settings > Service > Case Assignment Rules in the left menu bar or search Case Assignment Rules in Quick Find.

  2. Click the New button at the top of the Assignment Rules table.

  3. 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.

  4. Click the New button in the Rule Entries section.

  5. 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 as Sendbird 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

Copy link

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.

  1. Go to Security > Sharing Settings under Security in the left menu bar. Or you can search the menu in the search box.

  2. Select Cases for the Manage sharing settings for menu.

  3. In the Sharing Rules section, click New to create a rule for the bots.

  4. 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.

  1. Click Save.

Step 7: Client-side implementation for Einstein Bots

Copy link

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

Copy link

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 nameTypeDescription

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.

Message types

Copy link

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."
}

Start a chat with Einstein Bot

Copy link

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.

{
  "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 ...*/
}

Receive messages from Einstein Bots

Copy link

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.

{
  "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... */
}

End a chat with Einstein Bots

Copy link

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.

{
  "type": "MESG",
  "message_id": 3879686875,
  "message": "Resolved!",
  "custom_type": "EINSTEIN_BOT_END_SESSION",
  "data": "",
  "created_at": 1671702626160,
  "channel_url": "sendbird_group_channel_78300127_b52e9db99fe00accbfc96e7bbc7118cd1d1a9701"
  /* Other message properties below ...*/
}