Book Image

Building Slack Bots

Book Image

Building Slack Bots

Overview of this book

Slack promises that its users will "be less busy." Slack bots interact with users in Slack chatrooms, providing useful immediate information, and automating work. This book gives you everything you need to build powerful and useful Slack bots. You’ll see how to hook into the Slack API to create software that can read and post to chatrooms, respond to commands and hints given in natural conversational language, and build fun and useful bots for your own place of work, both as a front end to your own service and to distribute and share as apps. You can even sell your bots and build a business as a Slack bot developer. Throughout the book, you’ll build useful and fun example applications that you can modify for your own situations. These range from simple, fun applications to liven up discussions to useful, data-driven apps to help you make decisions quickly and manage work.
Table of Contents (14 chapters)

Understanding the OAuth process


In order to implement a bot user in a team that is not our own, we require a bot token similar to the ones we created earlier for our own team. We can request this token, but first we must prove that we are who we say we are using the OAuth process. OAuth (Open Authentication) is an open standard for authentication used by many companies, large and small.

The authentication process works through the following steps:

  1. The user clicks the Add to Slack button.

  2. Slack sends a request to the redirect URI provided in our app's settings page.

  3. Once the request is received on our server, we redirect it to the authorization API endpoint (https://slack.com/oauth/authorize) and include the following parameters in the query string:

    • client_id: This is the unique ID given to us when we first created our app.

    • scope: This includes the permissions we require for our app. We will go into more detail on scopes later in this chapter.

    • redirect_uri: This is an optional parameter. This...