Last active
February 14, 2018 07:52
-
-
Save shigwata/fb3322db95185fca29501349c77bcf4a to your computer and use it in GitHub Desktop.
Cloud Functions pubsub to slack
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 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); | |
| }); | |
| }; |
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
| { | |
| "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