Last active
January 5, 2018 06:50
-
-
Save nibral/7990fa5f129afb251f4f10610fbbed58 to your computer and use it in GitHub Desktop.
環境変数SLACK_WEBHOOK_URLを設定して使うこと
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 https = require('https'); | |
| const url = require('url'); | |
| exports.handler = function(event, context) { | |
| // prepare https POST request | |
| const reqOptions = url.parse(process.env.SLACK_WEBHOOK_URL); | |
| reqOptions.method = 'POST'; | |
| reqOptions.headers = { | |
| 'Content-Type': 'application/json' | |
| }; | |
| const request = https.request(reqOptions, (res) => { | |
| if (res.statusCode === 200) { | |
| context.succeed('request success'); | |
| } else { | |
| context.fail('status code: ' + res.statusCode); | |
| } | |
| }); | |
| request.on('error', (error) => { | |
| console.log('request fail: ' + error.message); | |
| context.fail(error.message); | |
| }); | |
| // send message to slack | |
| request.write(JSON.stringify({ | |
| text: '<write message here>', | |
| icon_emoji: ':name_badge:' | |
| })); | |
| request.end(); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment