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 c35d66974800b4e00b9e14d6eac42f49e8d49259
parent 99857966a872555c80406b405d9033ab2426ffa0
Author: Henry Unite <henry@getpoint.io>
Date:   Wed,  4 Mar 2026 11:04:34 -0800

feat: configure twilio endpoint

Diffstat:
Mapp.ts | 3+++
Aconfigure.ts | 39+++++++++++++++++++++++++++++++++++++++
2 files changed, 42 insertions(+), 0 deletions(-)

diff --git a/app.ts b/app.ts @@ -3,6 +3,7 @@ import twilio from "twilio"; import log from "./log.ts"; import message from "./message.ts"; import voice from "./voice.ts"; +import configure from "./configure.ts"; import health from "./health.ts"; import listen from "./listen.ts"; @@ -18,6 +19,8 @@ app.post("/voice", twilio.webhook({ validate }), voice); app.post("/message", twilio.webhook({ validate }), message); +app.post("/configure", configure); + app.get("/health", health); const port: number = parseInt(process.env.PORT || "3000", 10); diff --git a/configure.ts b/configure.ts @@ -0,0 +1,39 @@ +import { type Request, type Response } from "express"; +import twilio from "twilio"; +import log from "./log.ts"; + +interface ConfigureRequest { + twilioAccountSid: string; + twilioAuthToken: string; + twilioPhoneNumberSid: string; +} + +export default async (req: Request, res: Response): Promise<void> => { + const origin = `${req.protocol}://${req.get("host")}`; + + log("INFO", "Configure twilio webhook", { origin }); + + const requestBody: ConfigureRequest = { + twilioAccountSid: req.body.twilioAccountSid, + twilioAuthToken: req.body.twilioAuthToken, + twilioPhoneNumberSid: req.body.twilioPhoneNumberSid + }; + + log("INFO", "Init twilio client", { + accountSid: requestBody.twilioAccountSid, + phoneSid: requestBody.twilioPhoneNumberSid, + origin, + }); + + const client = twilio(requestBody.twilioAccountSid, requestBody.twilioAuthToken); + + await client.incomingPhoneNumbers(requestBody.twilioPhoneNumberSid) + .update({ + smsUrl: origin + '/message', + smsMethod: 'POST', + voiceUrl: origin + '/voice', + voiceMethod: 'POST' + }); + + res.sendStatus(200); +}