commit 42a28052c80f7703280a116423891d9aeca44283
parent 29f3eeee7537233b3ab0bffb37e7326e3e244544
Author: Henry Unite <unitehenry@gmail.com>
Date: Thu, 26 Feb 2026 08:19:36 +0000
refactor: logs
Diffstat:
2 files changed, 13 insertions(+), 12 deletions(-)
diff --git a/app.ts b/app.ts
@@ -41,21 +41,23 @@ function hangup(res: Response): void {
app.post("/voice", async (req: Request, res: Response): Promise<void> => {
const callId: string = req.body.CallSid;
- console.log(`Call ID: ${callId}`);
+ log("INFO", `Call webhook received`, { callId });
const speechResult: string = req.body.SpeechResult;
if (speechResult) {
- console.log("User message:", speechResult);
+ log("INFO", "Caller message received", { callId, speechResult });
const { sessionId, text } = await prompt(
speechResult,
app.get(callId) as string | null,
);
+ log("INFO", "Agent responded", { callId, sessionId, text });
+
app.set(callId, sessionId);
- console.log(text);
+ log("INFO", "Session cached", { callId, sessionId });
agentResponse(res, text);
} else {
@@ -66,17 +68,17 @@ app.post("/voice", async (req: Request, res: Response): Promise<void> => {
app.post("/message", async (req: Request, res: Response): Promise<void> => {
const messageId: string = req.body.MessageSid;
- console.log(`Message ID: ${messageId}`);
+ log("INFO", `Message webhook received`, { messageId });
const messageResult: string = req.body.Body;
if (!messageResult) return;
- console.log("User message:", messageResult);
+ log("INFO", "User message received", {messageResult});
- const { text } = await prompt(messageResult, null);
+ const { sessionId, text } = await prompt(messageResult, null);
- console.log(text);
+ log("INFO", "Agent responded", { sessionId, text });
smsResponse(res, text);
});
@@ -85,6 +87,4 @@ app.get("/health", (req, res) => res.sendStatus(200));
const port: number = parseInt(process.env.PORT || "3000", 10);
-app.listen(port, (): void => {
- log("INFO", `Server running on port ${port}`);
-});
+app.listen(port, (): void => log("INFO", `Server running on port ${port}`));
diff --git a/prompt.ts b/prompt.ts
@@ -1,4 +1,5 @@
import { createOpencodeClient } from "@opencode-ai/sdk";
+import log from "./log.ts";
interface PromptResult {
sessionId: string;
@@ -9,7 +10,7 @@ export async function prompt(
message: string,
sessionId: string | null,
): Promise<PromptResult> {
- console.log(`Session ID Param: ${sessionId}`);
+ log("INFO", `Session ID Param: ${sessionId}`);
const client = createOpencodeClient({
baseUrl: "http://127.0.0.1:36967",
@@ -25,7 +26,7 @@ export async function prompt(
return sessionResult.data.id;
})();
- console.log(`Session ID: ${id}`);
+ log("INFO", `Session ID: ${id}`);
const result = await client.session.prompt({
path: { id },