Last active
July 18, 2022 15:07
-
-
Save stekhn/6ebbf059bbfbf6725402d9c163695b82 to your computer and use it in GitHub Desktop.
Use webhooks for posting to Slack. Works great with Google Cloud Functions and Google Cloud Scheduler. The incoming webhook for your Slack team needs to be created beforehand.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const https = require('https'); | |
exports.postToSlack = () => { | |
// Read more about Slack webhooks here: https://api.slack.com/messaging/webhooks | |
const webhookPath = '/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX' | |
const payload = { | |
'channel': '#mychannel', | |
'username': 'slackbot', | |
'icon_emoji': ':bot:', | |
'text': 'Bow to your robot overlord' | |
} | |
const options = { | |
hostname: 'hooks.slack.com', | |
path: webhookPath, | |
port: 443, | |
method: 'POST', | |
headers: { | |
'Accept': '*/*', | |
'Content-Type': 'application/json' | |
} | |
} | |
const req = https.request(options); | |
req.write(JSON.stringify(payload)); | |
req.end(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment