Skip to content

Instantly share code, notes, and snippets.

@shigwata
Last active February 14, 2018 07:52
Show Gist options
  • Select an option

  • Save shigwata/fb3322db95185fca29501349c77bcf4a to your computer and use it in GitHub Desktop.

Select an option

Save shigwata/fb3322db95185fca29501349c77bcf4a 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