-
Notifications
You must be signed in to change notification settings - Fork 1
/
router.ts
38 lines (30 loc) · 1.14 KB
/
router.ts
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
36
37
38
import express, { Router, Request, Response } from 'express';
import twilio from 'twilio';
import { receiver as slackReceiver } from './utils/slack';
import { handleTwilioMessage } from './helpers/mfa';
const TWILIO_NO_REPLY = '<Response></Response>';
const router: Router = express.Router();
// Slack Bolt.js (mount before body-parser)
router.use('/slack/events', slackReceiver.router);
// Express body-parser. These middleware MUST be before Slack Bolt. (Bolt only takes raw requests)
router.use(express.json());
router.use(express.urlencoded({ extended: true }));
// Ping Pong (test endpoint)
router.get('/ping', (req: Request, res: Response) => {
res.send('pong! 🏓');
});
// Receive incoming SMS from Twilio
// https://www.twilio.com/docs/messaging/guides/webhook-request
router.post(
'/twilio/messaging',
// twilio.webhook(process.env.TWILIO_AUTH_TOKEN, {
// // This middleware verifies that the request is from Twilio
// url: 'https://mfa.hackclub.com',
// }),
async (req: Request, res: Response) => {
// Don't reply to incoming sms message
res.send(TWILIO_NO_REPLY);
await handleTwilioMessage(req.body);
}
);
export default router;