From d6491d8d7151e5c6455fd046a5f5d42c4993e213 Mon Sep 17 00:00:00 2001 From: Shakker Date: Tue, 3 Mar 2026 00:04:52 +0000 Subject: [PATCH] fix: narrow webhook event provider call id typing --- extensions/voice-call/src/manager/events.ts | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/extensions/voice-call/src/manager/events.ts b/extensions/voice-call/src/manager/events.ts index b32c4b267ce..668369e0c35 100644 --- a/extensions/voice-call/src/manager/events.ts +++ b/extensions/voice-call/src/manager/events.ts @@ -110,19 +110,18 @@ export function processEvent(ctx: EventContext, event: NormalizedEvent): void { callIdOrProviderCallId: event.callId, }); + const providerCallId = event.providerCallId; + const eventDirection = + event.direction === "inbound" || event.direction === "outbound" ? event.direction : undefined; + // Auto-register untracked calls arriving via webhook. This covers both // true inbound calls and externally-initiated outbound-api calls (e.g. calls // placed directly via the Twilio REST API pointing at our webhook URL). - const isUnregisteredWebhookCall = - !call && - event.providerCallId && - (event.direction === "inbound" || event.direction === "outbound"); - - if (isUnregisteredWebhookCall) { + if (!call && providerCallId && eventDirection) { // Apply inbound policy for true inbound calls; external outbound-api calls // are implicitly trusted because the caller controls the webhook URL. - if (event.direction === "inbound" && !shouldAcceptInbound(ctx.config, event.from)) { - const pid = event.providerCallId; + if (eventDirection === "inbound" && !shouldAcceptInbound(ctx.config, event.from)) { + const pid = providerCallId; if (!ctx.provider) { console.warn( `[voice-call] Inbound call rejected by policy but no provider to hang up (providerCallId: ${pid}, from: ${event.from}); call will time out on provider side.`, @@ -150,8 +149,8 @@ export function processEvent(ctx: EventContext, event: NormalizedEvent): void { call = createWebhookCall({ ctx, - providerCallId: event.providerCallId, - direction: event.direction === "outbound" ? "outbound" : "inbound", + providerCallId, + direction: eventDirection === "outbound" ? "outbound" : "inbound", from: event.from || "unknown", to: event.to || ctx.config.fromNumber || "unknown", });