Prerequisites
- A Slack workspace you can install an app into
- A published with a Slack channel
The token belongs to the recipient
This is the part that surprises people, and it is worth understanding before you start. Most providers hold one credential on the integration. Slack passes its bot token with each recipient, onto.slack.access_token. Install the Slack integration once, then store a token per user or per customer.
That is what makes Slack workable for B2B. One Courier workspace posts into many customers’ Slack workspaces, because each recipient carries the token for the workspace they belong to. A single shared credential could not do that.
Send it
1
Install the integration and create a Slack app
Add Slack from in Courier.Then create the app on Slack’s side. At api.slack.com/apps, choose Create an App, then From scratch, and pick your workspace.Under OAuth & Permissions, add these Bot Token Scopes:
Install the app to the workspace, then copy the Bot User OAuth Token. It starts with
xoxb-. has the screenshots for each step.2
Put the token and a target on the profile
Store the token alongside how you want to reach the person. Courier accepts three targets, and uses the first one it finds in this order: Which target to pick is a real decision rather than a preference:
channel, then user_id, then email. covers profile storage for every channel.Profile
Start with
email and move to user_id when a mismatch bites. The users:read.email scope is what makes email targeting work at all.3
Send the message
Address the user and route to the Slack provider. Courier reads Slack content is built in the template’s Slack block rather than in the send, which is why this call carries a template id and no inline content.
slack off the profile.Verify
1
Check Slack
The message arrives as a direct message from your app, not from a person.
2
Read the status
Open . The provider response carries Slack’s own error when something fails, which is more specific than the Courier status alone.
not_in_channel means the app is not in the channel you targeted, so invite it. users_not_found means the email on the profile does not match any member of that workspace, which is the usual cost of targeting by email.
What changes in production
A token per workspace, not per app. Each customer installing your Slack app produces its own token. Store it on the profiles belonging to that customer, or on a if you scope by customer already. Tokens can be revoked. An admin removing the app invalidates its token, and sends then fail per recipient rather than globally. Watch forinvalid_auth in the logs and prompt a reinstall.
Slack rate limits per app. Its limits apply to your app rather than to Courier, so a high-volume broadcast into one workspace is the case to watch.