Skip to content

Instantly share code, notes, and snippets.

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 hisasann/cc59b36431b487494716497de4bf3a6d to your computer and use it in GitHub Desktop.
Save hisasann/cc59b36431b487494716497de4bf3a6d to your computer and use it in GitHub Desktop.
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':'140177271400161403', // fixed, for multiple messages
'content': {
"messageNotified": 0,
"messages": [
// text
{
'contentType': 1,
'toType': 1,
'text': '\(^o^)/'
},
// stamp
{
'contentType': 8,
'toType': 1,
'contentMetadata':{
'STKID':'100',
'STKPKGID':'1',
'STKVER':'100'
}
},
// image
{
'contentType': 2,
'toType': 1,
'originalContentUrl': 'http://hisasann.com/img/notechnonolife_character.jpeg',
'previewImageUrl': 'http://hisasann.com/img/notechnonolife_character.jpeg'
}
]
}
};
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