REST API Sample For IFTTT Maker Channel.
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
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')); | |
}); |
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
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); | |
} | |
}); | |
} | |
}; |
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
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(""); | |
} | |
}; |
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
{ | |
"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