A Webhook, in simple terms, is a user-defined HTTP callback. It is a mechanism for the system to notify you about an event.
In our case, we need to send messages to a particular channel in slack. Slack calls in Incoming Webhook. It is a mechanism
to send messages to your Slack Channel from external sources. These external sources could be any application or service
that is capable of sending a JSON payload
over HTTP into a Slack Channel. Each Channel will be identified by a
unique Incoming Webhook URL to which you can post the message from outside. This configuration is done via the Integrations for your channel.
incoming webhook integration
below the heading Incoming Webhooks.curl -X POST --data-urlencode 'payload={"channel": "#general", "username": "webhookbot", "text": "This is posted to #general and comes from a bot named webhookbot.", "icon_emoji": ":ghost:"}' https://hooks.slack.com/services/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
.import
axios
from
'axios'
;
const
options
=
{
text
:"Message from slack bot!!"
,
}
;
axios
.
post
(
'<SLACK_WEBHOOK_URL>'
,
JSON
.
stringify
(
options
)
)
.
then
(
(
response
)
=>
{
console
.
log
(
'SUCCEEDED: Sent slack webhook: \n'
,
response
.
data
)
;
resolve
(
response
.
data
)
;
}
)
.
catch
(
(
error
)
=>
{
console
.
log
(
'FAILED: Send slack webhook'
,
error
)
;
reject
(
new
Error
(
'FAILED: Send slack webhook'
)
)
;
}
)
;
By following above steps, one can create a slack webHook to a particular channel and send notifications to it from any sources.
If you have any questions on how to get slack webhook url. We will give the professional answers to your questions.