Before creating a Slack bot we will explore the APIs. This will give us the knowledge needed to sketch out an architecture.
- [Narrator] So we want to build a Slackbot. Let's get into the details of the bot a bit later. Before we start designing our application, it makes sense to have a look at its API. So let's go to api.slack.com. We see that Slack offers a lot. And let's look at API here. The Web API provides us with a way to communicate with Slack. It's a typical chase-based HTTP API. Let's review the methods. By looking closer we see that it provides us with quite everything except a way to get messages pushed to us.
But there is a menu item called Real Time Messaging API. This looks promising. The intro on this page reads: The Real Time Messaging API is a WebSocket based API that allows you to receive events from Slack in real time and send messages to users. It's sometimes referred to as simply the "RTM API". I think this is what we are looking for, but what are WebSockets again? Regular HTTP requests are stateless. You request a page, the server processes the request, and sends the response.
After the request is processed, there is no connection between the client and the server. It's a one shot. WebSockets work a bit differently. There is an initial HTTP request where the client asks the server if it could do WebSockets, the WebSocket capable web server then replies, which completes the handshake. After that, a stateful bidirectional communication channel is opened. This means server as client can use this channel to send or receive messages. And this is exactly what we need for a chat application.
We see that the API provides everything we need, and that it relies on WebSockets. This information is important if we would want to run our application behind some web server or proxy. In this case, we would have to make sure that WebSocket connections are passed through to Node. We will later discuss if we are going to use an existing module to communicate with Slack, or build everything from scratch. But even if we will use a module, we should always know what's going on behind the scenes, and not blindly rely on third party code.
Please take some time to explore the Slack API a little bit further.
After explaining some basics about Node.js and microservices, Daniel shows you how to sketch out the planned architecture for your application and get the boilerplate code, modules, and credentials in place. Next, he shows how to create a bot user in Slack, connect to Slack, and post messages. He also shows you how to get your bot to process variations in text by creating logic that delegates the processing of intent to dedicated modules. Lastly, he shows how to register additional services and he covers how to use monitoring to identify architectural or performance issues.
- Using Slack APIs
- Sketching out a Slack bot architecture
- Setting up a project and choosing modules
- Creating and naming your bot
- Connecting to Slack
- Setting up and using natural language processing
- Routing by intents
- Implementing geocoding and time calculation
- Adding and monitoring services