@openclaw/sms 2026.10.1 → 2026.10.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-fLUYh_H2.mjs → media-q2rqllHl.mjs} +1 -1
- package/dist/.setup/{secret-contract-BEWVid4f.mjs → secret-contract-B2P_lFGm.mjs} +4 -6
- package/dist/.setup/{twilio-DLNDolQb.mjs → twilio-DoiIsgd_.mjs} +71 -88
- package/dist/channel-plugin-api.js +66 -96
- package/dist/secret-contract-api.js +1 -1
- package/package.json +4 -4
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as getSmsRuntime } from "./runtime-BBlPgBIF.mjs";
|
|
2
|
-
import { h as assertSmsCredentialOwnerAvailable, n as TWILIO_MMS_MAX_BYTES } from "./twilio-
|
|
2
|
+
import { h as assertSmsCredentialOwnerAvailable, n as TWILIO_MMS_MAX_BYTES } from "./twilio-DoiIsgd_.mjs";
|
|
3
3
|
import { collectErrorGraphCandidates } from "openclaw/plugin-sdk/error-runtime";
|
|
4
4
|
import { resolveExpiresAtMsFromDurationMs } from "openclaw/plugin-sdk/number-runtime";
|
|
5
5
|
import { createHash } from "node:crypto";
|
|
@@ -2,23 +2,21 @@ import { collectConditionalChannelFieldAssignments, createChannelSecretContract,
|
|
|
2
2
|
//#region extensions/sms/src/secret-contract.ts
|
|
3
3
|
const DEFAULT_ACCOUNT_ID = "default";
|
|
4
4
|
function hasTopLevelSmsAccount(channel) {
|
|
5
|
-
|
|
5
|
+
return [
|
|
6
6
|
"accountSid",
|
|
7
7
|
"fromNumber",
|
|
8
8
|
"messagingServiceSid",
|
|
9
9
|
"defaultTo"
|
|
10
|
-
])
|
|
11
|
-
return false;
|
|
10
|
+
].some((field) => typeof channel[field] === "string" && channel[field].trim().length > 0);
|
|
12
11
|
}
|
|
13
12
|
function hasEnvBackedDefaultSmsAccount(env) {
|
|
14
|
-
|
|
13
|
+
return [
|
|
15
14
|
"TWILIO_ACCOUNT_SID",
|
|
16
15
|
"TWILIO_AUTH_TOKEN",
|
|
17
16
|
"TWILIO_PHONE_NUMBER",
|
|
18
17
|
"TWILIO_SMS_FROM",
|
|
19
18
|
"TWILIO_MESSAGING_SERVICE_SID"
|
|
20
|
-
])
|
|
21
|
-
return false;
|
|
19
|
+
].some((name) => typeof env[name] === "string" && env[name].trim().length > 0);
|
|
22
20
|
}
|
|
23
21
|
const channelSecrets = createChannelSecretContract({
|
|
24
22
|
channelKey: "sms",
|
|
@@ -9,6 +9,7 @@ import { isIP } from "node:net";
|
|
|
9
9
|
import { fetchWithSsrFGuard, isBlockedHostnameOrIp } from "openclaw/plugin-sdk/ssrf-runtime";
|
|
10
10
|
import { createHmac } from "node:crypto";
|
|
11
11
|
import * as querystring from "node:querystring";
|
|
12
|
+
import { captureEffectAuthority } from "openclaw/plugin-sdk/fetch-runtime";
|
|
12
13
|
import { redactToolPayloadText } from "openclaw/plugin-sdk/logging-core";
|
|
13
14
|
import { readResponseTextPrefix, readResponseWithLimit } from "openclaw/plugin-sdk/response-limit-runtime";
|
|
14
15
|
import { safeEqualSecret } from "openclaw/plugin-sdk/security-runtime";
|
|
@@ -28,7 +29,7 @@ function looksLikeSmsPhoneNumber(raw) {
|
|
|
28
29
|
}
|
|
29
30
|
function normalizeSmsAllowFrom(raw) {
|
|
30
31
|
if (raw.trim() === "*") return "*";
|
|
31
|
-
return normalizeSmsPhoneNumber(raw)
|
|
32
|
+
return normalizeSmsPhoneNumber(raw);
|
|
32
33
|
}
|
|
33
34
|
//#endregion
|
|
34
35
|
//#region extensions/sms/src/public-webhook-url.ts
|
|
@@ -63,13 +64,8 @@ function hasValidHostname(url) {
|
|
|
63
64
|
function parseSmsPublicWebhookUrl(value) {
|
|
64
65
|
const trimmed = value.trim();
|
|
65
66
|
if (!ABSOLUTE_HTTP_URL_PATTERN.test(trimmed) || !hasSafeRawUrlCharacters(trimmed) || INVALID_PERCENT_ESCAPE_PATTERN.test(trimmed) || hasForbiddenRawUrlCharacter(trimmed)) return;
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
url = new URL(trimmed);
|
|
69
|
-
} catch {
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
if (url.protocol !== "http:" && url.protocol !== "https:" || url.username || url.password || !hasValidHostname(url)) return;
|
|
67
|
+
const url = URL.parse(trimmed);
|
|
68
|
+
if (!url || url.protocol !== "http:" && url.protocol !== "https:" || url.username || url.password || !hasValidHostname(url)) return;
|
|
73
69
|
return url;
|
|
74
70
|
}
|
|
75
71
|
function parseTwilioRetryPolicies(overrides) {
|
|
@@ -252,27 +248,23 @@ function parseTwilioApiError(text) {
|
|
|
252
248
|
}
|
|
253
249
|
function parseTwilioSuccessPayload(text) {
|
|
254
250
|
if (!text.trim()) return {};
|
|
251
|
+
let parsed;
|
|
255
252
|
try {
|
|
256
|
-
|
|
257
|
-
if (!parsed || typeof parsed !== "object") throw new Error("Twilio SMS send returned malformed JSON.");
|
|
258
|
-
const record = parsed;
|
|
259
|
-
return {
|
|
260
|
-
sid: typeof record.sid === "string" ? record.sid : void 0,
|
|
261
|
-
to: typeof record.to === "string" ? record.to : void 0,
|
|
262
|
-
from: typeof record.from === "string" ? record.from : void 0,
|
|
263
|
-
status: typeof record.status === "string" ? record.status : void 0
|
|
264
|
-
};
|
|
253
|
+
parsed = JSON.parse(text);
|
|
265
254
|
} catch (cause) {
|
|
266
|
-
if (cause instanceof Error && cause.message === "Twilio SMS send returned malformed JSON.") throw cause;
|
|
267
255
|
throw new Error("Twilio SMS send returned malformed JSON.", { cause });
|
|
268
256
|
}
|
|
257
|
+
if (!parsed || typeof parsed !== "object") throw new Error("Twilio SMS send returned malformed JSON.");
|
|
258
|
+
const record = parsed;
|
|
259
|
+
return {
|
|
260
|
+
sid: typeof record.sid === "string" ? record.sid : void 0,
|
|
261
|
+
to: typeof record.to === "string" ? record.to : void 0,
|
|
262
|
+
from: typeof record.from === "string" ? record.from : void 0,
|
|
263
|
+
status: typeof record.status === "string" ? record.status : void 0
|
|
264
|
+
};
|
|
269
265
|
}
|
|
270
266
|
function requestSearch(req) {
|
|
271
|
-
|
|
272
|
-
return new URL(req.url ?? "/", "http://localhost").search;
|
|
273
|
-
} catch {
|
|
274
|
-
return "";
|
|
275
|
-
}
|
|
267
|
+
return URL.parse(req.url ?? "/", "http://localhost")?.search ?? "";
|
|
276
268
|
}
|
|
277
269
|
function stripUrlFragment(url) {
|
|
278
270
|
const hashIndex = url.indexOf("#");
|
|
@@ -379,18 +371,6 @@ function respondTwiml(res, statusCode, body = "") {
|
|
|
379
371
|
res.setHeader("content-type", TWIML_CONTENT_TYPE);
|
|
380
372
|
res.end(body || "<Response></Response>");
|
|
381
373
|
}
|
|
382
|
-
function twilioApiUrl(accountSid, path, query) {
|
|
383
|
-
const normalizedPath = path.startsWith("/") ? path : `/${path}`;
|
|
384
|
-
const url = new URL(`${TWILIO_ACCOUNTS_URL}/${encodeURIComponent(accountSid)}${normalizedPath}`);
|
|
385
|
-
if (query) url.search = query.toString();
|
|
386
|
-
return url.toString();
|
|
387
|
-
}
|
|
388
|
-
function twilioMessagingUrl(path, query) {
|
|
389
|
-
const normalizedPath = path.startsWith("/") ? path : `/${path}`;
|
|
390
|
-
const url = new URL(`${TWILIO_MESSAGING_URL}${normalizedPath}`);
|
|
391
|
-
if (query) url.search = query.toString();
|
|
392
|
-
return url.toString();
|
|
393
|
-
}
|
|
394
374
|
function basicAuthHeader(account) {
|
|
395
375
|
return `Basic ${Buffer.from(`${account.accountSid}:${account.authToken}`).toString("base64")}`;
|
|
396
376
|
}
|
|
@@ -414,6 +394,9 @@ function assertTwilioRequestCredentialsAvailable(account) {
|
|
|
414
394
|
}
|
|
415
395
|
}
|
|
416
396
|
async function requestTwilioApi(params) {
|
|
397
|
+
const baseUrl = params.api === "accounts" ? `${TWILIO_ACCOUNTS_URL}/${encodeURIComponent(params.account.accountSid)}` : TWILIO_MESSAGING_URL;
|
|
398
|
+
const url = new URL(`${baseUrl}${params.path}`);
|
|
399
|
+
if (params.query) url.search = params.query.toString();
|
|
417
400
|
const init = {
|
|
418
401
|
...params.init,
|
|
419
402
|
headers: {
|
|
@@ -421,41 +404,43 @@ async function requestTwilioApi(params) {
|
|
|
421
404
|
authorization: basicAuthHeader(params.account)
|
|
422
405
|
}
|
|
423
406
|
};
|
|
424
|
-
|
|
407
|
+
let response;
|
|
408
|
+
let release;
|
|
409
|
+
const fetchImpl = params.fetchImpl;
|
|
410
|
+
if (fetchImpl) response = await captureEffectAuthority().initiate(() => {
|
|
425
411
|
assertTwilioRequestCredentialsAvailable(params.account);
|
|
426
|
-
|
|
427
|
-
return {
|
|
428
|
-
ok: response.ok,
|
|
429
|
-
status: response.status,
|
|
430
|
-
text: await readTwilioApiResponseText(response)
|
|
431
|
-
};
|
|
432
|
-
}
|
|
433
|
-
let requestDispatched = false;
|
|
434
|
-
const guarded = await fetchWithSsrFGuard({
|
|
435
|
-
url: params.url,
|
|
436
|
-
init,
|
|
437
|
-
beforeRequest: () => {
|
|
438
|
-
if (requestDispatched) {
|
|
439
|
-
assertSmsCredentialOwnerAvailable(params.account);
|
|
440
|
-
return;
|
|
441
|
-
}
|
|
442
|
-
assertTwilioRequestCredentialsAvailable(params.account);
|
|
443
|
-
requestDispatched = true;
|
|
444
|
-
},
|
|
445
|
-
auditContext: "sms-twilio-api",
|
|
446
|
-
policy: { allowedHostnames: [params.allowedHostname] },
|
|
447
|
-
requireHttps: true,
|
|
448
|
-
timeoutMs: params.timeoutMs ?? TWILIO_API_TIMEOUT_MS
|
|
412
|
+
return fetchImpl(url.toString(), init);
|
|
449
413
|
});
|
|
414
|
+
else {
|
|
415
|
+
let requestDispatched = false;
|
|
416
|
+
({response, release} = await fetchWithSsrFGuard({
|
|
417
|
+
url: url.toString(),
|
|
418
|
+
init,
|
|
419
|
+
beforeRequest: () => {
|
|
420
|
+
if (requestDispatched) {
|
|
421
|
+
assertSmsCredentialOwnerAvailable(params.account);
|
|
422
|
+
return;
|
|
423
|
+
}
|
|
424
|
+
assertTwilioRequestCredentialsAvailable(params.account);
|
|
425
|
+
requestDispatched = true;
|
|
426
|
+
},
|
|
427
|
+
auditContext: "sms-twilio-api",
|
|
428
|
+
policy: { allowedHostnames: [params.api === "accounts" ? TWILIO_API_HOSTNAME : TWILIO_MESSAGING_HOSTNAME] },
|
|
429
|
+
requireHttps: true,
|
|
430
|
+
timeoutMs: params.timeoutMs ?? TWILIO_API_TIMEOUT_MS
|
|
431
|
+
}));
|
|
432
|
+
}
|
|
433
|
+
let ok;
|
|
434
|
+
let status;
|
|
435
|
+
let text;
|
|
450
436
|
try {
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
status: guarded.response.status,
|
|
454
|
-
text: await readTwilioApiResponseText(guarded.response)
|
|
455
|
-
};
|
|
437
|
+
({ok, status} = response);
|
|
438
|
+
text = await readTwilioApiResponseText(response);
|
|
456
439
|
} finally {
|
|
457
|
-
await
|
|
440
|
+
if (release) await release();
|
|
458
441
|
}
|
|
442
|
+
if (!ok) throw new TwilioSmsApiError(status, text, params.operation);
|
|
443
|
+
return text;
|
|
459
444
|
}
|
|
460
445
|
function parseTwilioIncomingPhoneNumber(record) {
|
|
461
446
|
return {
|
|
@@ -495,26 +480,26 @@ function parseTwilioListPayload(text, key, parseEntry) {
|
|
|
495
480
|
async function listTwilioIncomingPhoneNumbers(params) {
|
|
496
481
|
const query = new URLSearchParams();
|
|
497
482
|
if (params.phoneNumber) query.set("PhoneNumber", params.phoneNumber);
|
|
498
|
-
|
|
483
|
+
return parseTwilioListPayload(await requestTwilioApi({
|
|
499
484
|
account: params.account,
|
|
500
|
-
|
|
501
|
-
|
|
485
|
+
path: "/IncomingPhoneNumbers.json",
|
|
486
|
+
api: "accounts",
|
|
487
|
+
query,
|
|
488
|
+
operation: "phone-number lookup",
|
|
502
489
|
fetchImpl: params.fetchImpl,
|
|
503
490
|
timeoutMs: params.timeoutMs
|
|
504
|
-
});
|
|
505
|
-
if (!response.ok) throw new TwilioSmsApiError(response.status, response.text, "phone-number lookup");
|
|
506
|
-
return parseTwilioListPayload(response.text, "incoming_phone_numbers", parseTwilioIncomingPhoneNumber);
|
|
491
|
+
}), "incoming_phone_numbers", parseTwilioIncomingPhoneNumber);
|
|
507
492
|
}
|
|
508
493
|
async function retrieveTwilioMessagingService(params) {
|
|
509
|
-
const
|
|
494
|
+
const text = await requestTwilioApi({
|
|
510
495
|
account: params.account,
|
|
511
|
-
|
|
512
|
-
|
|
496
|
+
path: `/Services/${encodeURIComponent(params.serviceSid)}`,
|
|
497
|
+
api: "messaging",
|
|
498
|
+
operation: "messaging-service lookup",
|
|
513
499
|
fetchImpl: params.fetchImpl,
|
|
514
500
|
timeoutMs: params.timeoutMs
|
|
515
501
|
});
|
|
516
|
-
|
|
517
|
-
const parsed = safeParseJson(response.text);
|
|
502
|
+
const parsed = safeParseJson(text);
|
|
518
503
|
if (!isRecord(parsed)) throw new Error("Twilio Messaging Service lookup returned malformed JSON.");
|
|
519
504
|
return parseTwilioMessagingService(parsed);
|
|
520
505
|
}
|
|
@@ -523,15 +508,15 @@ async function listTwilioMessages(params) {
|
|
|
523
508
|
if (params.to) query.set("To", params.to);
|
|
524
509
|
if (params.from) query.set("From", params.from);
|
|
525
510
|
query.set("PageSize", String(params.pageSize ?? 5));
|
|
526
|
-
|
|
511
|
+
return parseTwilioListPayload(await requestTwilioApi({
|
|
527
512
|
account: params.account,
|
|
528
|
-
|
|
529
|
-
|
|
513
|
+
path: "/Messages.json",
|
|
514
|
+
api: "accounts",
|
|
515
|
+
query,
|
|
516
|
+
operation: "message lookup",
|
|
530
517
|
fetchImpl: params.fetchImpl,
|
|
531
518
|
timeoutMs: params.timeoutMs
|
|
532
|
-
});
|
|
533
|
-
if (!response.ok) throw new TwilioSmsApiError(response.status, response.text, "message lookup");
|
|
534
|
-
return parseTwilioListPayload(response.text, "messages", parseTwilioMessageLogEntry);
|
|
519
|
+
}), "messages", parseTwilioMessageLogEntry);
|
|
535
520
|
}
|
|
536
521
|
async function sendSmsViaTwilio(params) {
|
|
537
522
|
assertSmsCredentialOwnerAvailable(params.account);
|
|
@@ -553,15 +538,13 @@ async function sendSmsViaTwilio(params) {
|
|
|
553
538
|
body
|
|
554
539
|
};
|
|
555
540
|
await params.onPlatformSendDispatch?.();
|
|
556
|
-
const
|
|
541
|
+
const payload = parseTwilioSuccessPayload(await requestTwilioApi({
|
|
557
542
|
account: params.account,
|
|
558
|
-
|
|
559
|
-
|
|
543
|
+
path: "/Messages.json",
|
|
544
|
+
api: "accounts",
|
|
560
545
|
init,
|
|
561
546
|
fetchImpl: params.fetchImpl
|
|
562
|
-
});
|
|
563
|
-
if (!response.ok) throw new TwilioSmsApiError(response.status, response.text);
|
|
564
|
-
const payload = parseTwilioSuccessPayload(response.text);
|
|
547
|
+
}));
|
|
565
548
|
const sid = payload.sid?.trim();
|
|
566
549
|
if (!sid) throw new Error("Twilio SMS send response did not include a Message SID.");
|
|
567
550
|
return {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as getSmsRuntime } from "./.setup/runtime-BBlPgBIF.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-
|
|
3
|
-
import { n as collectRuntimeConfigAssignments, r as secretTargetRegistryEntries } from "./.setup/secret-contract-
|
|
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-DoiIsgd_.mjs";
|
|
3
|
+
import { n as collectRuntimeConfigAssignments, r as secretTargetRegistryEntries } from "./.setup/secret-contract-B2P_lFGm.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";
|
|
@@ -367,63 +367,21 @@ function toSmsPlainText(text) {
|
|
|
367
367
|
linkStyle: "label-and-url"
|
|
368
368
|
}).replace(/\r\n/g, "\n").replace(/\n{3,}/g, "\n\n").trim();
|
|
369
369
|
}
|
|
370
|
-
function
|
|
370
|
+
function prepareSmsTextChunks(params) {
|
|
371
|
+
const text = toSmsPlainText(params.text);
|
|
372
|
+
if (!text) return [];
|
|
371
373
|
return renderMarkdownIRChunksWithinLimit({
|
|
372
374
|
ir: {
|
|
373
375
|
text,
|
|
374
376
|
styles: [],
|
|
375
377
|
links: []
|
|
376
378
|
},
|
|
377
|
-
limit,
|
|
379
|
+
limit: Math.min(params.configuredLimit, TWILIO_MESSAGE_BODY_MAX_LENGTH),
|
|
378
380
|
assistantTranscriptRoleMessageBoundaries: true,
|
|
379
381
|
renderChunk: (chunk) => chunk.annotations?.some((annotation) => annotation.type === "assistant_transcript_role") ? `${SMS_ASSISTANT_TRANSCRIPT_ROLE_PREFIX}${chunk.text}` : chunk.text,
|
|
380
382
|
measureRendered: (rendered) => rendered.length
|
|
381
383
|
}).map(({ rendered }) => rendered).filter(Boolean);
|
|
382
384
|
}
|
|
383
|
-
function prepareSmsTextChunks(params) {
|
|
384
|
-
const text = toSmsPlainText(params.text);
|
|
385
|
-
if (!text) return [];
|
|
386
|
-
return chunkSmsPlainText(text, Math.min(params.configuredLimit, TWILIO_MESSAGE_BODY_MAX_LENGTH));
|
|
387
|
-
}
|
|
388
|
-
async function sendSmsProviderMessage(params) {
|
|
389
|
-
let platformDispatchStarted = false;
|
|
390
|
-
let result;
|
|
391
|
-
try {
|
|
392
|
-
result = await sendSmsViaTwilio({
|
|
393
|
-
account: params.account,
|
|
394
|
-
to: params.to,
|
|
395
|
-
...params.text !== void 0 ? { text: params.text } : {},
|
|
396
|
-
...params.mediaUrls !== void 0 ? { mediaUrls: params.mediaUrls } : {},
|
|
397
|
-
onPlatformSendDispatch: async () => {
|
|
398
|
-
await params.onPlatformSendDispatch?.();
|
|
399
|
-
platformDispatchStarted = true;
|
|
400
|
-
}
|
|
401
|
-
});
|
|
402
|
-
} catch (error) {
|
|
403
|
-
if (platformDispatchStarted || error instanceof PlatformMessageNotDispatchedError) throw error;
|
|
404
|
-
throw new PlatformMessageNotDispatchedError(`SMS send failed before Twilio dispatch: ${formatErrorMessage(error)}`, { cause: error });
|
|
405
|
-
}
|
|
406
|
-
await recordInitialDeliveryBestEffort(params.account, result);
|
|
407
|
-
return result;
|
|
408
|
-
}
|
|
409
|
-
async function recordInitialDeliveryBestEffort(account, result) {
|
|
410
|
-
try {
|
|
411
|
-
await recordInitialSmsDeliveryResult({
|
|
412
|
-
account,
|
|
413
|
-
result
|
|
414
|
-
});
|
|
415
|
-
} catch (error) {
|
|
416
|
-
try {
|
|
417
|
-
getSmsRuntime().logging.getChildLogger({
|
|
418
|
-
plugin: "sms",
|
|
419
|
-
feature: "delivery-status"
|
|
420
|
-
}).warn("SMS delivery initial state could not be persisted.", {
|
|
421
|
-
messageSid: result.sid,
|
|
422
|
-
errorType: error instanceof Error ? error.name : typeof error
|
|
423
|
-
});
|
|
424
|
-
} catch {}
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
385
|
async function sendSmsTextChunks(params) {
|
|
428
386
|
const chunks = prepareSmsTextChunks({
|
|
429
387
|
text: params.text,
|
|
@@ -436,12 +394,39 @@ async function sendSmsMessages(params, messages, kind) {
|
|
|
436
394
|
const results = [];
|
|
437
395
|
try {
|
|
438
396
|
for (const [index, message] of messages.entries()) {
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
397
|
+
let platformDispatchStarted = false;
|
|
398
|
+
let result;
|
|
399
|
+
try {
|
|
400
|
+
result = await sendSmsViaTwilio({
|
|
401
|
+
account: params.account,
|
|
402
|
+
to: params.to,
|
|
403
|
+
...message.text !== void 0 ? { text: message.text } : {},
|
|
404
|
+
...message.mediaUrls !== void 0 ? { mediaUrls: message.mediaUrls } : {},
|
|
405
|
+
onPlatformSendDispatch: async () => {
|
|
406
|
+
await params.onPlatformSendDispatch?.();
|
|
407
|
+
platformDispatchStarted = true;
|
|
408
|
+
}
|
|
409
|
+
});
|
|
410
|
+
} catch (error) {
|
|
411
|
+
if (platformDispatchStarted || error instanceof PlatformMessageNotDispatchedError) throw error;
|
|
412
|
+
throw new PlatformMessageNotDispatchedError(`SMS send failed before Twilio dispatch: ${formatErrorMessage(error)}`, { cause: error });
|
|
413
|
+
}
|
|
414
|
+
try {
|
|
415
|
+
await recordInitialSmsDeliveryResult({
|
|
416
|
+
account: params.account,
|
|
417
|
+
result
|
|
418
|
+
});
|
|
419
|
+
} catch (error) {
|
|
420
|
+
try {
|
|
421
|
+
getSmsRuntime().logging.getChildLogger({
|
|
422
|
+
plugin: "sms",
|
|
423
|
+
feature: "delivery-status"
|
|
424
|
+
}).warn("SMS delivery initial state could not be persisted.", {
|
|
425
|
+
messageSid: result.sid,
|
|
426
|
+
errorType: error instanceof Error ? error.name : typeof error
|
|
427
|
+
});
|
|
428
|
+
} catch {}
|
|
429
|
+
}
|
|
445
430
|
results.push(result);
|
|
446
431
|
await params.onDeliveryResult?.(createSmsSendResult({
|
|
447
432
|
results: [result],
|
|
@@ -461,7 +446,7 @@ async function prepareSmsMediaAttempt(params) {
|
|
|
461
446
|
});
|
|
462
447
|
let hostedMedia;
|
|
463
448
|
try {
|
|
464
|
-
const { prepareHostedSmsMedia } = await import("./.setup/media-
|
|
449
|
+
const { prepareHostedSmsMedia } = await import("./.setup/media-q2rqllHl.mjs");
|
|
465
450
|
assertSmsCredentialOwnerAvailable(params.account);
|
|
466
451
|
const prepared = await prepareHostedSmsMedia({
|
|
467
452
|
account: params.account,
|
|
@@ -572,7 +557,7 @@ async function dispatchSmsInboundEvent(params) {
|
|
|
572
557
|
params.log?.warn?.(`SMS sender ${from} is not authorized`);
|
|
573
558
|
return;
|
|
574
559
|
}
|
|
575
|
-
const materialized = params.msg.media.length > 0 || (params.msg.unavailableMediaCount ?? 0) > 0 ? await (await import("./.setup/media-
|
|
560
|
+
const materialized = params.msg.media.length > 0 || (params.msg.unavailableMediaCount ?? 0) > 0 ? await (await import("./.setup/media-q2rqllHl.mjs")).materializeSmsInboundMedia({
|
|
576
561
|
account: params.account,
|
|
577
562
|
msg: params.msg,
|
|
578
563
|
mediaRuntime: params.channelRuntime,
|
|
@@ -1075,7 +1060,7 @@ async function registerSmsWebhookRoute(params) {
|
|
|
1075
1060
|
throwOnFailure: true,
|
|
1076
1061
|
log: (msg) => params.log?.info?.(msg),
|
|
1077
1062
|
handler: async (req, res) => {
|
|
1078
|
-
const { tryHandleHostedSmsMediaRequest } = await import("./.setup/media-
|
|
1063
|
+
const { tryHandleHostedSmsMediaRequest } = await import("./.setup/media-q2rqllHl.mjs");
|
|
1079
1064
|
if (await tryHandleHostedSmsMediaRequest(req, res, params.account.accountId)) return true;
|
|
1080
1065
|
return await webhookHandler(req, res);
|
|
1081
1066
|
}
|
|
@@ -1157,13 +1142,7 @@ async function runRemoteProbe(params) {
|
|
|
1157
1142
|
}
|
|
1158
1143
|
}
|
|
1159
1144
|
function addTailscaleHint(account, hints) {
|
|
1160
|
-
|
|
1161
|
-
try {
|
|
1162
|
-
host = new URL(account.publicWebhookUrl).hostname;
|
|
1163
|
-
} catch {
|
|
1164
|
-
return;
|
|
1165
|
-
}
|
|
1166
|
-
if (!host.endsWith(".ts.net")) return;
|
|
1145
|
+
if (!(URL.parse(account.publicWebhookUrl)?.hostname)?.endsWith(".ts.net")) return;
|
|
1167
1146
|
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}`);
|
|
1168
1147
|
}
|
|
1169
1148
|
function compareTwilioWebhook(account, phoneNumber) {
|
|
@@ -1205,7 +1184,7 @@ function compareTwilioWebhook(account, phoneNumber) {
|
|
|
1205
1184
|
function compareTwilioMessagingService(account, service) {
|
|
1206
1185
|
if (service.useInboundWebhookOnNumber) return {
|
|
1207
1186
|
status: "unavailable",
|
|
1208
|
-
reason: "Twilio Messaging Service defers inbound webhooks to sender phone numbers; configure fromNumber or disable defer-to-sender before
|
|
1187
|
+
reason: "Twilio Messaging Service defers inbound webhooks to sender phone numbers; configure fromNumber or disable defer-to-sender before checking."
|
|
1209
1188
|
};
|
|
1210
1189
|
const summary = {
|
|
1211
1190
|
serviceSid: service.sid || account.messagingServiceSid,
|
|
@@ -1281,43 +1260,38 @@ async function probeSmsAccount(params) {
|
|
|
1281
1260
|
let messages = [];
|
|
1282
1261
|
if (remoteTimeoutMs === 0) webhook = {
|
|
1283
1262
|
status: "unavailable",
|
|
1284
|
-
reason: "Twilio webhook
|
|
1263
|
+
reason: "Twilio webhook check skipped because the check timeout is too short."
|
|
1285
1264
|
};
|
|
1286
1265
|
else {
|
|
1287
|
-
const
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
timeoutMs: remoteTimeoutMs
|
|
1295
|
-
}))[0])
|
|
1296
|
-
}) : params.account.messagingServiceSid ? runRemoteProbe({
|
|
1297
|
-
label: "Twilio webhook probe",
|
|
1266
|
+
const requestOptions = () => ({
|
|
1267
|
+
account: params.account,
|
|
1268
|
+
fetchImpl: params.options?.fetchImpl,
|
|
1269
|
+
timeoutMs: remoteTimeoutMs
|
|
1270
|
+
});
|
|
1271
|
+
const webhookTask = params.account.fromNumber || params.account.messagingServiceSid ? runRemoteProbe({
|
|
1272
|
+
label: "Twilio webhook check",
|
|
1298
1273
|
timeoutMs: remoteTimeoutMs,
|
|
1299
|
-
run: async () =>
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1274
|
+
run: params.account.fromNumber ? async () => compareTwilioWebhook(params.account, (await listTwilioIncomingPhoneNumbers({
|
|
1275
|
+
...requestOptions(),
|
|
1276
|
+
phoneNumber: params.account.fromNumber
|
|
1277
|
+
}))[0]) : async () => compareTwilioMessagingService(params.account, await retrieveTwilioMessagingService({
|
|
1278
|
+
...requestOptions(),
|
|
1279
|
+
serviceSid: params.account.messagingServiceSid
|
|
1304
1280
|
}))
|
|
1305
1281
|
}) : Promise.resolve({
|
|
1306
1282
|
kind: "value",
|
|
1307
1283
|
value: {
|
|
1308
1284
|
status: "unavailable",
|
|
1309
|
-
reason: "Twilio SMS
|
|
1285
|
+
reason: "Twilio SMS check requires fromNumber or messagingServiceSid."
|
|
1310
1286
|
}
|
|
1311
1287
|
});
|
|
1312
1288
|
const messageTask = params.account.fromNumber ? runRemoteProbe({
|
|
1313
|
-
label: "Twilio message history
|
|
1289
|
+
label: "Twilio message history check",
|
|
1314
1290
|
timeoutMs: remoteTimeoutMs,
|
|
1315
1291
|
run: async () => await listTwilioMessages({
|
|
1316
|
-
|
|
1292
|
+
...requestOptions(),
|
|
1317
1293
|
to: params.account.fromNumber,
|
|
1318
|
-
pageSize: 3
|
|
1319
|
-
fetchImpl: params.options?.fetchImpl,
|
|
1320
|
-
timeoutMs: remoteTimeoutMs
|
|
1294
|
+
pageSize: 3
|
|
1321
1295
|
})
|
|
1322
1296
|
}) : Promise.resolve({
|
|
1323
1297
|
kind: "value",
|
|
@@ -1352,11 +1326,11 @@ function formatSmsProbeLines(probe) {
|
|
|
1352
1326
|
const smsProbe = probe;
|
|
1353
1327
|
const lines = [];
|
|
1354
1328
|
if (smsProbe.ok === true) lines.push({
|
|
1355
|
-
text: "
|
|
1329
|
+
text: "Check: ok",
|
|
1356
1330
|
tone: "success"
|
|
1357
1331
|
});
|
|
1358
1332
|
else if (smsProbe.ok === false) lines.push({
|
|
1359
|
-
text: `
|
|
1333
|
+
text: `Check: failed${smsProbe.error ? ` (${smsProbe.error})` : ""}`,
|
|
1360
1334
|
tone: "error"
|
|
1361
1335
|
});
|
|
1362
1336
|
if (smsProbe.webhook?.status === "matches" || smsProbe.webhook?.status === "messaging-service-matches") lines.push({ text: `Twilio SMS webhook: ${smsProbe.webhook.configuredUrl}` });
|
|
@@ -1428,7 +1402,7 @@ const collectSmsOpenDmFindings = createConditionalWarningCollector.findings({
|
|
|
1428
1402
|
severity: "critical",
|
|
1429
1403
|
title: "SMS security warning"
|
|
1430
1404
|
});
|
|
1431
|
-
function
|
|
1405
|
+
function applySmsAccountConfig(params) {
|
|
1432
1406
|
const patch = {};
|
|
1433
1407
|
for (const key of [
|
|
1434
1408
|
"accountSid",
|
|
@@ -1440,11 +1414,7 @@ function smsSetupPatch(input) {
|
|
|
1440
1414
|
"publicWebhookUrl",
|
|
1441
1415
|
"dmPolicy",
|
|
1442
1416
|
"allowFrom"
|
|
1443
|
-
]) if (input[key] !== void 0) patch[key] = input[key];
|
|
1444
|
-
return patch;
|
|
1445
|
-
}
|
|
1446
|
-
function applySmsAccountConfig(params) {
|
|
1447
|
-
const patch = smsSetupPatch(params.input);
|
|
1417
|
+
]) if (params.input[key] !== void 0) patch[key] = params.input[key];
|
|
1448
1418
|
const channels = { ...params.cfg.channels };
|
|
1449
1419
|
const current = { ...channels[CHANNEL_ID] };
|
|
1450
1420
|
if (params.accountId === DEFAULT_ACCOUNT_ID) {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as collectRuntimeConfigAssignments, r as secretTargetRegistryEntries, t as channelSecrets } from "./.setup/secret-contract-
|
|
1
|
+
import { n as collectRuntimeConfigAssignments, r as secretTargetRegistryEntries, t as channelSecrets } from "./.setup/secret-contract-B2P_lFGm.mjs";
|
|
2
2
|
export { channelSecrets, collectRuntimeConfigAssignments, secretTargetRegistryEntries };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openclaw/sms",
|
|
3
|
-
"version": "2026.10.1",
|
|
3
|
+
"version": "2026.10.5-beta.1",
|
|
4
4
|
"description": "OpenClaw SMS/MMS channel plugin for Twilio messages.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -123,10 +123,10 @@
|
|
|
123
123
|
}
|
|
124
124
|
},
|
|
125
125
|
"compat": {
|
|
126
|
-
"pluginApi": ">=2026.10.1"
|
|
126
|
+
"pluginApi": ">=2026.10.5-beta.1"
|
|
127
127
|
},
|
|
128
128
|
"build": {
|
|
129
|
-
"openclawVersion": "2026.10.1",
|
|
129
|
+
"openclawVersion": "2026.10.5-beta.1",
|
|
130
130
|
"bundledDist": false
|
|
131
131
|
},
|
|
132
132
|
"install": {
|
|
@@ -152,7 +152,7 @@
|
|
|
152
152
|
"assets/activity.svg"
|
|
153
153
|
],
|
|
154
154
|
"peerDependencies": {
|
|
155
|
-
"openclaw": ">=2026.10.1"
|
|
155
|
+
"openclaw": ">=2026.10.5-beta.1"
|
|
156
156
|
},
|
|
157
157
|
"peerDependenciesMeta": {
|
|
158
158
|
"openclaw": {
|