From 6702cf2523048d1c1c4238a16c7972bc8704ffdb Mon Sep 17 00:00:00 2001 From: Matthew R Date: Wed, 22 Jul 2020 22:04:25 -0400 Subject: [PATCH] add webhook sd notifications --- src/api/routes/Webhook.ts | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/api/routes/Webhook.ts diff --git a/src/api/routes/Webhook.ts b/src/api/routes/Webhook.ts new file mode 100644 index 0000000..5d6d897 --- /dev/null +++ b/src/api/routes/Webhook.ts @@ -0,0 +1,31 @@ +import { TextChannel } from 'eris'; +import { Server } from '..'; +import { Route, RichEmbed } from '../../class'; + +export default class Webhook extends Route { + constructor(server: Server) { + super(server, { path: '/wh', deprecated: false, maintenance: false }); + } + + public bind() { + this.router.get('/s1', async (req, res) => { + try { + if (req.headers.authorization !== this.server.security.keys.iv.toString()) return res.status(401).json({ code: this.constants.codes.UNAUTHORIZED, message: this.constants.codes.UNAUTHORIZED }); + const embed = new RichEmbed(); + embed.setTitle('Service Request'); + embed.setDescription(req.body.url); + embed.setColor('#FF00FF'); + embed.addField('Ticket Number', req.body.key, true); + embed.addField('Reporter', req.body.reporter, true); + embed.addField('Status', req.body.status, true); + embed.addField('Summary', req.body.summary); + embed.setFooter(this.server.client.user.username, this.server.client.user.avatarURL); + embed.setTimestamp(); + const chan = this.server.client.getChannel('580950455581147146'); + return chan.createMessage({ embed }); + } catch (err) { + return this.handleError(err, res); + } + }); + } +}