Skip to content

Instantly share code, notes, and snippets.

@chandler767
Created March 8, 2019 22:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chandler767/1ff38024475286b626b145e97a57adfe to your computer and use it in GitHub Desktop.
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.
// 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