mtfosbot/route/google/index.js

33 lines
718 B
JavaScript
Raw Normal View History

2018-07-03 02:27:24 +00:00
const Router = require('koa-router')
2018-07-03 14:14:14 +00:00
const xml2js = require('xml2js')
2018-07-03 02:27:24 +00:00
const r = new Router()
// const koaBody = require('koa-body')
const {
getRaw
} = require('../../libs/middleware')
const {
textMessage
} = require('../../libs/line-message')
r.get('/youtube/webhook', async (c, n) => {
2018-07-03 14:14:14 +00:00
let mode = c.query['hub.mode'] || ''
let verifyToken = c.query['hub.verify_token'] || ''
let challenge = c.query['hub.challenge']
if (mode) {
if (mode === 'subscribe') {
c.status = 200
c.body = challenge
} else {
c.status = 403
c.body = ''
}
}
2018-07-03 02:27:24 +00:00
})
r.post('/youtube/webhook', getRaw, async (c, n) => {
console.log(JSON.stringify(c.request.body, null, 2))
})
module.exports = r