Before sending alert messages through a Slack channel, you must obtain the webhook URL of your custom chatbot in Slack. This topic describes how to obtain the webhook URL in Slack and associate it with a Slack channel.
Procedure
Step 1: Create a Slack channel
Go to the official Slack website or install the desktop version of Slack.
Click Channel > Create Channel on the left to create a Slack channel for receiving alert notifications (similar to a group chat).
Step 2: Add the Incoming Webhook app
In Slack, click Applications, search for Incoming Webhooks, and go to the app.
On the channel settings page, select the Slack channel created in Step 1 and click Add Incoming WebHook Integration to associate it.
Step 3: Obtain the WebHook URL
After the association is successful, Incoming Webhook automatically generates a WebHook URL, for example:
https://hooks.slack.com/services/xxx/xxx. As described in the "Sending Messages" section, you can choose to use any one of the alert message formats.Run the following script to test whether alert messages can be sent to the Slack channel.
# https://hooks.slack.com/services/XXXX is the WebHook URL generated in Step 3. curl -X POST -H 'Content-type: application/json' \ --data '{"text":"Hello, World!"}' \ https://hooks.slack.com/services/XXXXIf the test result shows
okand the message Hello, World! appears in the channel, it means the WebHook connection is normal and the Slack channel is properly associated with the WebHook.
