Skip to content

Latest commit

 

History

History
39 lines (27 loc) · 1.82 KB

REAME-slack-webhook-alert.md

File metadata and controls

39 lines (27 loc) · 1.82 KB

Setting Up and Using Slack Webhooks

This guide will walk you through the process of creating a Slack webhook and using it to send messages to a specific channel.

1. Creating a Slack App and Webhook

  1. Go to the Slack API website.
  2. Click on "Create New App" and choose "From scratch".
  3. Give your app a name and select the workspace where you want to use it.
  4. Once your app is created, go to "Incoming Webhooks" in the left sidebar.
  5. Toggle "Activate Incoming Webhooks" to On.
  6. Scroll down and click "Add New Webhook to Workspace".
  7. Choose the channel where you want the messages to appear.
  8. Click "Allow" to authorize the webhook.
  9. You'll see a new webhook URL. Copy this URL, as you'll need it later.

2. Setting Up Environment Variables

To keep your webhook URL secure, we'll use environment variables:

  1. Create a .env file in your project root if it doesn't exist already.

  2. Add the following line to your .env file:

    SLACK_WEBHOOK_URL=https://hooks.slack.com/services/YOUR/WEBHOOK/URL
  3. Replace https://hooks.slack.com/services/YOUR/WEBHOOK/URL with the actual webhook URL you copied earlier.

  4. Make sure your .gitignore file includes .env to avoid accidentally committing sensitive information.

3. Using the Webhook in Your Code

Refer to test/webhook/slack.go for an example of how to use the Slack webhook in your code.

Troubleshooting

If you're not seeing messages in Slack, double-check that your webhook URL is correct and that you've selected the right channel when setting up the webhook. Ensure that your .env file is in the correct location and that the environment variable is being loaded properly. Check the Slack App settings to make sure the app has the necessary permissions for the channel you're posting to.