-
Notifications
You must be signed in to change notification settings - Fork 163
Expand file tree
/
Copy pathmeta.router.ts
More file actions
35 lines (31 loc) · 1.41 KB
/
meta.router.ts
File metadata and controls
35 lines (31 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { RouterBroker } from '@api/abstract/abstract.router';
import { metaController } from '@api/server.module';
import { ConfigService, WaBusiness } from '@config/env.config';
import { Router } from 'express';
export class MetaRouter extends RouterBroker {
constructor(readonly configService: ConfigService) {
super();
this.router
.get(this.routerPath('webhook/meta', false), async (req, res) => {
if (req.query['hub.verify_token'] === configService.get<WaBusiness>('WA_BUSINESS').TOKEN_WEBHOOK)
res.send(req.query['hub.challenge']);
else res.send('Error, wrong validation token');
})
.post(this.routerPath('webhook/meta', false), async (req, res) => {
const { body } = req;
const response = await metaController.receiveWebhook(body);
return res.status(200).json(response);
})
.get(this.routerPath('webhook/whatsapp', false), async (req, res) => {
if (req.query['hub.verify_token'] === configService.get<WaBusiness>('WA_BUSINESS').TOKEN_WEBHOOK)
res.send(req.query['hub.challenge']);
else res.send('Error, wrong validation token');
})
.post(this.routerPath('webhook/whatsapp', false), async (req, res) => {
const { body } = req;
const response = await metaController.receiveWebhook(body);
return res.status(200).json(response);
});
}
public readonly router: Router = Router();
}