Prerequisites
You need an account before starting, create one here.
We can use the offical slack npm package to send notifications to a slack channel.
Prerequisites
Since we're just using the offical slack npm package, there is not one specific way to set up slack notifications. For this example, we're going to create a slack app and use a bot token to send messages.
1. Create a slack app
Go to the slack api page and click on Create New App.
For our example, we only need the chat:write
permission. You should add more permissions depending on your use case.
Use the following manifest to quickly create a slack app with the necessary permissions:
2. Install the app
In your slack app settings, click on Install app and follow the instructions.
3. Save the bot token
Copy the bot token and add it to your PandaCI project variables. For this example, we're going to name it SLACK_BOT_TOKEN
.
4. Get the channel id
You can skip this if you only want to send messages directly to users.
You can find the channel id in the channel details modal. For this example, we're going to store it in the SLACK_CHANNEL_ID
variable. But since this isn't a secret, you can also hardcode it in your workflow.
Learn more about secrets.
Make sure you add the slack app to the channel you want to send messages to.
Simple example
Sending markdown messages
You can send markdown messages to slack by setting the mrkdwn
property to true
.
Sending messages with blocks
You can send messages with blocks to slack by setting the blocks
property.