const Router = require('koa-router') const r = new Router() // const koaBody = require('koa-body') const { verifyLine, getRaw } = require('../../libs/middleware') const { textMessage } = require('../../libs/line-message') r.post('/', getRaw, verifyLine, async (c, n) => { console.log(JSON.stringify(c.request.body, null, 2)) if (!('events' in c.request.body)) return c.throw(400, 'data struct error') let evt = c.request.body.events || [] evt.forEach(t => { let type = t.type switch (type) { case 'message': textMessage(t).catch(err => { console.log(err) }) break } }) c.body = 'success' c.status = 200 }) module.exports = r