Guest User

Untitled

a guest
Aug 19th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. 'use strict'
  2.  
  3. const express = require('express');
  4. const Linebot = require('./linebot.js');
  5.  
  6. const app = express();
  7.  
  8. const linebot = new Linebot();
  9. //const ai = new AI();
  10.  
  11. app.get('/', (req, res) => {
  12. res.json({
  13. api: 'lineBot'
  14. });
  15. });
  16.  
  17. app.post('/linebot/callback',
  18. linebot.getMiddleware(), (req, res) => {
  19. Promise.all(req.body.events.map(linebot.handleEvent.bind(linebot)))
  20. .then(result => {
  21. return res.json(result)
  22. })
  23. .catch(err => {
  24. console.error(err);
  25. res.status(500).end();
  26. });
  27. });
  28. const port = process.env.PORT || 8100;
  29. app.listen(port, () => {
  30. console.log(`listening on ${port}`);
  31. });
Add Comment
Please, Sign In to add comment