Skip to content

Instantly share code, notes, and snippets.

@victortsaitw12
Last active August 19, 2018 05:57
Show Gist options
  • Select an option

  • Save victortsaitw12/be8150d0d57f2c236424f58f421a5647 to your computer and use it in GitHub Desktop.

Select an option

Save victortsaitw12/be8150d0d57f2c236424f58f421a5647 to your computer and use it in GitHub Desktop.
'use strict'
const express = require('express');
const Linebot = require('./linebot.js');
const app = express();
const linebot = new Linebot();
//const ai = new AI();
app.get('/', (req, res) => {
res.json({
api: 'lineBot'
});
});
// 當在 Line 打字後, Line 把 Message 傳到這裡。
// 呼叫 linebot 的 handleEvent function 處理。
app.post('/linebot/callback',
linebot.getMiddleware(), (req, res) => {
Promise.all(req.body.events.map(linebot.handleEvent.bind(linebot)))
.then(result => {
return res.json(result)
})
.catch(err => {
console.error(err);
res.status(500).end();
});
});
const port = process.env.PORT || 8100;
app.listen(port, () => {
console.log(`listening on ${port}`);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment