Last active
May 24, 2017 07:15
-
-
Save wokamoto/8b985bb5b157168daa62ee82a8fb1e87 to your computer and use it in GitHub Desktop.
[AWS][Lambda] Lambda で Typetalk に投稿するサンプル ref: http://qiita.com/wokamoto/items/44c0439c0e56fd6e0035
This file contains 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
'use strict'; | |
module.exports.hello = (event, context, callback) => { | |
const https = require('https'); | |
const querystring = require('querystring'); | |
const typetalk_talken = process.env.TYPETALK_TOKEN; | |
const typetalk_room = process.env.TYPETALK_ROOM; | |
const options = { | |
hostname: 'typetalk.in', | |
path: '/api/v1/topics/'+typetalk_room+'?typetalkToken='+typetalk_talken, | |
method: 'POST', | |
headers: { | |
'Content-Type': 'application/x-www-form-urlencoded' | |
} | |
}; | |
let req = https.request(options, (res) => { | |
let response = { | |
statusCode: res.statusCode, | |
body: JSON.stringify({ | |
statusCode: res.statusCode | |
}) | |
}; | |
console.log('STATUS: ' + res.statusCode); | |
callback(null,response); | |
}); | |
req.write(querystring.stringify({'message': 'Hello Typetalk!'})); | |
req.on('error', (err) => { | |
callback(err); | |
}); | |
req.end(); | |
}; |
This file contains 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
service: post-typetalk | |
provider: | |
name: aws | |
runtime: nodejs6.10 | |
stage: dev | |
region: ap-norhteast-1 | |
environment: | |
TYPETALK_TOKEN: '<string>__TYPETALK_TALKEN_HERE__' | |
TYPETALK_ROOM: '<number>__TYPETALK_ROOM_NO_HERE__' | |
functions: | |
hello: | |
handler: handler.hello |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment