Bots are an inherent part of Slack. Everyday, teams across the world use Slack bots to increase their productivity, better communicate or have fun at the office.
Recast.AI allows you to build, train, host, connect and monitor new bots on Slack! To show you how simple it is to build a Slack bot with Recast.AI, let’s walk you through the creation of a Chuck Norris jokes bot.
Here are the main steps of bot building we cover in this tutorial:
1 – Create and train the bot on Recast.AI
2 – Connect it to Slack using Bot Connector
3 – Fork our starter kit repository on GitHub to code and customize the bot
4 – Deploy your bot on Bot Hosting
Create and train your bot on Recast.AI
First, we need a bot on Recast.AI, so let’s login to the platform and create a new bot:
You can see that your new bot contains greetings and goodbyes default intents:
Now, let’s add our main intent: get-joke. Click on the + CREATE button and type your intent name.
Enter expressions you want your bot to understand. These expressions are training it to understand when a user asks for a joke.
We don’t need extensive training for this tutorial, so let’s move on to the next step. In the “build” tab, you can set the logic of your bot and its replies. For instance, click on the edition symbol of the “greeting” block: you can consult and edit replies your bot provides when a user says “hello”. To add a new action, click on the “+” button and select get-joke!
Connect your bot to Slack
Go to the “Run” tab, select “Slack”.
1/ Create a Slack App
Create a new Slack app using this link.
Fill the form with your App Name and your Development Slack Team name. If you don’t have a team yet, create one.
2/ Get your credentials
Go to Settings > Basic Information, scroll down and fill the form within Bot Connector with your Client ID and Client Secret. You can find them in the App Credentials section.
3/ Add a new bot user
In the Bot Users tab, create a new bot user.
4/ Set the OAuth redirect URL
In the OAuth & Permission tab, fill the Redirect URL with the OAuth URL provided within Bot Connector.
5/ Enable interactive messages
In the Interactive Messages tab, enable and fill the Request URL with the Events URL of your channel.
6/ Fill the Events redirect URL
In the Event Subcription tab, enable and fill the Request URL with the Events URL of your channel.
Scroll down to the “Subcribe to Bot Events” section, and enable the following events (or others, according to the behavior you want your Slack bot to have):
That’s it! You can already test your bot by hitting the button “Add to Slack” and start chatting:
Customize your Bot
If you need to customize your bot by implementing an external API, you need to code the integration and deploy it. In our case, we’re using https://api.chucknorris.io to get Chuck Norris facts.
First, go to the Code tab, clone the starter kit and follow the indications to run your bot locally.
Then, code your bot logic. If you want to see the code of the Chuck Norris bot, here’s the GitHub repository.
Now, create a public repo on Github:
Change the remote URL of your code to push to your new Github repo:
Go to the Run tab, then go to the Bot Hosting sub-tab.
Connect your account to Github and link your repository:
Click on “Connect your repo” to start deploying your repository. Wait 2 minutes for deployment and start talking to your bot!
Congratulations, you’ve made it!
Again, you can find the complete code on Github and the bot on Recast.AI.
If you have any feedback, question or suggestion, drop us an email at email@example.com or join our Slack Community (https://slack.recast.ai).