Restricting access

Occasionally, you might wish to restrict bot commands to administrators of your Slack team. A good example is a bot that controls a project's deploy process. This can be immensely powerful but perhaps not something that you want every user to have access to. Only administrators (also known as admins) should have the authority to access such functions. Admins are special users who have administrative powers over the Slack team. Luckily, restricting such access is easy with the is_admin property attached to a user object.

In the following example, we'll restrict the uptime command demonstrated in the previous topic to admin users, notifying the restricted user that they can't use that command:

slack.on(RTM_EVENTS.MESSAGE, (message) ...

Get Building Slack Bots now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.