Chapter 7. Publishing Your App
At this point, you have all the knowledge needed to build a bot that can increase your productivity and improve communications across teams. Hopefully, by now you have already thought of an idea for a bot that will not just make your own life easier but may also be useful for others. In this chapter, you will learn how to make your bot accessible to users outside of your own team and across the Slack community.
We will cover the steps necessary to add your bot to the Slack app directory and to make it accessible to others. We will review the following steps to add your bot onto the Slack app directory:
Registering your bot and obtaining tokens
Understanding the OAuth process
Configuring the Add to Slack button
Scopes
Submitting your app or bot to the app directory
Monetizing your bot
In order to make adding apps easy for their users, Slack has created the app directory (https://slack.com/apps). This is a place to shop for apps and bots to add to your Slack team. Like other app stores available, every app submitted to the app directory is controlled and has to be approved by Slack itself to counteract spam and abuse.
It is possible for other teams to use your bot by means of webhooks, as we saw in the previous chapter. However, if you are trying to reach a wide audience and potentially monetize your bot, the app directory is the most efficient way.
The end goal of this chapter is to allow users to add a bot to their Slack team by clicking an Add to Slack button, which we will cover in detail later.
Let's start by registering an app. In this example, we will add the Wikibot bot, which we built in Chapter 3, Adding Complexity.
Note
Please note that our registering of Wikibot (and the use of the Wikipedia API...
Registering your app and obtaining tokens
Certain unique tokens are required in order to successfully authenticate with Slack's OAuth servers. This is necessary so that Slack can determine whether we are who we say we are and whether our app or bot is actually integrated with the team we are attempting to get access to.
We start by navigating to the Slack new app registration page at https://api.slack.com/applications/new. Fill out the form by picking a name for your bot, the team it originated from, descriptions of your bot, links to help pages, and a redirect URI:
After saving your settings, you can choose to set up a bot user, webhook, or slash command. For Wikibot, we will be setting up a bot user.
Once you've saved your changes, you should be presented with OAuth information on the next screen. First, make sure to save the Client ID and Client Secret...
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:
The user clicks the Add to Slack button.
Slack sends a request to the redirect URI provided in our app's settings page.
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...
OAuth scopes allow you to specify exactly what access your app needs to perform its functions. In the previous example, we requested the bot
scope, which gives our bots access to all the actions a bot user can perform. For example, the channels:history
scope gives us access to the channel's chat history and users:read
allows us to access the full list of users in the team. There is a long list of scopes available (which you can review at https://api.slack.com/docs/oauth-scopes), but we will focus on the three most likely to be used scopes in our apps:
bot
: This provides a bot token, allowing us to connect to the team as a bot user
incoming-webhook
: This provides an incoming webhook token
commands
: This provides a Slack token, which we can use to ensure that the incoming slash command requests are valid
Multiple...
Submitting your app to the app directory
Once you have tested your integration within your team's channel, and you are happy with your bot, it's time to submit it to the app directory. To do so, first ensure that your application conforms to Slack's checklist for deploying an app (https://api.slack.com/docs/slack-apps-checklist). In short, your app must:
Request only those scopes that are actually in use.
Display the Add to Slack button on a webpage. You are required to have your own website with instructions and help for new users.
Have an appropriate name (for example, no trademark or copyright infringement).
Have an app or bot icon that is clear and distinctive.
Have a high-quality icon that is at least 512 x 512 pixels in size.
Include short and long descriptions of your bot's actions.
Include an installation link (this can simply be a webpage displaying the Add to Slack button and a guide on how to use your bot).
Feature an customer support link and e-mail, in case users run into problems installing...
Monetizing your bot, of course, is entirely optional and how you monetize it is dependent on the function of your bot and whether there is a market. Bear in mind that if your goal is to sell your bots for a one-off price, the Slack app directory does not support monetary transfers.
All apps in the app directive are free to install, but how you convert your user base to paying customers is left up to you.
There are a variety of methods to do this and there is no single correct way or Slack-sanctioned method. A popular method employed by companies such as Zoho Expense (https://www.zoho.com/us/expense/slack-integration/) is a payment plan based on users. The service is free for small teams, but once you require more than three users to have access, you have to migrate to a paid tier.
The idea here is similar to APIs we have encountered, such as Wolfram Alpha. This means using a tiered approach where a free tier exists (tied either to amount of calls made or an expiration date...
In this chapter, you saw how to make your app accessible to other teams via the Slack App Directory. You saw how to request scopes from Slack to ensure that your apps have the correct permissions to perform actions. Finally, you learned how to correctly authenticate your apps with Slack and obtain the tokens required to make your bots, webhooks, and slash commands work.
By following the lessons in this book, you have obtained all the knowledge and tools required to create a world-class Slack bot. It is now up to you to create the next leap forward in bot technology and to push the boundaries of how we interact with bots to solve problems and achieve optimum efficiency.
To perhaps inspire you further, you should be aware that chat bots in general and Slack bots in particular are enjoying an unprecedented explosion in popularity and recognition.
At the beginning of his keynote speech at the 2016 Microsoft Build developers conference, Microsoft CEO Satya Nadella prophesized the future...