Created
March 8, 2019 22:22
-
-
Save chandler767/1ff38024475286b626b145e97a57adfe to your computer and use it in GitHub Desktop.
Slack Incoming Webhooks provide an easy way to post messages to Slack from a PubNub Function.
This file contains 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
// FOR A PUBNUB SERVERLESS ENV. | |
// Learn More: https://api.slack.com/incoming-webhooks | |
export default (request, response) => { | |
const xhr = require('xhr'); | |
// Message | |
let message = `Hello World!`; | |
// Slack Webhook URL | |
const url = "SLACK-WEBHOOK-URL-HERE"; | |
// Basic Slack Post | |
const http_options = { | |
"headers": { | |
"Content-Type": "application/json" | |
}, | |
"method": "POST", | |
"body": JSON.stringify({ | |
"text": message, | |
}) | |
}; | |
return xhr.fetch(url, http_options).then((x) => { | |
//console.log(body); | |
return response.send(); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment