|
1 | | -import { createDefaultDeps } from "../index.js"; |
2 | | -import { logWebSelfId, logTwilioFrom, monitorTwilio } from "../index.js"; |
| 1 | +import { ensureBinary } from "../infra/binaries.js"; |
| 2 | +import { ensurePortAvailable, handlePortError } from "../infra/ports.js"; |
| 3 | +import { ensureFunnel, getTailnetHostname } from "../infra/tailscale.js"; |
| 4 | +import { waitForever } from "./wait.js"; |
| 5 | +import { readEnv } from "../env.js"; |
| 6 | +import { monitorTwilio as monitorTwilioImpl } from "../twilio/monitor.js"; |
| 7 | +import { sendMessage, waitForFinalStatus } from "../twilio/send.js"; |
| 8 | +import { sendMessageWeb, monitorWebProvider, logWebSelfId } from "../provider-web.js"; |
| 9 | +import { assertProvider, sleep } from "../utils.js"; |
| 10 | +import { createClient } from "../twilio/client.js"; |
| 11 | +import { listRecentMessages } from "../twilio/messages.js"; |
| 12 | +import { updateWebhook } from "../twilio/update-webhook.js"; |
| 13 | +import { findWhatsappSenderSid } from "../twilio/senders.js"; |
| 14 | +import { startWebhook } from "../twilio/webhook.js"; |
| 15 | +import { defaultRuntime, type RuntimeEnv } from "../runtime.js"; |
| 16 | +import { info } from "../globals.js"; |
| 17 | +import { autoReplyIfConfigured } from "../auto-reply/reply.js"; |
3 | 18 |
|
4 | | -export { createDefaultDeps, logWebSelfId, logTwilioFrom, monitorTwilio }; |
| 19 | +export type CliDeps = { |
| 20 | + sendMessage: typeof sendMessage; |
| 21 | + sendMessageWeb: typeof sendMessageWeb; |
| 22 | + waitForFinalStatus: typeof waitForFinalStatus; |
| 23 | + assertProvider: typeof assertProvider; |
| 24 | + createClient?: typeof createClient; |
| 25 | + monitorTwilio: typeof monitorTwilio; |
| 26 | + listRecentMessages: typeof listRecentMessages; |
| 27 | + ensurePortAvailable: typeof ensurePortAvailable; |
| 28 | + startWebhook: typeof import("../twilio/webhook.js").startWebhook; |
| 29 | + waitForever: typeof waitForever; |
| 30 | + ensureBinary: typeof ensureBinary; |
| 31 | + ensureFunnel: typeof ensureFunnel; |
| 32 | + getTailnetHostname: typeof getTailnetHostname; |
| 33 | + readEnv: typeof readEnv; |
| 34 | + findWhatsappSenderSid: typeof findWhatsappSenderSid; |
| 35 | + updateWebhook: typeof updateWebhook; |
| 36 | + handlePortError: typeof handlePortError; |
| 37 | + monitorWebProvider: typeof monitorWebProvider; |
| 38 | +}; |
| 39 | + |
| 40 | +export async function monitorTwilio( |
| 41 | + intervalSeconds: number, |
| 42 | + lookbackMinutes: number, |
| 43 | + clientOverride?: ReturnType<typeof createClient>, |
| 44 | + maxIterations = Infinity, |
| 45 | +) { |
| 46 | + // Adapter that wires default deps/runtime for the Twilio monitor loop. |
| 47 | + return monitorTwilioImpl(intervalSeconds, lookbackMinutes, { |
| 48 | + client: clientOverride, |
| 49 | + maxIterations, |
| 50 | + deps: { |
| 51 | + autoReplyIfConfigured, |
| 52 | + listRecentMessages, |
| 53 | + readEnv, |
| 54 | + createClient, |
| 55 | + sleep, |
| 56 | + }, |
| 57 | + runtime: defaultRuntime, |
| 58 | + }); |
| 59 | +} |
| 60 | + |
| 61 | +export function createDefaultDeps(): CliDeps { |
| 62 | + // Default dependency bundle used by CLI commands and tests. |
| 63 | + return { |
| 64 | + sendMessage, |
| 65 | + sendMessageWeb, |
| 66 | + waitForFinalStatus, |
| 67 | + assertProvider, |
| 68 | + createClient, |
| 69 | + monitorTwilio, |
| 70 | + listRecentMessages, |
| 71 | + ensurePortAvailable, |
| 72 | + startWebhook, |
| 73 | + waitForever, |
| 74 | + ensureBinary, |
| 75 | + ensureFunnel, |
| 76 | + getTailnetHostname, |
| 77 | + readEnv, |
| 78 | + findWhatsappSenderSid, |
| 79 | + updateWebhook, |
| 80 | + handlePortError, |
| 81 | + monitorWebProvider, |
| 82 | + }; |
| 83 | +} |
| 84 | + |
| 85 | +export function logTwilioFrom(runtime: RuntimeEnv = defaultRuntime) { |
| 86 | + // Log the configured Twilio sender for clarity in CLI output. |
| 87 | + const env = readEnv(runtime); |
| 88 | + runtime.log( |
| 89 | + info(`Provider: twilio (polling inbound) | from ${env.whatsappFrom}`), |
| 90 | + ); |
| 91 | +} |
| 92 | + |
| 93 | +export { logWebSelfId }; |
0 commit comments