Most Popular
Courier is a notification service that centralizes all of your templates and messaging channels in one place which increases visibility and reduces engineering time.
Sign-up
As a follow up to the Courier Live where Troy and I built the Pigeon Weather App, I went back and added support for sending the notification as a direct message in Slack. Adding this additional channel only required adding the Slack provider, designing the message, and updating our Glitch App to accept Slack profile information.
Check out the video below to watch me:
Be sure to Like the video and Subscribe to our YouTube channel.
Courier makes it easy to send notifications to a Slack channel or as a direct message to a Slack user. You can use your existing Slack App or create a new one, as long as it has the proper permissions granted via OAuth scopes. You can then send a notification by providing a slack object to the profile that includes the Slack App Bot User OAuth Access Token (bot token) and either the channel id, user id, or user email address.
To send to a Slack public or private channel, your Slack app must be granted the chat:write scope. Your Slack app must also be a member of the channel you're sending to. The recipient profile requires the bot token and channel id. This can be supplied to the send in the profile object, but I like to use the Profiles API to create a channel recipient profile.
1import { CourierClient } from "@trycourier/courier";23const courier = CourierClient({ authorizationToken: "<AUTH_TOKEN>" });45const { status: mergeStatus } = await courier.mergeProfile({6recipientId: "CHANNEL_GENERAL",7profile: {8slack: {9access_token: "xoxb-xxxxx",10channel: "CL2MR6HEX",11},12},13});14console.log(mergeStatus);
You can learn more about sending to public and private channels in our Slack documentation.
To send a direct message, in addition to the chat:write scope, your app will also need to be granted the im:write scope. For sending a direct message, you have a few options when setting up the recipient profile. You could use a Slack Button, the user's Slack user_id, or the email associated with the user's account like we did in our Pigeon Weather example. To simplify setting up a recipient profile for a Slack direct message, we added the shortcut to allow you to use the email address. This method does require that you add the users:read and users:read.email scopes because Courier will do the user_id lookup for you using the Slack API. Now you can either supply the profile information to the send or live above, use the Profiles API to add the Slack profile to your recipient's profile.
1import { CourierClient } from "@trycourier/courier";23const courier = CourierClient({ authorizationToken: "<AUTH_TOKEN>" });45const { status: mergeStatus } = await courier.mergeProfile({6recipientId: "STANPINES97009",7profile: {8slack: {9access_token: "xoxb-xxxxx",10email: "stan.pines@themysteryshack.com",11},12},13});14console.log(mergeStatus);
You can learn more about the different options for sending direct messages in our Slack documentation.
Feel free to remix our Pigeon Weather Glitch app and connect your Slack app to it and start sending Slack messages. Then, check out our Jsonnet Courier Live to learn how to create messages using dynamic Block Kit elements.
Is there something you’d like to see us do using Courier? Let us know and it might be the subject of our next Courier Live. We stream a new Courier Live every Wednesday at noon Pacific. Follow us on Twitch to be notified when we go live.
-Aydrian
Courier is a notification service that centralizes all of your templates and messaging channels in one place which increases visibility and reduces engineering time.
Sign-up
Tools and Techniques to Establish Your Data Team Early
How tools like Segment, Metabase, Snowflake, Census, and others, can help establish a data team from the very early stages in a startup.
Raymond See
February 16, 2023
Develop a Motivational QOTD with Courier and GPT2
Courier and OpenGPT2 in action: build a service that sends friends and family an AI generated motivational quote of the day.
Prakhar Srivastav
February 09, 2023
Free Tools
Comparison Guides
Send up to 10,000 notifications every month, for free.
Get started for free
Send up to 10,000 notifications every month, for free.
Get started for free
© 2024 Courier. All rights reserved.