@openclaw/sms 2026.10.10-beta.5 → 2026.11.5-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/.setup/{media-BIjSnGTm.mjs → media-BF6-nsm2.mjs} +17 -34
- package/dist/.setup/{runtime-BBlPgBIF.mjs → runtime-A8rnEOmw.mjs} +1 -2
- package/dist/.setup/{secret-contract-B2P_lFGm.mjs → secret-contract-BTxRnkG1.mjs} +1 -2
- package/dist/.setup/{twilio-BvmfwtSb.mjs → twilio-07yIWayE.mjs} +42 -95
- package/dist/.source-module-urls/795a0e3f2ca7aa49f58abd6277a5075ff6437cd84711eea7629da8f4ff8f2b43.json +1 -1
- package/dist/api.js +1 -1
- package/dist/channel-plugin-api.js +295 -388
- package/dist/configured-state.js +1 -2
- package/dist/index.js +1 -2
- package/dist/secret-contract-api.js +1 -1
- package/node_modules/zod/package.json +1 -1
- package/node_modules/zod/src/v4/classic/tests/array.test.ts +27 -0
- package/node_modules/zod/src/v4/classic/tests/map.test.ts +7 -0
- package/node_modules/zod/src/v4/classic/tests/set.test.ts +6 -0
- package/node_modules/zod/src/v4/core/compile.ts +9 -0
- package/node_modules/zod/src/v4/core/schemas.ts +35 -1
- package/node_modules/zod/src/v4/core/util.ts +13 -0
- package/node_modules/zod/src/v4/core/versions.ts +1 -1
- package/node_modules/zod/v4/core/compile.cjs +8 -0
- package/node_modules/zod/v4/core/compile.js +8 -0
- package/node_modules/zod/v4/core/schemas.cjs +30 -0
- package/node_modules/zod/v4/core/schemas.d.cts +3 -1
- package/node_modules/zod/v4/core/schemas.d.ts +3 -1
- package/node_modules/zod/v4/core/schemas.js +30 -0
- package/node_modules/zod/v4/core/util.cjs +15 -0
- package/node_modules/zod/v4/core/util.d.cts +2 -0
- package/node_modules/zod/v4/core/util.d.ts +2 -0
- package/node_modules/zod/v4/core/util.js +14 -0
- package/node_modules/zod/v4/core/versions.cjs +1 -1
- package/node_modules/zod/v4/core/versions.js +1 -1
- package/package.json +5 -5
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { t as getSmsRuntime } from "./.setup/runtime-
|
|
2
|
-
import { C as normalizeSmsAllowFrom, S as looksLikeSmsPhoneNumber, _ as isSmsAccountConfigured, a as listTwilioIncomingPhoneNumbers, b as resolveSmsAccount, c as resolveTwilioInboundSender, d as respondTwiml, f as retrieveTwilioMessagingService, g as inspectSmsAccount, h as assertSmsCredentialOwnerAvailable, i as buildTwilioInboundMessage, l as resolveTwilioMessageSid, m as verifyTwilioSignature, o as listTwilioMessages, p as sendSmsViaTwilio, r as TWIML_CONTENT_TYPE, s as readTwilioWebhookForm, t as TWILIO_MESSAGE_BODY_MAX_LENGTH, u as resolveTwilioWebhookSignatureUrl, v as listSmsAccountIds, w as normalizeSmsPhoneNumber, x as resolveTwilioStatusCallbackUrl, y as resolveDefaultSmsAccountId } from "./.setup/twilio-
|
|
3
|
-
import { n as collectRuntimeConfigAssignments, r as secretTargetRegistryEntries } from "./.setup/secret-contract-
|
|
1
|
+
import { t as getSmsRuntime } from "./.setup/runtime-A8rnEOmw.mjs";
|
|
2
|
+
import { C as normalizeSmsAllowFrom, S as looksLikeSmsPhoneNumber, _ as isSmsAccountConfigured, a as listTwilioIncomingPhoneNumbers, b as resolveSmsAccount, c as resolveTwilioInboundSender, d as respondTwiml, f as retrieveTwilioMessagingService, g as inspectSmsAccount, h as assertSmsCredentialOwnerAvailable, i as buildTwilioInboundMessage, l as resolveTwilioMessageSid, m as verifyTwilioSignature, o as listTwilioMessages, p as sendSmsViaTwilio, r as TWIML_CONTENT_TYPE, s as readTwilioWebhookForm, t as TWILIO_MESSAGE_BODY_MAX_LENGTH, u as resolveTwilioWebhookSignatureUrl, v as listSmsAccountIds, w as normalizeSmsPhoneNumber, x as resolveTwilioStatusCallbackUrl, y as resolveDefaultSmsAccountId } from "./.setup/twilio-07yIWayE.mjs";
|
|
3
|
+
import { n as collectRuntimeConfigAssignments, r as secretTargetRegistryEntries } from "./.setup/secret-contract-BTxRnkG1.mjs";
|
|
4
4
|
import { DEFAULT_ACCOUNT_ID } from "openclaw/plugin-sdk/account-id";
|
|
5
5
|
import { createHybridChannelConfigAdapter, createScopedDmSecurityResolver } from "openclaw/plugin-sdk/channel-config-helpers";
|
|
6
6
|
import { buildChannelOutboundSessionRoute, createChatChannelPlugin } from "openclaw/plugin-sdk/channel-core";
|
|
@@ -16,14 +16,13 @@ import { buildSecretInputSchema } from "openclaw/plugin-sdk/secret-input";
|
|
|
16
16
|
import { AllowFromListSchema, DmPolicySchema, buildChannelConfigSchema, buildMultiAccountChannelSchema, requireOpenAllowFrom } from "openclaw/plugin-sdk/channel-config-schema";
|
|
17
17
|
import { requireChannelOpenAllowFrom } from "openclaw/plugin-sdk/extension-shared";
|
|
18
18
|
import { z } from "zod";
|
|
19
|
-
import {
|
|
20
|
-
import { withTimeout } from "openclaw/plugin-sdk/text-utility-runtime";
|
|
19
|
+
import { sha256Hex } from "openclaw/plugin-sdk/node-crypto-runtime";
|
|
21
20
|
import { createFixedWindowRateLimiter, isRequestBodyLimitError, registerPluginHttpRoute, resolveRequestClientIp } from "openclaw/plugin-sdk/webhook-ingress";
|
|
22
21
|
import { channelBlockedPatch, channelReadyPatch, channelStoppedPatch } from "openclaw/plugin-sdk/gateway-runtime";
|
|
23
22
|
import { createWebhookInFlightLimiter, runDetachedWebhookWork, sendHttpRequestRejection } from "openclaw/plugin-sdk/webhook-request-guards";
|
|
24
23
|
import { createChannelPairingChallengeIssuer } from "openclaw/plugin-sdk/channel-pairing";
|
|
25
24
|
import { createChannelPartialDeliveryError } from "openclaw/plugin-sdk/channel-inbound";
|
|
26
|
-
|
|
25
|
+
// extensions/sms/src/config-schema.ts
|
|
27
26
|
const SecretInputSchema = buildSecretInputSchema();
|
|
28
27
|
const SmsAccountConfigSchema = z.object({
|
|
29
28
|
name: z.string().optional(),
|
|
@@ -106,8 +105,7 @@ const SmsChannelConfigSchema = buildChannelConfigSchema(SmsConfigSchema, { uiHin
|
|
|
106
105
|
help: "Maximum characters per outbound SMS chunk before OpenClaw splits long replies."
|
|
107
106
|
}
|
|
108
107
|
} });
|
|
109
|
-
|
|
110
|
-
//#region extensions/sms/src/delivery-observations.ts
|
|
108
|
+
// extensions/sms/src/delivery-observations.ts
|
|
111
109
|
const DELIVERY_NAMESPACE = "twilio-delivery-observations-v1";
|
|
112
110
|
const DELIVERY_RETENTION_MS = 2592e6;
|
|
113
111
|
const DELIVERY_MAX_MESSAGES = 5e3;
|
|
@@ -137,20 +135,14 @@ function normalizeDeliveryStatus(rawStatus) {
|
|
|
137
135
|
function resolveDeliveryStatus(form) {
|
|
138
136
|
return normalizeDeliveryStatus(firstTrimmed(form, "MessageStatus") || firstTrimmed(form, "SmsStatus"));
|
|
139
137
|
}
|
|
140
|
-
function hashAccountSid(accountSid) {
|
|
141
|
-
return createHash("sha256").update(accountSid).digest("hex");
|
|
142
|
-
}
|
|
143
138
|
function fingerprintObservation(params) {
|
|
144
|
-
return
|
|
139
|
+
return sha256Hex(JSON.stringify([
|
|
145
140
|
params.source,
|
|
146
141
|
params.messageSid,
|
|
147
142
|
params.status,
|
|
148
143
|
params.errorCode ?? "",
|
|
149
144
|
params.rawDlrDoneDate ?? ""
|
|
150
|
-
]))
|
|
151
|
-
}
|
|
152
|
-
function deliveryRecordKey(params) {
|
|
153
|
-
return createHash("sha256").update(`${params.accountId}\n${params.accountSidHash}\n${params.messageSid}`).digest("hex");
|
|
145
|
+
]));
|
|
154
146
|
}
|
|
155
147
|
function openDeliveryStore() {
|
|
156
148
|
const runtime = getSmsRuntime();
|
|
@@ -168,30 +160,6 @@ function openDeliveryStore() {
|
|
|
168
160
|
function isTwilioDeliveryStatusForm(form) {
|
|
169
161
|
return Boolean(resolveDeliveryStatus(form));
|
|
170
162
|
}
|
|
171
|
-
function parseSmsDeliveryObservation(form, nowMs = Date.now()) {
|
|
172
|
-
const messageSid = resolveTwilioMessageSid(form);
|
|
173
|
-
const status = resolveDeliveryStatus(form);
|
|
174
|
-
if (!messageSid || !status) return null;
|
|
175
|
-
const errorCode = firstTrimmed(form, "ErrorCode");
|
|
176
|
-
const rawDlrDoneDate = firstTrimmed(form, "RawDlrDoneDate");
|
|
177
|
-
return {
|
|
178
|
-
messageSid,
|
|
179
|
-
observation: {
|
|
180
|
-
source: "callback",
|
|
181
|
-
fingerprint: fingerprintObservation({
|
|
182
|
-
source: "callback",
|
|
183
|
-
messageSid,
|
|
184
|
-
status,
|
|
185
|
-
...errorCode ? { errorCode } : {},
|
|
186
|
-
...rawDlrDoneDate ? { rawDlrDoneDate } : {}
|
|
187
|
-
}),
|
|
188
|
-
status,
|
|
189
|
-
observedAt: nowMs,
|
|
190
|
-
...errorCode ? { errorCode } : {},
|
|
191
|
-
...rawDlrDoneDate ? { rawDlrDoneDate } : {}
|
|
192
|
-
}
|
|
193
|
-
};
|
|
194
|
-
}
|
|
195
163
|
function reduceDeliveryStatus(current, observation) {
|
|
196
164
|
if (current?.status === "conflicted") return {
|
|
197
165
|
status: current.status,
|
|
@@ -223,39 +191,32 @@ function reduceDeliveryStatus(current, observation) {
|
|
|
223
191
|
...selected === current && current.conflict ? { conflict: true } : {}
|
|
224
192
|
};
|
|
225
193
|
}
|
|
226
|
-
function mergeSmsDeliveryObservation(params) {
|
|
227
|
-
if (params.current?.observations.some((existing) => existing.fingerprint === params.observation.fingerprint)) return;
|
|
228
|
-
const reduced = reduceDeliveryStatus(params.current, params.observation);
|
|
229
|
-
return {
|
|
230
|
-
accountId: params.accountId,
|
|
231
|
-
accountSidHash: params.accountSidHash,
|
|
232
|
-
messageSid: params.messageSid,
|
|
233
|
-
status: reduced.status,
|
|
234
|
-
firstObservedAt: params.current?.firstObservedAt ?? params.observation.observedAt,
|
|
235
|
-
lastObservedAt: params.observation.observedAt,
|
|
236
|
-
...reduced.errorCode ? { errorCode: reduced.errorCode } : {},
|
|
237
|
-
...reduced.conflict ? { conflict: true } : {},
|
|
238
|
-
observations: [...params.current?.observations ?? [], params.observation].slice(-20)
|
|
239
|
-
};
|
|
240
|
-
}
|
|
241
194
|
async function recordSmsDeliveryObservation(params) {
|
|
242
195
|
if (!params.store.observe || !params.store.compareAndApply) throw new Error("SMS delivery observations require plugin state comparisons.");
|
|
243
196
|
const accountId = params.account.accountId;
|
|
244
|
-
const accountSidHash =
|
|
245
|
-
const key =
|
|
246
|
-
accountId,
|
|
247
|
-
accountSidHash,
|
|
248
|
-
messageSid: params.messageSid
|
|
249
|
-
});
|
|
197
|
+
const accountSidHash = sha256Hex(params.account.accountSid);
|
|
198
|
+
const key = sha256Hex(`${accountId}\n${accountSidHash}\n${params.messageSid}`);
|
|
250
199
|
let observed = await params.store.observe(key);
|
|
251
|
-
|
|
252
|
-
const
|
|
200
|
+
function mergeSmsDeliveryObservation() {
|
|
201
|
+
const messageSid = params.messageSid;
|
|
202
|
+
const current = observed.value;
|
|
203
|
+
const observation = params.observation;
|
|
204
|
+
if (current?.observations.some((existing) => existing.fingerprint === observation.fingerprint)) return;
|
|
205
|
+
const reduced = reduceDeliveryStatus(current, observation);
|
|
206
|
+
return {
|
|
253
207
|
accountId,
|
|
254
208
|
accountSidHash,
|
|
255
|
-
messageSid
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
209
|
+
messageSid,
|
|
210
|
+
status: reduced.status,
|
|
211
|
+
firstObservedAt: current?.firstObservedAt ?? observation.observedAt,
|
|
212
|
+
lastObservedAt: observation.observedAt,
|
|
213
|
+
...reduced.errorCode ? { errorCode: reduced.errorCode } : {},
|
|
214
|
+
...reduced.conflict ? { conflict: true } : {},
|
|
215
|
+
observations: [...current?.observations ?? [], observation].slice(-20)
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
while (true) {
|
|
219
|
+
const next = mergeSmsDeliveryObservation();
|
|
259
220
|
const result = await params.store.compareAndApply(key, observed.comparison, next ? {
|
|
260
221
|
operation: "update",
|
|
261
222
|
action: "set",
|
|
@@ -276,14 +237,32 @@ async function recordSmsDeliveryObservation(params) {
|
|
|
276
237
|
};
|
|
277
238
|
}
|
|
278
239
|
}
|
|
279
|
-
function createSmsDeliveryRecorder(
|
|
240
|
+
function createSmsDeliveryRecorder() {
|
|
241
|
+
const store = openDeliveryStore();
|
|
280
242
|
return { async record({ account, form }) {
|
|
281
|
-
const
|
|
282
|
-
|
|
243
|
+
const nowMs = Date.now();
|
|
244
|
+
const messageSid = resolveTwilioMessageSid(form);
|
|
245
|
+
const status = resolveDeliveryStatus(form);
|
|
246
|
+
if (!messageSid || !status) throw new Error("Invalid Twilio delivery status callback.");
|
|
247
|
+
const errorCode = firstTrimmed(form, "ErrorCode");
|
|
248
|
+
const rawDlrDoneDate = firstTrimmed(form, "RawDlrDoneDate");
|
|
283
249
|
return await recordSmsDeliveryObservation({
|
|
284
250
|
account,
|
|
285
|
-
messageSid
|
|
286
|
-
observation:
|
|
251
|
+
messageSid,
|
|
252
|
+
observation: {
|
|
253
|
+
source: "callback",
|
|
254
|
+
fingerprint: fingerprintObservation({
|
|
255
|
+
source: "callback",
|
|
256
|
+
messageSid,
|
|
257
|
+
status,
|
|
258
|
+
...errorCode ? { errorCode } : {},
|
|
259
|
+
...rawDlrDoneDate ? { rawDlrDoneDate } : {}
|
|
260
|
+
}),
|
|
261
|
+
status,
|
|
262
|
+
observedAt: nowMs,
|
|
263
|
+
...errorCode ? { errorCode } : {},
|
|
264
|
+
...rawDlrDoneDate ? { rawDlrDoneDate } : {}
|
|
265
|
+
},
|
|
287
266
|
store
|
|
288
267
|
});
|
|
289
268
|
} };
|
|
@@ -303,18 +282,17 @@ async function recordInitialSmsDeliveryResult(params) {
|
|
|
303
282
|
status
|
|
304
283
|
}),
|
|
305
284
|
status,
|
|
306
|
-
observedAt:
|
|
285
|
+
observedAt: Date.now()
|
|
307
286
|
},
|
|
308
|
-
store:
|
|
287
|
+
store: openDeliveryStore()
|
|
309
288
|
});
|
|
310
289
|
}
|
|
311
|
-
async function listRecentSmsDeliveryRecords(account
|
|
312
|
-
|
|
313
|
-
const accountSidHash =
|
|
314
|
-
return (await store.entries()).map((entry) => entry.value).filter((record) => record.accountId === account.accountId && record.accountSidHash === accountSidHash).toSorted((left, right) => right.lastObservedAt - left.lastObservedAt).slice(0,
|
|
290
|
+
async function listRecentSmsDeliveryRecords(account) {
|
|
291
|
+
const store = openDeliveryStore();
|
|
292
|
+
const accountSidHash = sha256Hex(account.accountSid);
|
|
293
|
+
return (await store.entries()).map((entry) => entry.value).filter((record) => record.accountId === account.accountId && record.accountSidHash === accountSidHash).toSorted((left, right) => right.lastObservedAt - left.lastObservedAt).slice(0, 1);
|
|
315
294
|
}
|
|
316
|
-
|
|
317
|
-
//#region extensions/sms/src/send.ts
|
|
295
|
+
// extensions/sms/src/send.ts
|
|
318
296
|
const SMS_ASSISTANT_TRANSCRIPT_ROLE_PREFIX = "[assistant-authored transcript] ";
|
|
319
297
|
function createSmsMessageReceipt(params) {
|
|
320
298
|
const receipt = createMessageReceiptFromOutboundResults({
|
|
@@ -446,7 +424,7 @@ async function prepareSmsMediaAttempt(params) {
|
|
|
446
424
|
});
|
|
447
425
|
let hostedMedia;
|
|
448
426
|
try {
|
|
449
|
-
const { prepareHostedSmsMedia } = await import("./.setup/media-
|
|
427
|
+
const { prepareHostedSmsMedia } = await import("./.setup/media-BF6-nsm2.mjs");
|
|
450
428
|
assertSmsCredentialOwnerAvailable(params.account);
|
|
451
429
|
const prepared = await prepareHostedSmsMedia({
|
|
452
430
|
account: params.account,
|
|
@@ -476,88 +454,76 @@ async function sendPreparedSmsMediaAttempt(params) {
|
|
|
476
454
|
mediaUrls: [params.attempt.hostedMediaUrl]
|
|
477
455
|
}, ...params.attempt.remainingChunks.map((text) => ({ text }))], "media");
|
|
478
456
|
}
|
|
479
|
-
|
|
480
|
-
//#region extensions/sms/src/inbound.ts
|
|
457
|
+
// extensions/sms/src/inbound.ts
|
|
481
458
|
const CHANNEL_ID$2 = "sms";
|
|
482
|
-
async function authorizeSmsSender(params) {
|
|
483
|
-
const commandRequested = params.channelRuntime.commands.shouldComputeCommandAuthorized(params.rawBody, params.cfg);
|
|
484
|
-
return await params.channelRuntime.inbound.ingress.resolveStable({
|
|
485
|
-
channelId: CHANNEL_ID$2,
|
|
486
|
-
accountId: params.account.accountId,
|
|
487
|
-
cfg: params.cfg,
|
|
488
|
-
identity: {
|
|
489
|
-
key: "phone",
|
|
490
|
-
entryIdPrefix: "sms-entry"
|
|
491
|
-
},
|
|
492
|
-
readStoreAllowFrom: async () => await params.channelRuntime.pairing.readAllowFromStore({
|
|
493
|
-
channel: CHANNEL_ID$2,
|
|
494
|
-
accountId: params.account.accountId
|
|
495
|
-
}),
|
|
496
|
-
subject: { stableId: params.from },
|
|
497
|
-
conversation: {
|
|
498
|
-
kind: "direct",
|
|
499
|
-
id: params.from
|
|
500
|
-
},
|
|
501
|
-
contextBinding: params.contextBinding,
|
|
502
|
-
event: { mayPair: true },
|
|
503
|
-
dmPolicy: params.account.dmPolicy,
|
|
504
|
-
allowFrom: params.account.allowFrom,
|
|
505
|
-
command: commandRequested ? {
|
|
506
|
-
cfg: params.cfg,
|
|
507
|
-
modeWhenAccessGroupsOff: "configured"
|
|
508
|
-
} : void 0
|
|
509
|
-
});
|
|
510
|
-
}
|
|
511
|
-
async function issueSmsPairingChallenge(params) {
|
|
512
|
-
await createChannelPairingChallengeIssuer({
|
|
513
|
-
channel: CHANNEL_ID$2,
|
|
514
|
-
accountId: params.account.accountId,
|
|
515
|
-
upsertPairingRequest: async (input) => await params.channelRuntime.pairing.upsertPairingRequest({
|
|
516
|
-
channel: CHANNEL_ID$2,
|
|
517
|
-
accountId: params.account.accountId,
|
|
518
|
-
...input
|
|
519
|
-
})
|
|
520
|
-
})({
|
|
521
|
-
senderId: params.from,
|
|
522
|
-
senderIdLine: `Your SMS phone number: ${params.from}`,
|
|
523
|
-
sendPairingReply: async (text) => {
|
|
524
|
-
await sendSmsTextChunks({
|
|
525
|
-
account: params.account,
|
|
526
|
-
to: params.from,
|
|
527
|
-
text
|
|
528
|
-
});
|
|
529
|
-
},
|
|
530
|
-
onCreated: () => {
|
|
531
|
-
params.log?.info?.(`SMS pairing request created for ${params.from}`);
|
|
532
|
-
},
|
|
533
|
-
onReplyError: (err) => {
|
|
534
|
-
params.log?.warn?.(`SMS pairing reply failed for ${params.from}: ${String(err)}`);
|
|
535
|
-
}
|
|
536
|
-
});
|
|
537
|
-
}
|
|
538
459
|
async function dispatchSmsInboundEvent(params) {
|
|
539
460
|
const from = normalizeSmsPhoneNumber(params.msg.from);
|
|
540
|
-
|
|
541
|
-
cfg
|
|
542
|
-
|
|
543
|
-
channelRuntime
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
461
|
+
async function authorizeSmsSender(contextBinding) {
|
|
462
|
+
const { cfg, account, channelRuntime } = params;
|
|
463
|
+
const rawBody = params.msg.body;
|
|
464
|
+
const commandRequested = channelRuntime.commands.shouldComputeCommandAuthorized(rawBody, cfg);
|
|
465
|
+
return await channelRuntime.inbound.ingress.resolveStable({
|
|
466
|
+
channelId: CHANNEL_ID$2,
|
|
467
|
+
accountId: account.accountId,
|
|
468
|
+
cfg,
|
|
469
|
+
identity: {
|
|
470
|
+
key: "phone",
|
|
471
|
+
entryIdPrefix: "sms-entry"
|
|
472
|
+
},
|
|
473
|
+
readStoreAllowFrom: async () => await channelRuntime.pairing.readAllowFromStore({
|
|
474
|
+
channel: CHANNEL_ID$2,
|
|
475
|
+
accountId: account.accountId
|
|
476
|
+
}),
|
|
477
|
+
subject: { stableId: from },
|
|
478
|
+
conversation: {
|
|
479
|
+
kind: "direct",
|
|
480
|
+
id: from
|
|
481
|
+
},
|
|
482
|
+
contextBinding,
|
|
483
|
+
event: { mayPair: true },
|
|
484
|
+
dmPolicy: account.dmPolicy,
|
|
485
|
+
allowFrom: account.allowFrom,
|
|
486
|
+
command: commandRequested ? {
|
|
487
|
+
cfg,
|
|
488
|
+
modeWhenAccessGroupsOff: "configured"
|
|
489
|
+
} : void 0
|
|
490
|
+
});
|
|
491
|
+
}
|
|
492
|
+
let auth = await authorizeSmsSender();
|
|
547
493
|
if (!auth.senderAccess.allowed) {
|
|
548
494
|
if (auth.senderAccess.decision === "pairing") {
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
495
|
+
const { account, channelRuntime, log } = params;
|
|
496
|
+
await createChannelPairingChallengeIssuer({
|
|
497
|
+
channel: CHANNEL_ID$2,
|
|
498
|
+
accountId: account.accountId,
|
|
499
|
+
upsertPairingRequest: async (input) => await channelRuntime.pairing.upsertPairingRequest({
|
|
500
|
+
channel: CHANNEL_ID$2,
|
|
501
|
+
accountId: account.accountId,
|
|
502
|
+
...input
|
|
503
|
+
})
|
|
504
|
+
})({
|
|
505
|
+
senderId: from,
|
|
506
|
+
senderIdLine: `Your SMS phone number: ${from}`,
|
|
507
|
+
sendPairingReply: async (text) => {
|
|
508
|
+
await sendSmsTextChunks({
|
|
509
|
+
account,
|
|
510
|
+
to: from,
|
|
511
|
+
text
|
|
512
|
+
});
|
|
513
|
+
},
|
|
514
|
+
onCreated: () => {
|
|
515
|
+
log?.info?.(`SMS pairing request created for ${from}`);
|
|
516
|
+
},
|
|
517
|
+
onReplyError: (err) => {
|
|
518
|
+
log?.warn?.(`SMS pairing reply failed for ${from}: ${String(err)}`);
|
|
519
|
+
}
|
|
554
520
|
});
|
|
555
521
|
return;
|
|
556
522
|
}
|
|
557
523
|
params.log?.warn?.(`SMS sender ${from} is not authorized`);
|
|
558
524
|
return;
|
|
559
525
|
}
|
|
560
|
-
const materialized = params.msg.media.length > 0 || (params.msg.unavailableMediaCount ?? 0) > 0 ? await (await import("./.setup/media-
|
|
526
|
+
const materialized = params.msg.media.length > 0 || (params.msg.unavailableMediaCount ?? 0) > 0 ? await (await import("./.setup/media-BF6-nsm2.mjs")).materializeSmsInboundMedia({
|
|
561
527
|
account: params.account,
|
|
562
528
|
msg: params.msg,
|
|
563
529
|
mediaRuntime: params.channelRuntime,
|
|
@@ -604,17 +570,10 @@ async function dispatchSmsInboundEvent(params) {
|
|
|
604
570
|
});
|
|
605
571
|
const sessionKey = route.sessionKey;
|
|
606
572
|
auth = await authorizeSmsSender({
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
rawBody: params.msg.body,
|
|
612
|
-
contextBinding: {
|
|
613
|
-
agentId: route.agentId,
|
|
614
|
-
sessionKey,
|
|
615
|
-
messageId: params.msg.messageSid,
|
|
616
|
-
inboundEventKind: "user_request"
|
|
617
|
-
}
|
|
573
|
+
agentId: route.agentId,
|
|
574
|
+
sessionKey,
|
|
575
|
+
messageId: params.msg.messageSid,
|
|
576
|
+
inboundEventKind: "user_request"
|
|
618
577
|
});
|
|
619
578
|
if (!auth.senderAccess.allowed) {
|
|
620
579
|
params.log?.warn?.(`SMS sender ${from} authorization changed before dispatch`);
|
|
@@ -712,8 +671,7 @@ async function dispatchSmsInboundEvent(params) {
|
|
|
712
671
|
if (adoptionState === "pending" || adoptionState === "abandoned") await materialized.cleanup();
|
|
713
672
|
}
|
|
714
673
|
}
|
|
715
|
-
|
|
716
|
-
//#region extensions/sms/src/ingress-spool.ts
|
|
674
|
+
// extensions/sms/src/ingress-spool.ts
|
|
717
675
|
const SMS_INGRESS_PAYLOAD_VERSION = 1;
|
|
718
676
|
const SMS_INGRESS_DRAIN_INTERVAL_MS = 500;
|
|
719
677
|
var SmsIngressPermanentError = class extends Error {};
|
|
@@ -815,8 +773,7 @@ function createSmsIngressSpool(params) {
|
|
|
815
773
|
stop: monitor.stop
|
|
816
774
|
};
|
|
817
775
|
}
|
|
818
|
-
|
|
819
|
-
//#region extensions/sms/src/webhook.ts
|
|
776
|
+
// extensions/sms/src/webhook.ts
|
|
820
777
|
const INVALID_REQUEST_MAX_REQUESTS = 300;
|
|
821
778
|
const PRE_AUTH_MAX_IN_FLIGHT = 64;
|
|
822
779
|
const INBOUND_DISPATCH_MAX_REQUESTS = 30;
|
|
@@ -995,8 +952,7 @@ function createSmsWebhookHandler(params) {
|
|
|
995
952
|
return true;
|
|
996
953
|
};
|
|
997
954
|
}
|
|
998
|
-
|
|
999
|
-
//#region extensions/sms/src/gateway.ts
|
|
955
|
+
// extensions/sms/src/gateway.ts
|
|
1000
956
|
const CHANNEL_ID$1 = "sms";
|
|
1001
957
|
const activeRoutePaths = /* @__PURE__ */ new Map();
|
|
1002
958
|
const pendingRouteStops = /* @__PURE__ */ new Map();
|
|
@@ -1035,65 +991,6 @@ function collectSmsStartupWarnings(account) {
|
|
|
1035
991
|
if (account.dmPolicy === "open" && !account.allowFrom.includes("*")) warnings.push("- SMS: dmPolicy=open should set allowFrom=[\"*\"] or explicit sender numbers.");
|
|
1036
992
|
return warnings;
|
|
1037
993
|
}
|
|
1038
|
-
async function registerSmsWebhookRoute(params) {
|
|
1039
|
-
const webhookPath = normalizeWebhookPath(params.account.webhookPath);
|
|
1040
|
-
const currentRoute = activeRoutePaths.get(webhookPath);
|
|
1041
|
-
if (currentRoute && currentRoute.accountId !== params.account.accountId) throw new Error(`SMS webhook path ${webhookPath} is already registered by account ${currentRoute.accountId}; configure a distinct webhookPath for account ${params.account.accountId}.`);
|
|
1042
|
-
const predecessorStop = currentRoute ? stopSmsWebhookRoute(webhookPath, currentRoute) : pendingRouteStops.get(webhookPath) ?? Promise.resolve();
|
|
1043
|
-
const ingress = createSmsIngressSpool({
|
|
1044
|
-
cfg: params.cfg,
|
|
1045
|
-
account: params.account,
|
|
1046
|
-
channelRuntime: params.channelRuntime,
|
|
1047
|
-
...params.log ? { log: params.log } : {}
|
|
1048
|
-
});
|
|
1049
|
-
let unregisterRoute;
|
|
1050
|
-
try {
|
|
1051
|
-
const webhookHandler = createSmsWebhookHandler({
|
|
1052
|
-
...params,
|
|
1053
|
-
ingress
|
|
1054
|
-
});
|
|
1055
|
-
unregisterRoute = registerPluginHttpRoute({
|
|
1056
|
-
path: webhookPath,
|
|
1057
|
-
auth: "plugin",
|
|
1058
|
-
pluginId: CHANNEL_ID$1,
|
|
1059
|
-
accountId: params.account.accountId,
|
|
1060
|
-
throwOnFailure: true,
|
|
1061
|
-
log: (msg) => params.log?.info?.(msg),
|
|
1062
|
-
handler: async (req, res) => {
|
|
1063
|
-
const { tryHandleHostedSmsMediaRequest } = await import("./.setup/media-BIjSnGTm.mjs");
|
|
1064
|
-
if (await tryHandleHostedSmsMediaRequest(req, res, params.account.accountId)) return true;
|
|
1065
|
-
return await webhookHandler(req, res);
|
|
1066
|
-
}
|
|
1067
|
-
});
|
|
1068
|
-
} catch (error) {
|
|
1069
|
-
await Promise.allSettled([predecessorStop, ingress.stop()]);
|
|
1070
|
-
throw error;
|
|
1071
|
-
}
|
|
1072
|
-
const route = {
|
|
1073
|
-
accountId: params.account.accountId,
|
|
1074
|
-
ingress,
|
|
1075
|
-
unregisterRoute,
|
|
1076
|
-
ready: Promise.resolve()
|
|
1077
|
-
};
|
|
1078
|
-
activeRoutePaths.set(webhookPath, route);
|
|
1079
|
-
route.ready = predecessorStop.then(() => {
|
|
1080
|
-
if (activeRoutePaths.get(webhookPath) === route && !route.stopTask) ingress.start();
|
|
1081
|
-
});
|
|
1082
|
-
const unregister = () => stopSmsWebhookRoute(webhookPath, route);
|
|
1083
|
-
const readinessAbort = new AbortController();
|
|
1084
|
-
const lifecycle = waitUntilAbort(AbortSignal.any([params.abortSignal, readinessAbort.signal]), unregister);
|
|
1085
|
-
try {
|
|
1086
|
-
await route.ready;
|
|
1087
|
-
} catch (error) {
|
|
1088
|
-
readinessAbort.abort();
|
|
1089
|
-
await Promise.allSettled([lifecycle]);
|
|
1090
|
-
throw error;
|
|
1091
|
-
}
|
|
1092
|
-
return {
|
|
1093
|
-
lifecycle,
|
|
1094
|
-
isActive: () => activeRoutePaths.get(webhookPath) === route
|
|
1095
|
-
};
|
|
1096
|
-
}
|
|
1097
994
|
async function startSmsGatewayAccount(params) {
|
|
1098
995
|
params.statusSink?.({ lifecycle: "starting" });
|
|
1099
996
|
if (!params.account.enabled) {
|
|
@@ -1111,7 +1008,66 @@ async function startSmsGatewayAccount(params) {
|
|
|
1111
1008
|
return waitUntilAbort(params.abortSignal);
|
|
1112
1009
|
}
|
|
1113
1010
|
for (const warning of warnings) params.log?.warn?.(warning);
|
|
1114
|
-
|
|
1011
|
+
async function registerSmsWebhookRoute() {
|
|
1012
|
+
const webhookPath = normalizeWebhookPath(params.account.webhookPath);
|
|
1013
|
+
const currentRoute = activeRoutePaths.get(webhookPath);
|
|
1014
|
+
if (currentRoute && currentRoute.accountId !== params.account.accountId) throw new Error(`SMS webhook path ${webhookPath} is already registered by account ${currentRoute.accountId}; configure a distinct webhookPath for account ${params.account.accountId}.`);
|
|
1015
|
+
const predecessorStop = currentRoute ? stopSmsWebhookRoute(webhookPath, currentRoute) : pendingRouteStops.get(webhookPath) ?? Promise.resolve();
|
|
1016
|
+
const ingress = createSmsIngressSpool({
|
|
1017
|
+
cfg: params.cfg,
|
|
1018
|
+
account: params.account,
|
|
1019
|
+
channelRuntime: params.channelRuntime,
|
|
1020
|
+
...params.log ? { log: params.log } : {}
|
|
1021
|
+
});
|
|
1022
|
+
let unregisterRoute;
|
|
1023
|
+
try {
|
|
1024
|
+
const webhookHandler = createSmsWebhookHandler({
|
|
1025
|
+
...params,
|
|
1026
|
+
ingress
|
|
1027
|
+
});
|
|
1028
|
+
unregisterRoute = registerPluginHttpRoute({
|
|
1029
|
+
path: webhookPath,
|
|
1030
|
+
auth: "plugin",
|
|
1031
|
+
pluginId: CHANNEL_ID$1,
|
|
1032
|
+
accountId: params.account.accountId,
|
|
1033
|
+
throwOnFailure: true,
|
|
1034
|
+
log: (msg) => params.log?.info?.(msg),
|
|
1035
|
+
handler: async (req, res) => {
|
|
1036
|
+
const { tryHandleHostedSmsMediaRequest } = await import("./.setup/media-BF6-nsm2.mjs");
|
|
1037
|
+
if (await tryHandleHostedSmsMediaRequest(req, res, params.account.accountId)) return true;
|
|
1038
|
+
return await webhookHandler(req, res);
|
|
1039
|
+
}
|
|
1040
|
+
});
|
|
1041
|
+
} catch (error) {
|
|
1042
|
+
await Promise.allSettled([predecessorStop, ingress.stop()]);
|
|
1043
|
+
throw error;
|
|
1044
|
+
}
|
|
1045
|
+
const route = {
|
|
1046
|
+
accountId: params.account.accountId,
|
|
1047
|
+
ingress,
|
|
1048
|
+
unregisterRoute,
|
|
1049
|
+
ready: Promise.resolve()
|
|
1050
|
+
};
|
|
1051
|
+
activeRoutePaths.set(webhookPath, route);
|
|
1052
|
+
route.ready = predecessorStop.then(() => {
|
|
1053
|
+
if (activeRoutePaths.get(webhookPath) === route && !route.stopTask) ingress.start();
|
|
1054
|
+
});
|
|
1055
|
+
const unregister = () => stopSmsWebhookRoute(webhookPath, route);
|
|
1056
|
+
const readinessAbort = new AbortController();
|
|
1057
|
+
const lifecycle = waitUntilAbort(AbortSignal.any([params.abortSignal, readinessAbort.signal]), unregister);
|
|
1058
|
+
try {
|
|
1059
|
+
await route.ready;
|
|
1060
|
+
} catch (error) {
|
|
1061
|
+
readinessAbort.abort();
|
|
1062
|
+
await Promise.allSettled([lifecycle]);
|
|
1063
|
+
throw error;
|
|
1064
|
+
}
|
|
1065
|
+
return {
|
|
1066
|
+
lifecycle,
|
|
1067
|
+
isActive: () => activeRoutePaths.get(webhookPath) === route
|
|
1068
|
+
};
|
|
1069
|
+
}
|
|
1070
|
+
const registration = await registerSmsWebhookRoute();
|
|
1115
1071
|
if (registration.isActive()) {
|
|
1116
1072
|
params.log?.info?.(`Registered SMS webhook route ${params.account.webhookPath} for account ${params.account.accountId}`);
|
|
1117
1073
|
params.statusSink?.(channelReadyPatch());
|
|
@@ -1120,31 +1076,42 @@ async function startSmsGatewayAccount(params) {
|
|
|
1120
1076
|
params.statusSink?.(channelStoppedPatch());
|
|
1121
1077
|
});
|
|
1122
1078
|
}
|
|
1123
|
-
|
|
1124
|
-
//#region extensions/sms/src/status.ts
|
|
1079
|
+
// extensions/sms/src/status.ts
|
|
1125
1080
|
const TWILIO_ERROR_WEBHOOK_REACHABILITY = "11200";
|
|
1126
1081
|
function resolveRemoteProbeTimeoutMs(timeoutMs) {
|
|
1127
1082
|
const normalized = Math.max(1, Math.floor(timeoutMs));
|
|
1128
1083
|
const settleMarginMs = Math.min(100, Math.max(1, Math.floor(normalized / 10)));
|
|
1129
1084
|
return Math.max(0, normalized - settleMarginMs);
|
|
1130
1085
|
}
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
return {
|
|
1134
|
-
kind: "value",
|
|
1135
|
-
value: await withTimeout(Promise.resolve().then(params.run), params.timeoutMs, { message: `timed out after ${params.timeoutMs}ms` })
|
|
1136
|
-
};
|
|
1137
|
-
} catch (error) {
|
|
1138
|
-
return {
|
|
1139
|
-
kind: "error",
|
|
1140
|
-
error: `${params.label} failed: ${formatErrorMessage(error)}`
|
|
1141
|
-
};
|
|
1142
|
-
}
|
|
1086
|
+
function formatRemoteProbeFailure(label, error, timeoutMs) {
|
|
1087
|
+
return `${label} failed: ${error instanceof Error && error.name === "TimeoutError" ? `timed out after ${timeoutMs}ms` : formatErrorMessage(error)}`;
|
|
1143
1088
|
}
|
|
1144
1089
|
function addTailscaleHint(account, hints) {
|
|
1145
1090
|
if (!(URL.parse(account.publicWebhookUrl)?.hostname)?.endsWith(".ts.net")) return;
|
|
1146
1091
|
hints.push(`Tailscale Funnel must expose the exact SMS path: tailscale funnel --bg --set-path ${account.webhookPath} http://127.0.0.1:<gateway-port>${account.webhookPath}`);
|
|
1147
1092
|
}
|
|
1093
|
+
function compareWebhook(summary, url, prefix) {
|
|
1094
|
+
if (!url) return {
|
|
1095
|
+
status: `${prefix}missing`,
|
|
1096
|
+
...summary
|
|
1097
|
+
};
|
|
1098
|
+
const configured = {
|
|
1099
|
+
...summary,
|
|
1100
|
+
configuredUrl: url
|
|
1101
|
+
};
|
|
1102
|
+
if (summary.configuredMethod && summary.configuredMethod !== "POST") return {
|
|
1103
|
+
status: `${prefix}method-mismatch`,
|
|
1104
|
+
...configured
|
|
1105
|
+
};
|
|
1106
|
+
if (url !== summary.expectedUrl) return {
|
|
1107
|
+
status: `${prefix}url-mismatch`,
|
|
1108
|
+
...configured
|
|
1109
|
+
};
|
|
1110
|
+
return {
|
|
1111
|
+
status: `${prefix}matches`,
|
|
1112
|
+
...configured
|
|
1113
|
+
};
|
|
1114
|
+
}
|
|
1148
1115
|
function compareTwilioWebhook(account, phoneNumber) {
|
|
1149
1116
|
if (!account.fromNumber) return {
|
|
1150
1117
|
status: "skipped",
|
|
@@ -1154,63 +1121,26 @@ function compareTwilioWebhook(account, phoneNumber) {
|
|
|
1154
1121
|
status: "number-not-found",
|
|
1155
1122
|
expectedNumber: account.fromNumber
|
|
1156
1123
|
};
|
|
1157
|
-
const
|
|
1124
|
+
const probe = compareWebhook({
|
|
1158
1125
|
phoneNumber: phoneNumber.phoneNumber || account.fromNumber,
|
|
1159
1126
|
expectedUrl: account.publicWebhookUrl,
|
|
1160
1127
|
configuredMethod: phoneNumber.smsMethod.toUpperCase()
|
|
1161
|
-
};
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
...summary
|
|
1165
|
-
};
|
|
1166
|
-
const configured = {
|
|
1167
|
-
...summary,
|
|
1168
|
-
configuredUrl: phoneNumber.smsUrl
|
|
1169
|
-
};
|
|
1170
|
-
if (summary.configuredMethod && summary.configuredMethod !== "POST") return {
|
|
1171
|
-
status: "method-mismatch",
|
|
1172
|
-
...configured
|
|
1173
|
-
};
|
|
1174
|
-
if (phoneNumber.smsUrl !== account.publicWebhookUrl) return {
|
|
1175
|
-
status: "url-mismatch",
|
|
1176
|
-
...configured
|
|
1177
|
-
};
|
|
1178
|
-
return {
|
|
1179
|
-
status: "matches",
|
|
1180
|
-
...configured,
|
|
1128
|
+
}, phoneNumber.smsUrl, "");
|
|
1129
|
+
return probe.status === "matches" ? {
|
|
1130
|
+
...probe,
|
|
1181
1131
|
voiceUrl: phoneNumber.voiceUrl
|
|
1182
|
-
};
|
|
1132
|
+
} : probe;
|
|
1183
1133
|
}
|
|
1184
1134
|
function compareTwilioMessagingService(account, service) {
|
|
1185
1135
|
if (service.useInboundWebhookOnNumber) return {
|
|
1186
1136
|
status: "unavailable",
|
|
1187
1137
|
reason: "Twilio Messaging Service defers inbound webhooks to sender phone numbers; configure fromNumber or disable defer-to-sender before checking."
|
|
1188
1138
|
};
|
|
1189
|
-
|
|
1139
|
+
return compareWebhook({
|
|
1190
1140
|
serviceSid: service.sid || account.messagingServiceSid,
|
|
1191
1141
|
expectedUrl: account.publicWebhookUrl,
|
|
1192
1142
|
configuredMethod: service.inboundMethod.toUpperCase()
|
|
1193
|
-
};
|
|
1194
|
-
if (!service.inboundRequestUrl) return {
|
|
1195
|
-
status: "messaging-service-missing",
|
|
1196
|
-
...summary
|
|
1197
|
-
};
|
|
1198
|
-
const configured = {
|
|
1199
|
-
...summary,
|
|
1200
|
-
configuredUrl: service.inboundRequestUrl
|
|
1201
|
-
};
|
|
1202
|
-
if (summary.configuredMethod && summary.configuredMethod !== "POST") return {
|
|
1203
|
-
status: "messaging-service-method-mismatch",
|
|
1204
|
-
...configured
|
|
1205
|
-
};
|
|
1206
|
-
if (service.inboundRequestUrl !== account.publicWebhookUrl) return {
|
|
1207
|
-
status: "messaging-service-url-mismatch",
|
|
1208
|
-
...configured
|
|
1209
|
-
};
|
|
1210
|
-
return {
|
|
1211
|
-
status: "messaging-service-matches",
|
|
1212
|
-
...configured
|
|
1213
|
-
};
|
|
1143
|
+
}, service.inboundRequestUrl, "messaging-service-");
|
|
1214
1144
|
}
|
|
1215
1145
|
function recentInboundSummary(messages) {
|
|
1216
1146
|
const message = messages[0];
|
|
@@ -1265,45 +1195,29 @@ async function probeSmsAccount(params) {
|
|
|
1265
1195
|
else {
|
|
1266
1196
|
const requestOptions = () => ({
|
|
1267
1197
|
account: params.account,
|
|
1268
|
-
fetchImpl: params.options?.fetchImpl,
|
|
1269
1198
|
timeoutMs: remoteTimeoutMs
|
|
1270
1199
|
});
|
|
1271
|
-
const webhookTask = params.account.fromNumber
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
}))
|
|
1281
|
-
}) : Promise.resolve({
|
|
1282
|
-
kind: "value",
|
|
1283
|
-
value: {
|
|
1284
|
-
status: "unavailable",
|
|
1285
|
-
reason: "Twilio SMS check requires fromNumber or messagingServiceSid."
|
|
1286
|
-
}
|
|
1287
|
-
});
|
|
1288
|
-
const messageTask = params.account.fromNumber ? runRemoteProbe({
|
|
1289
|
-
label: "Twilio message history check",
|
|
1290
|
-
timeoutMs: remoteTimeoutMs,
|
|
1291
|
-
run: async () => await listTwilioMessages({
|
|
1292
|
-
...requestOptions(),
|
|
1293
|
-
to: params.account.fromNumber,
|
|
1294
|
-
pageSize: 3
|
|
1295
|
-
})
|
|
1296
|
-
}) : Promise.resolve({
|
|
1297
|
-
kind: "value",
|
|
1298
|
-
value: []
|
|
1200
|
+
const webhookTask = params.account.fromNumber ? listTwilioIncomingPhoneNumbers({
|
|
1201
|
+
...requestOptions(),
|
|
1202
|
+
phoneNumber: params.account.fromNumber
|
|
1203
|
+
}).then(([number]) => compareTwilioWebhook(params.account, number)) : params.account.messagingServiceSid ? retrieveTwilioMessagingService({
|
|
1204
|
+
...requestOptions(),
|
|
1205
|
+
serviceSid: params.account.messagingServiceSid
|
|
1206
|
+
}).then((service) => compareTwilioMessagingService(params.account, service)) : Promise.resolve({
|
|
1207
|
+
status: "unavailable",
|
|
1208
|
+
reason: "Twilio SMS check requires fromNumber or messagingServiceSid."
|
|
1299
1209
|
});
|
|
1300
|
-
const
|
|
1301
|
-
|
|
1210
|
+
const messageTask = params.account.fromNumber ? listTwilioMessages({
|
|
1211
|
+
...requestOptions(),
|
|
1212
|
+
to: params.account.fromNumber
|
|
1213
|
+
}) : Promise.resolve([]);
|
|
1214
|
+
const [webhookOutcome, messageOutcome] = await Promise.allSettled([webhookTask, messageTask]);
|
|
1215
|
+
webhook = webhookOutcome.status === "fulfilled" ? webhookOutcome.value : {
|
|
1302
1216
|
status: "unavailable",
|
|
1303
|
-
reason: webhookOutcome.
|
|
1217
|
+
reason: formatRemoteProbeFailure("Twilio webhook check", webhookOutcome.reason, remoteTimeoutMs)
|
|
1304
1218
|
};
|
|
1305
|
-
if (messageOutcome.
|
|
1306
|
-
else messageHistoryError = messageOutcome.
|
|
1219
|
+
if (messageOutcome.status === "fulfilled") messages = messageOutcome.value;
|
|
1220
|
+
else messageHistoryError = formatRemoteProbeFailure("Twilio message history check", messageOutcome.reason, remoteTimeoutMs);
|
|
1307
1221
|
}
|
|
1308
1222
|
const recentInbound = recentInboundSummary(messages);
|
|
1309
1223
|
if (recentInbound?.errorCode === TWILIO_ERROR_WEBHOOK_REACHABILITY) hints.push("Twilio error 11200 means Twilio could not reach the SMS webhook. Check the public URL, tunnel/Funnel route, and Twilio Messaging webhook method.");
|
|
@@ -1360,8 +1274,7 @@ function formatSmsProbeLines(probe) {
|
|
|
1360
1274
|
});
|
|
1361
1275
|
return lines;
|
|
1362
1276
|
}
|
|
1363
|
-
|
|
1364
|
-
//#region extensions/sms/src/channel.ts
|
|
1277
|
+
// extensions/sms/src/channel.ts
|
|
1365
1278
|
const CHANNEL_ID = "sms";
|
|
1366
1279
|
const smsConfigAdapter = createHybridChannelConfigAdapter({
|
|
1367
1280
|
sectionKey: CHANNEL_ID,
|
|
@@ -1402,45 +1315,6 @@ const collectSmsOpenDmFindings = createConditionalWarningCollector.findings({
|
|
|
1402
1315
|
severity: "critical",
|
|
1403
1316
|
title: "SMS security warning"
|
|
1404
1317
|
});
|
|
1405
|
-
function applySmsAccountConfig(params) {
|
|
1406
|
-
const patch = {};
|
|
1407
|
-
for (const key of [
|
|
1408
|
-
"accountSid",
|
|
1409
|
-
"authToken",
|
|
1410
|
-
"fromNumber",
|
|
1411
|
-
"messagingServiceSid",
|
|
1412
|
-
"defaultTo",
|
|
1413
|
-
"webhookPath",
|
|
1414
|
-
"publicWebhookUrl",
|
|
1415
|
-
"dmPolicy",
|
|
1416
|
-
"allowFrom"
|
|
1417
|
-
]) if (params.input[key] !== void 0) patch[key] = params.input[key];
|
|
1418
|
-
const channels = { ...params.cfg.channels };
|
|
1419
|
-
const current = { ...channels[CHANNEL_ID] };
|
|
1420
|
-
if (params.accountId === DEFAULT_ACCOUNT_ID) {
|
|
1421
|
-
channels[CHANNEL_ID] = {
|
|
1422
|
-
...current,
|
|
1423
|
-
...patch
|
|
1424
|
-
};
|
|
1425
|
-
return {
|
|
1426
|
-
...params.cfg,
|
|
1427
|
-
channels
|
|
1428
|
-
};
|
|
1429
|
-
}
|
|
1430
|
-
const accounts = { ...current.accounts };
|
|
1431
|
-
accounts[params.accountId] = {
|
|
1432
|
-
...accounts[params.accountId],
|
|
1433
|
-
...patch
|
|
1434
|
-
};
|
|
1435
|
-
channels[CHANNEL_ID] = {
|
|
1436
|
-
...current,
|
|
1437
|
-
accounts
|
|
1438
|
-
};
|
|
1439
|
-
return {
|
|
1440
|
-
...params.cfg,
|
|
1441
|
-
channels
|
|
1442
|
-
};
|
|
1443
|
-
}
|
|
1444
1318
|
const smsSetupContract = defineChannelSetupContract({
|
|
1445
1319
|
fields: {
|
|
1446
1320
|
accountSid: {
|
|
@@ -1515,11 +1389,46 @@ const smsSetupContract = defineChannelSetupContract({
|
|
|
1515
1389
|
}
|
|
1516
1390
|
}
|
|
1517
1391
|
},
|
|
1518
|
-
adapter: { applyAccountConfig:
|
|
1392
|
+
adapter: { applyAccountConfig: (params) => {
|
|
1393
|
+
const patch = {};
|
|
1394
|
+
for (const key of [
|
|
1395
|
+
"accountSid",
|
|
1396
|
+
"authToken",
|
|
1397
|
+
"fromNumber",
|
|
1398
|
+
"messagingServiceSid",
|
|
1399
|
+
"defaultTo",
|
|
1400
|
+
"webhookPath",
|
|
1401
|
+
"publicWebhookUrl",
|
|
1402
|
+
"dmPolicy",
|
|
1403
|
+
"allowFrom"
|
|
1404
|
+
]) if (params.input[key] !== void 0) patch[key] = params.input[key];
|
|
1405
|
+
const channels = { ...params.cfg.channels };
|
|
1406
|
+
const current = { ...channels[CHANNEL_ID] };
|
|
1407
|
+
if (params.accountId === DEFAULT_ACCOUNT_ID) {
|
|
1408
|
+
channels[CHANNEL_ID] = {
|
|
1409
|
+
...current,
|
|
1410
|
+
...patch
|
|
1411
|
+
};
|
|
1412
|
+
return {
|
|
1413
|
+
...params.cfg,
|
|
1414
|
+
channels
|
|
1415
|
+
};
|
|
1416
|
+
}
|
|
1417
|
+
const accounts = { ...current.accounts };
|
|
1418
|
+
accounts[params.accountId] = {
|
|
1419
|
+
...accounts[params.accountId],
|
|
1420
|
+
...patch
|
|
1421
|
+
};
|
|
1422
|
+
channels[CHANNEL_ID] = {
|
|
1423
|
+
...current,
|
|
1424
|
+
accounts
|
|
1425
|
+
};
|
|
1426
|
+
return {
|
|
1427
|
+
...params.cfg,
|
|
1428
|
+
channels
|
|
1429
|
+
};
|
|
1430
|
+
} }
|
|
1519
1431
|
});
|
|
1520
|
-
function resolveSmsTextChunkLimit(params) {
|
|
1521
|
-
return resolveSmsAccount(params.cfg, params.accountId).textChunkLimit || params.fallbackLimit || 1500;
|
|
1522
|
-
}
|
|
1523
1432
|
async function sendSmsText(ctx) {
|
|
1524
1433
|
const account = resolveSmsAccount(ctx.cfg, ctx.accountId);
|
|
1525
1434
|
const to = normalizeSmsPhoneNumber(ctx.to) || account.defaultTo;
|
|
@@ -1606,24 +1515,6 @@ const smsMessageAdapter = defineChannelMessageAdapter({
|
|
|
1606
1515
|
media: sendPreparedSmsAttachment
|
|
1607
1516
|
}
|
|
1608
1517
|
});
|
|
1609
|
-
function resolveSmsOutboundSessionRoute(params) {
|
|
1610
|
-
const to = normalizeSmsPhoneNumber(params.resolvedTarget?.to ?? params.target);
|
|
1611
|
-
if (!looksLikeSmsPhoneNumber(to)) return null;
|
|
1612
|
-
return buildChannelOutboundSessionRoute({
|
|
1613
|
-
cfg: params.cfg,
|
|
1614
|
-
agentId: params.agentId,
|
|
1615
|
-
channel: CHANNEL_ID,
|
|
1616
|
-
accountId: params.accountId,
|
|
1617
|
-
recipientSessionExact: true,
|
|
1618
|
-
peer: {
|
|
1619
|
-
kind: "direct",
|
|
1620
|
-
id: to
|
|
1621
|
-
},
|
|
1622
|
-
chatType: "direct",
|
|
1623
|
-
from: `sms:${to}`,
|
|
1624
|
-
to: `sms:${to}`
|
|
1625
|
-
});
|
|
1626
|
-
}
|
|
1627
1518
|
const smsPlugin = createChatChannelPlugin({
|
|
1628
1519
|
base: {
|
|
1629
1520
|
id: CHANNEL_ID,
|
|
@@ -1667,7 +1558,24 @@ const smsPlugin = createChatChannelPlugin({
|
|
|
1667
1558
|
targetPrefixes: ["twilio-sms"],
|
|
1668
1559
|
normalizeTarget: normalizeSmsPhoneNumber,
|
|
1669
1560
|
inferTargetChatType: ({ to }) => looksLikeSmsPhoneNumber(to) ? "direct" : void 0,
|
|
1670
|
-
resolveOutboundSessionRoute:
|
|
1561
|
+
resolveOutboundSessionRoute: (params) => {
|
|
1562
|
+
const to = normalizeSmsPhoneNumber(params.resolvedTarget?.to ?? params.target);
|
|
1563
|
+
if (!looksLikeSmsPhoneNumber(to)) return null;
|
|
1564
|
+
return buildChannelOutboundSessionRoute({
|
|
1565
|
+
cfg: params.cfg,
|
|
1566
|
+
agentId: params.agentId,
|
|
1567
|
+
channel: CHANNEL_ID,
|
|
1568
|
+
accountId: params.accountId,
|
|
1569
|
+
recipientSessionExact: true,
|
|
1570
|
+
peer: {
|
|
1571
|
+
kind: "direct",
|
|
1572
|
+
id: to
|
|
1573
|
+
},
|
|
1574
|
+
chatType: "direct",
|
|
1575
|
+
from: `sms:${to}`,
|
|
1576
|
+
to: `sms:${to}`
|
|
1577
|
+
});
|
|
1578
|
+
},
|
|
1671
1579
|
targetResolver: {
|
|
1672
1580
|
looksLikeId: looksLikeSmsPhoneNumber,
|
|
1673
1581
|
hint: "<+15551234567>"
|
|
@@ -1683,7 +1591,7 @@ const smsPlugin = createChatChannelPlugin({
|
|
|
1683
1591
|
accountId: ctx.account.accountId,
|
|
1684
1592
|
setStatus: ctx.setStatus
|
|
1685
1593
|
});
|
|
1686
|
-
|
|
1594
|
+
await startSmsGatewayAccount({
|
|
1687
1595
|
cfg: ctx.cfg,
|
|
1688
1596
|
account: ctx.account,
|
|
1689
1597
|
channelRuntime: ctx.channelRuntime,
|
|
@@ -1752,7 +1660,7 @@ const smsPlugin = createChatChannelPlugin({
|
|
|
1752
1660
|
chunker: chunkTextForOutbound,
|
|
1753
1661
|
chunkerMode: "text",
|
|
1754
1662
|
textChunkLimit: 1500,
|
|
1755
|
-
resolveEffectiveTextChunkLimit:
|
|
1663
|
+
resolveEffectiveTextChunkLimit: ({ cfg, accountId }) => resolveSmsAccount(cfg, accountId).textChunkLimit,
|
|
1756
1664
|
resolveTarget: ({ cfg, to, accountId }) => {
|
|
1757
1665
|
const explicit = normalizeSmsPhoneNumber(to ?? "");
|
|
1758
1666
|
if (explicit) return {
|
|
@@ -1775,5 +1683,4 @@ const smsPlugin = createChatChannelPlugin({
|
|
|
1775
1683
|
sendText: sendSmsText
|
|
1776
1684
|
}
|
|
1777
1685
|
});
|
|
1778
|
-
//#endregion
|
|
1779
1686
|
export { smsPlugin };
|