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 6963d4186efa82265895bec827bf63cad6acf3c4
parent c361aa1c8cfadf8d1450f52d63ce75106832b79d
Author: Henry Unite <unitehenry@gmail.com>
Date:   Sat, 28 Feb 2026 07:27:55 +0000

feat: probe opencode

Diffstat:
Mapp.ts | 5++---
Alisten.ts | 31+++++++++++++++++++++++++++++++
2 files changed, 33 insertions(+), 3 deletions(-)

diff --git a/app.ts b/app.ts @@ -4,6 +4,7 @@ import log from "./log.ts"; import message from "./message.ts"; import voice from "./voice.ts"; import health from "./health.ts"; +import listen from './listen.ts'; const app = express(); @@ -21,9 +22,7 @@ app.get("/health", health); const port: number = parseInt(process.env.PORT || "3000", 10); -const server = app.listen(port, (): void => - log("INFO", "Server started", { port }), -); +const server = app.listen(port, listen); process.on("SIGINT", () => { log("INFO", "Received SIGINT, shutting down gracefully"); diff --git a/listen.ts b/listen.ts @@ -0,0 +1,31 @@ +import log from "./log.ts"; + +export default async () : Promise<void> => { + const opencodeBaseUrl = process.env.OPENCODE_BASE_URL; + + if (!opencodeBaseUrl) { + log("ERROR", "No opencode base url"); + + process.exit(1); + } + + log("INFO", "Probing opencode", { opencodeBaseUrl }); + + try { + const response = await fetch(`${opencodeBaseUrl}/global/health`); + + const body = await response.json(); + + if (!body.healthy) { + log("ERROR", "Opencode not healthy"); + + process.exit(1); + } + } catch(error) { + log("ERROR", "Could not probe opencode", { error }); + + process.exit(1); + } + + log("INFO", "Server listening"); +}