Skip to content

Instantly share code, notes, and snippets.

@bhubbard
Forked from shigwata/index.js
Created February 14, 2018 07:52
Show Gist options
  • Save bhubbard/bf956bdae2c83501f8a314bd16b4beba to your computer and use it in GitHub Desktop.
Save bhubbard/bf956bdae2c83501f8a314bd16b4beba to your computer and use it in GitHub Desktop.
Cloud Functions pubsub to slack
const IncomingWebhook = require('@slack/client').IncomingWebhook;
const url = 'Webhook URL'
const defaults = {
username: 'webhookbot',
iconEmoji: ':ghost:',
channel: '#general'
}
const webhook = new IncomingWebhook(url, defaults);
exports.subscribe = function subscribe(event, callback) {
const pubsubMessage = event.data;
const data = JSON.parse(new Buffer(pubsubMessage.data, 'base64').toString());
const message = {
text: data.logName
}
console.log(message);
webhook.send(message, (err, res) => {
console.log(res);
callback(err);
});
};
{
"name": "pubsub2slack",
"version": "0.0.1",
"dependencies": {
"@slack/client": "3.14.2"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment