- Listen for new events and slash commands from Slack.
- Process those events and commands to route to the appropriate function.
- Process all Slack users in a channel to be added to a Box group when the bot is first added to a channel.
- Fetch profile information for a Slack user to get their email.
Listen for Slack events
When the Slack application was configured, it was instructed to send events to our application code for three events.- When a user joins a channel.
- When a user leaves a channel.
- When a user enters a
/boxaddSlash command.
Process Slack events
Next, we will want to determine what event was received and pass this on to the right part of our application.Process Slack user
Next, we need to define how user events should be processed. There are three events that we need to account for:- The bot was added to the channel.
- A regular user joined the channel.
- A regular user left the channel.
- If the user is a bot, it needs to initialize the Box group and add all current users of the channel as Box users in the group. This is to account for the bot being added to existing channels, and this is ignored if the bot is being re-added to a channel that they were already present in previously.
- If the user joined the channel it needs to add them to the group.
- If the user left the channel it needs to remove them from the group.
Process Slack channel users
When a bot is first added to a channel, it needs to list all users currently in the channel and create a Box group with those people in order to create a baseline for the channel. This code runs a number of actions in sequence.- First, it calls the Slack APIs to fetch all members of the channel. The
limitcan be adjusted to collect more users in the channel.- For every user that is found, it calls
getSlackUserto get their profile, allow it to map their email address to a Box user’s email address. - Each user is then sent to
addGroupUserto add them into the group.
Fetch Slack user profile
The last Slack related function is a utility mechanism used by the other functions. It calls the Slack API to fetch the user profile given the user ID provided by either Slack event / command or when fetching a list of channel users. Since we’re matching Slack users to Box users via their email address, that is the field that we care about from the user profile lookup.Email addresses in Box are unique and cannot be used for multiple accounts,
meaning that they can be used effectively for user account lookup.
Summary
- You’ve verified incoming events and forwarded them to be processed.
- You’ve processed events and routed to the appropriate function.
- You’ve implemented functions for processing all users in a channel and for fetching the Slack profile of a single user.
