Skip to content

Instantly share code, notes, and snippets.

@pirosuke pirosuke/app.js
Last active Feb 14, 2016

Embed
What would you like to do?
REST API Sample For IFTTT Maker Channel.
var express = require('express')
, bodyParser = require('body-parser')
, ifttt = require('./ifttt')
, http = require('http')
, path = require('path');
var app = express();
// all environments
app.set('port', process.env.PORT || 3000);
app.use(bodyParser.urlencoded({extended: false}));
app.use(bodyParser.json());
app.post('/ifttt/notify_workend', ifttt.notifyWorkend);
http.createServer(app).listen(app.get('port'), function(){
console.log('Express server listening on port ' + app.get('port'));
});
var request = require("request");
module.exports = {
/**
* Post message to Chatwork room.
*/
postChatwork: function (roomId, apiKey, message, callback) {
var endpointBase = "https://api.chatwork.com/v1/";
var options = {
url: endpointBase + "rooms/" + roomId + "/messages",
headers: {
"X-ChatWorkToken": apiKey
},
form: {
body: message
},
json: true
};
request.post(options, function (error, response, body) {
if (!error && response.statusCode == 200) {
callback(false, body);
} else {
callback(true, "error:" + response.statusCode);
}
});
}
};
var config = require('config');
var chatwork = require('./chatwork');
var chatworkApiKey = config.get("chatwork.api_key");
var chatworkRoomId = config.get("chatwork.room_id");
module.exports = {
notifyWorkend: function(req, res){
var time = req.body.time;
var message = "Work End Notification: " + req.body.message + "\n" + time;
chatwork.postChatwork(chatworkRoomId, chatworkApiKey, message, function (hasError, result) {
});
res.send("");
}
};
{
"name": "ifttt-maker-receiver",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node app.js"
},
"dependencies": {},
"devDependencies": {
"body-parser": "^1.15.0",
"config": "^1.19.0",
"express": "^4.13.4",
"request": "^2.69.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.