Skip to content

Commit aaf9c68

Browse files
committed
Add Twilio webhook validation
1 parent aecde8f commit aaf9c68

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
function shouldValidate () {
2+
return process.env.NODE_ENV !== 'test'
3+
}
4+
5+
export const webhookConfig = {
6+
protocol: 'https',
7+
host: process.env.DOMAIN,
8+
validate: shouldValidate()
9+
}

src/routes/index.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
import { Router } from "express";
22
import * as controllers from "../controllers";
3-
import basicAuth from 'express-basic-auth'
43

4+
import twilio from 'twilio'
5+
import { webhookConfig } from '../config/webhookValidationConfig'
6+
7+
import basicAuth from 'express-basic-auth'
58
const { AUTH_USERNAME, AUTH_PASSWORD } = process.env
69

710
const router = Router();
811

9-
router.post("/conversations-post-event", controllers.conversationsPostEvent.post);
12+
router.post("/conversations-post-event", twilio.webhook(webhookConfig), controllers.conversationsPostEvent.post);
1013

11-
router.post("/inbound-call", controllers.inboundCall.post);
12-
router.post("/join-conference", controllers.joinConference.get)
14+
router.post("/inbound-call", twilio.webhook(webhookConfig), controllers.inboundCall.post);
15+
router.post("/join-conference", twilio.webhook(webhookConfig), controllers.joinConference.get)
1316

1417
router.post("/sessions", basicAuth({
1518
users: { [AUTH_USERNAME]:AUTH_PASSWORD}

0 commit comments

Comments
 (0)