Created
May 2, 2016 06:05
-
-
Save hisasann/177f41e9f8c45fbeedcc309120b9810a to your computer and use it in GitHub Desktop.
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'); | |
var router = express.Router(); | |
var request = require('request'); | |
const headers = { | |
'Content-Type' : 'application/json; charset=UTF-8', | |
'X-Line-ChannelID' : '<Channel ID>', | |
'X-Line-ChannelSecret' : '<Channel Secret>', | |
'X-Line-Trusted-User-With-ACL' : '<MID>' | |
}; | |
const options = { | |
url: 'https://trialbot-api.line.me/v1/events', | |
proxy: process.env.FIXIE_URL, | |
headers: headers, | |
json: true, | |
body: null | |
}; | |
router.post('/callback', function(req, res, next) { | |
var json = req.body; | |
var text = json['result'][0]['content']['text']; | |
var from = [json['result'][0]['content']['from']]; | |
options.body = { | |
'to': from, | |
'toChannel': 1383378250, // fixed | |
'eventType':'138311608800106203', // fixed | |
'content': { | |
// text | |
'contentType': 1, | |
'toType': 1, | |
'text': '\(^o^)/' | |
} | |
}; | |
request.post(options, function (error, response, body) { | |
if (!error && response.statusCode == 200) { | |
console.log(body); | |
} else { | |
console.log('error: '+ JSON.stringify(response)); | |
} | |
}); | |
}); | |
module.exports = router; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment