Sendbird’s bot interface
Connect any bot to Sendbird so it can interact autonomously with users.
Connect a bot to Sendbird with the bot interface
Sendbird’s bot interface allows you to connect a bot to any 1-on-1 message or group channel so it can interact with users.
While Sendbird’s bot interface does not provide the AI, it accomplishes two necessary steps for implementing a chatbot:
- Connects a bot to Sendbird with a callback URL, so the bot can monitor user messages and events in real-time
- Enables the bot to join channels and send messages to users
Which apps should use Sendbird’s bot interface?
Bots can accomplish many simple or routine tasks at a large scale, provide answers to user questions quickly, and sell products or make suggestions based on a user’s information. By some measures, bots can resolve 40-80% of routine inquiries. So apps that manage high volumes of routine questions or tasks can use a chatbot to help users as quickly as possible. By freeing up customer agents for more complex tasks and reducing time-to-resolution for inquiries, your users feel helped and satisfied.
Use-cases for the chatbot interface
Since the purpose of existing chatbots varies so widely, it’s challenging to pin down specific use-cases by application type. The following, however, are a sample of successful use-cases:
- A chatbot that assists users during onboarding
- Use a chatbot to ask pre-screening questions or walk users through intake forms
- A concierge that makes smart suggestions or offers troubleshooting advice
- Sell simple products with a chatbot, or cross- and up-sell
- A virtual assistant for financial services
- A helper bot that answers routine questions
Implementing the chatbot interface
The rest of this guide instructs you how to implement a simple chat bot using Sendbird’s Platform API. This bot will respond with “pong” any time a user in it’s channel sends “ping.” Ultimately, this guide will familiarize you with Sendbird’s bot interface and prepare you to deploy various bots on your Sendbird application.
To implement a chatbot on AWS Elastic Beanstalk and a corresponding bot on SendBird, this guide will walk you through the following steps:
- Create a basic pong bot
- Deploy the bot on Elastic Beanstalk
- Set up a Sendbird bot
- Create a Sendbird user
- Create a Sendbird channel
- Create a Sendbird bot
- Add the bot to the channel
- Send a test message to the channel so the channel is visible
- Send messages to the channel to trigger a response from the bot
Create a basic pong bot
For this tutorial, Sendbird provides sample server code written in Python 3.6 that uses Flask. It can be deployed to AWS Elastic Beanstalk as a starting point for your own chatbot.
Read an explanation of the code in the README.md of this repository.
Note: Change the
api_token values in the config.py according to your own Application and Bot values.
Deploy the bot on Elastic Beanstalk
To get a chatbot running on a publicly accessible endpoint, this tutorial uses AWS Elastic Beanstalk so you don’t have to worry about the underlying infrastructure. AWS will handle the infrastructure and give us a web server to run our sample code.
Note: If you have a preferred cloud provider, feel free to use it. AWS Elastic Beanstalk is a suggestion for those without prior infrastructure knowledge.
AWS Flask/Python Reference
AWS Reference Documentation
Setup the Elastic Beanstalk CLI
For the commands in this tutorial, setup the Elastic Beanstalk CLI. Follow the AWS documentation for this because it applies generally:
Setup an Elastic Beanstalk Application Directory
eb init and follow the setup wizard. For this tutorial, accept the default options.
If you have never set up an AWS service using their CLI before, you may be prompted to authenticate your AWS account. Retrieve your credentials through the IAM section of the AWS Console.
Launch Bot on Elastic Beanstalk
eb create to launch an Elastic Beanstalk instance. For this tutorial, accept the default options suggested by the AWS CLI.
Once you have deployed your bot, you can take a look at Elastic Beanstalk on the AWS Console.
Note the URL of the bot. It will become part of the
bot_callback_url in the next section.
Set up a Sendbird bot
After setting up AWS Elastic Beanstalk, set up a corresponding bot on Sendbird using the Bot Interface. The Sendbird Bot will send commands to your chatbot on Elastic Beanstalk.
To create a Sendbird bot, use the Bot Interface – Create Bot Endpoint.
Add the /bot endpoint to
bot_callback_url since our server code listens for messages at this endpoint.
Create a Sendbird user
Create a Sendbird user using the Create User Endpoint. You can use any value for the user_id but note it for later steps in the tutorial.
Create a Sendbird channel
Create a Sendbird channel using the Create Channel Endpoint. In this example, add the user
test_user_1 to the channel (or the value of user_id created above). We’ll add the bot user to the channel in the next step, so do not add it for now.
Save the automatically generated
channel_url in the following response for later steps.
Add the bot to the channel
Next, add the Sendbird bot to the channel so it can receive messages and respond to them. This can be done using the Bot Interface – Join Channel Endpoint.
Send a test message to the channel so the channel is visible
The sample apps in the next section do not display channels without messages. Use the following Platform API call to send a test message to the channel so that it is visible in the channel list of the sample app.
Send messages to the channel to trigger a response from the bot
Now, your bot is ready to respond to a message.
If you don’t already have a Sendbird app running, use one of our sample apps and follow the instructions to replace the default
APP_ID with your application’s
Afterward, log in with the Sendbird user ID you created (not the bot) so you can interact with the bot.
The following image displays the login for
test_user_1 in a previous section.
After logging in, send the message “ping” to a channel. The bot responds with a “pong” after receiving the message event from Sendbird’s server.
The below image shows our first test message, “ping,” and then our exchange with the “pong” bot.
Redeploy changes to AWS Elastic Beanstalk
After deploying your bot, you may want to make changes to it like changing the response or changing the messages it will respond to. There are two options for redeploying.
eb CLI deploys the latest committed changes. If you do not make a commit, it will not use the latest changes.
git add * adds all new changes with committing.
Deploy them using
eb deploy --staged
Next Steps: cloud chatbot providers and upgrading infrastructure
For heavier traffic and more complex uses, we recommend using an infrastructure other than Elastic Beanstalk, like AWS EC2 or ECS, for better scalability and cost optimization of your chatbot.
This tutorial covers the implementation of a simple chatbot. But you’re now ready to implement more complex logic for your chatbot or integrate with cloud chatbot providers. They include Google’s DialogFLow and IBM Watson’s Chatbot. No matter which bot you choose, Sendbird’s bot interface can help you easily link it to chat and messaging on your app.