- Create a minimal Slack application within the Slack API dashboard
- Configure the Slack application to send notifications to our application whenever a user joins or leaves the channel - allowing our code to update the Box Box group.
- Configure a
/boxaddslash command that will allow users to share a Box file or folder with all the users in the channel.
Create a minimal Slack app
Go to the Slack apps page and click Create an App. Add an App Name, select your Development Slack Workspace from the dropdown list where the bot will be deployed to, then click Create App.
Configure the Slack app’s event listener
Setting up an event listener for our Slack app will allow us to monitor for events within the channel. For this bot, we want to monitor three Slack events in order to perform actions within Box.bot_added: When the bot is first added to a channel, it will get a list of all users in the channel, then create a Box group for those users. We can then use this group later on to add that group to any content that is shared with the slash command.member_joined_channel: When a new user joins a Slack channel they will be added to the Box group.member_left_channel: When a user leaves a Slack channel, or the user is removed, they will be removed from the Box group.
- Toggle Enable Events to On.
- Under Request URL add in the public URL that you deployed the above code to, and be aware that we are listening at
{YOUR_APP_DOMAIN}/event(such ashttps://myapp.com/event). Once you add the URL and click outside the field, Slack will immediately send the challenge to the URL that you were hosting the code at above. If the code responds correctly, you will see a green verified note beside the Request URL header.

- Expand the Subscribe to bot events section and click on the Add Bot User Event button.
- Add
member_joined_channelandmember_left_channelto the events the bot is subscribed to. These will send events when anyone new is added to the channel. - Click the Save Changes button at the bottom of the page.
Configure the Slack app slash command
To provide every user in a Slack channel access to a file or folder in Box, we can use a Slack “slash commands”. A slash command will allow any person in the channel to share content they own in Box with the rest of the channel. Through this command, a channel member will be able to type/boxadd [file / folder] [id], for example boxadd file 1459732312, into the
channel to share the file / folder with every user in the channel. To do this,
the file is automatically collaborated with the Box group of users that are in
that channel.
From the Basic Information tab of your application, under Add features and
functionality, click on the button titled Slash Commands.
In the page that comes up, click Create New Command and input the following:
- Command: This is the command that a channel user will use to share a Box file / folder ID with the channel. Use
/boxaddfor this quick start. - Request URL: The URL that is listening for and responding to slash commands in our Slack bot. In this quick start we use the same event URL that was used for the app event listener section above.
- Short Description: A description of what the Slash command will do.
- Usage Hint: Additional parameters that may be passed to the command. In our case, that’s the Box file / folder ID and type of content.

Add Additional Scopes
When slash commands or notifications are sent to our application from Slack they will contain a Slack user ID, which relates to the person that took or was affected by the action. To translate that ID to a Box user we need to get the Slack user’s email, which we can then use to associate that Slack user to a corresponding Box user. This action requires two extra scopes in the Slack application configuration. From your Slack application configuration, click on OAuth & Permissions in the left menu, then do the following.- Scroll down to the Scopes section.
- Click on the Add an OAuth Scope button under Bot Token Scopes..
- Search for and add
users:readandusers:read.email.
Deploy Bot to Slack Workspace
The last step is to install the application into your Slack workspace. From the Basic Information page of the app, expand the Install your app to your workspace section.

Summary
- You’ve created your Slack application.
- You’ve configured user event notifications, slash commands, and additional scoping.
- You’ve deployed your Slack bot to your workspace.
