You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tellme-bot/packages/server/http/api/webhook.js

41 lines
994 B

10 months ago
import tokenHandler from './../../handlers/token.js'
import parserHandler from './../../handlers/parser.js'
2 years ago
/**
* handle webhook
2 years ago
*
2 years ago
* @author Björn Hase
* @license hhttps://www.gnu.org/licenses/gpl-3.0.en.html GPL-3
2 years ago
* @link https://gitea.node001.net/HerrHase/tellme-bot.git
2 years ago
*
*/
10 months ago
export default async function(fastify, options) {
fastify.addHook('preHandler', tokenHandler)
fastify.addHook('preHandler', parserHandler)
10 months ago
2 years ago
/**
* getting post getting allowed parser class and send over xmpp
2 years ago
*
* @param {object} request
* @param {object} response
*
*/
10 months ago
fastify.post('/v1/:parser/:token', async function (request, response) {
2 years ago
10 months ago
// getting parser from preHandler: parserHandler
const result = response.locals.parser.run()
2 years ago
// send event for send xmpp
fastify.eventEmitter.emit('send-message', {
2 years ago
'message': result
})
10 months ago
response
2 years ago
.code(200)
.send()
})
10 months ago
}