Skip to content

Instantly share code, notes, and snippets.

@wokamoto
Last active May 24, 2017 07:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wokamoto/8b985bb5b157168daa62ee82a8fb1e87 to your computer and use it in GitHub Desktop.
Save wokamoto/8b985bb5b157168daa62ee82a8fb1e87 to your computer and use it in GitHub Desktop.
[AWS][Lambda] Lambda で Typetalk に投稿するサンプル ref: http://qiita.com/wokamoto/items/44c0439c0e56fd6e0035
'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();
};
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