twilio-opencode

A lightweight express server to handle Twilio voice and messaging webhooks for prompting Opencode.
git clone https://unitehenry.com/git/twilio-opencode.git
Log | Files | Refs | README | LICENSE

commit 2eeece3b8e2bf4456eeab1ebdb4c6e4f5ebdf11d
parent 4ddf8b96418b4da32c9d682810988e015c4b7b79
Author: Henry Unite <henry@getpoint.io>
Date:   Thu, 26 Feb 2026 09:23:46 -0800

feat: phone number whitelist

Diffstat:
Mmessage.ts | 11++++++++++-
Mvoice.ts | 7+++++++
Awhitelist.ts | 7+++++++
3 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/message.ts b/message.ts @@ -1,4 +1,5 @@ import { type Request, type Response } from "express"; +import whitlist from './whitelist'; import prompt from "./prompt.ts"; import log from "./log.ts"; @@ -15,7 +16,15 @@ function buildResponse(message: string): string { export default async (req: Request, res: Response): Promise<void> => { const messageId: string = req.body.MessageSid; - log("INFO", `Message webhook received`, { messageId }); + const from: string = req.body.From; + + log("INFO", "Message webhook received", { messageId, from }); + + if (!whitelist(from)) { + log('WARN', 'Phone number not whitelisted', { messageId, from }); + + return; + } const messageResult: string = req.body.Body; diff --git a/voice.ts b/voice.ts @@ -1,5 +1,6 @@ import { type Request, type Response } from "express"; import prompt from "./prompt.ts"; +import whitelist from './whitelist.ts'; import log from "./log.ts"; function buildResponse(message: string): string { @@ -21,6 +22,12 @@ export default async (req: Request, res: Response): Promise<void> => { log("INFO", `Call webhook received`, { callId, from }); + if (!whitelist(from)) { + log('WARN', 'Phone number not whitelisted', { callId, from }); + + return; + } + const speechResult: string = req.body.SpeechResult; if (!speechResult) { diff --git a/whitelist.ts b/whitelist.ts @@ -0,0 +1,7 @@ +export default (number : string) : boolean => { + if (!process.env.FROM_WHITELIST) return; + + return process.env.FROM_WHITELIST.split(',') + .map(phone => phone.trim()) + .contains(number.trim()); +}