fix: narrow webhook event provider call id typing

This commit is contained in:
Shakker
2026-03-03 00:04:52 +00:00
parent 6b85ec3022
commit d6491d8d71

View File

@@ -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",
});