@openclaw/sms 2026.8.1-beta.3 → 2026.8.2

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.
@@ -1,20 +1,18 @@
1
1
  import { t as getSmsRuntime } from "./runtime-BBlPgBIF.js";
2
- import { _ as normalizeSmsAllowFrom, a as listTwilioMessages, c as resolveTwilioMessageSid, d as retrieveTwilioMessagingService, f as sendSmsViaTwilio, g as looksLikeSmsPhoneNumber, h as resolveTwilioStatusCallbackUrl, i as listTwilioIncomingPhoneNumbers, l as resolveTwilioWebhookSignatureUrl, m as parseSmsPublicWebhookUrl, o as readTwilioWebhookForm, p as verifyTwilioSignature, r as buildTwilioInboundMessage, s as resolveTwilioInboundSender, t as TWILIO_MESSAGE_BODY_MAX_LENGTH, u as respondTwiml, v as normalizeSmsPhoneNumber } from "./twilio-QS1jkUGH.js";
2
+ import { C as normalizeSmsPhoneNumber, S as normalizeSmsAllowFrom, _ as listSmsAccountIds, a as listTwilioMessages, b as resolveTwilioStatusCallbackUrl, c as resolveTwilioMessageSid, d as retrieveTwilioMessagingService, f as sendSmsViaTwilio, g as isSmsAccountConfigured, h as inspectSmsAccount, i as listTwilioIncomingPhoneNumbers, l as resolveTwilioWebhookSignatureUrl, m as assertSmsCredentialOwnerAvailable, o as readTwilioWebhookForm, p as verifyTwilioSignature, r as buildTwilioInboundMessage, s as resolveTwilioInboundSender, t as TWILIO_MESSAGE_BODY_MAX_LENGTH, u as respondTwiml, v as resolveDefaultSmsAccountId, x as looksLikeSmsPhoneNumber, y as resolveSmsAccount } from "./twilio-BpcGZSHK.js";
3
3
  import { n as collectRuntimeConfigAssignments, r as secretTargetRegistryEntries } from "./secret-contract-Cp0f-YPc.js";
4
- import { DEFAULT_ACCOUNT_ID, normalizeOptionalAccountId } from "openclaw/plugin-sdk/account-id";
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";
7
7
  import { bindIngressLifecycleToReplyOptions, createAccountStatusSink, createChannelIngressMonitor, createMessageReceiptFromOutboundResults, defineChannelMessageAdapter, waitUntilAbort } from "openclaw/plugin-sdk/channel-outbound";
8
8
  import { createConditionalWarningCollector } from "openclaw/plugin-sdk/channel-policy";
9
9
  import { defineChannelSetupContract } from "openclaw/plugin-sdk/channel-setup";
10
10
  import { createEmptyChannelDirectoryAdapter } from "openclaw/plugin-sdk/directory-runtime";
11
+ import { PlatformMessageNotDispatchedError, formatErrorMessage } from "openclaw/plugin-sdk/error-runtime";
11
12
  import { createComputedAccountStatusAdapter, createDefaultChannelRuntimeState } from "openclaw/plugin-sdk/status-helpers";
12
13
  import { isRecord, normalizeStringEntries } from "openclaw/plugin-sdk/string-coerce-runtime";
13
14
  import { chunkTextForOutbound, renderMarkdownIRChunksWithinLimit, sanitizeAssistantVisibleText, stripMarkdown } from "openclaw/plugin-sdk/text-chunking";
14
- import { createAccountListHelpers } from "openclaw/plugin-sdk/account-helpers";
15
- import { DEFAULT_ACCOUNT_ID as DEFAULT_ACCOUNT_ID$1, hasConfiguredAccountValue, resolveAccountEntry } from "openclaw/plugin-sdk/account-resolution";
16
- import { parseStrictPositiveInteger } from "openclaw/plugin-sdk/number-runtime";
17
- import { buildSecretInputSchema, hasConfiguredSecretInput, normalizeResolvedSecretInputString } from "openclaw/plugin-sdk/secret-input";
15
+ import { buildSecretInputSchema } from "openclaw/plugin-sdk/secret-input";
18
16
  import { AllowFromListSchema, DmPolicySchema, buildChannelConfigSchema, buildMultiAccountChannelSchema, requireOpenAllowFrom } from "openclaw/plugin-sdk/channel-config-schema";
19
17
  import { requireChannelOpenAllowFrom } from "openclaw/plugin-sdk/extension-shared";
20
18
  import { z } from "zod";
@@ -25,102 +23,14 @@ import { runDetachedWebhookWork } from "openclaw/plugin-sdk/webhook-request-guar
25
23
  import { resolveStableChannelMessageIngress } from "openclaw/plugin-sdk/channel-ingress-runtime";
26
24
  import { createChannelPairingChallengeIssuer } from "openclaw/plugin-sdk/channel-pairing";
27
25
  import { createChannelPartialDeliveryError } from "openclaw/plugin-sdk/channel-inbound";
28
- import { PlatformMessageNotDispatchedError, formatErrorMessage } from "openclaw/plugin-sdk/error-runtime";
29
26
  import { withTimeout } from "openclaw/plugin-sdk/text-utility-runtime";
30
- //#region extensions/sms/src/accounts.ts
31
- const CHANNEL_ID$3 = "sms";
32
- const DEFAULT_WEBHOOK_PATH = "/webhooks/sms";
33
- const DEFAULT_TEXT_CHUNK_LIMIT = 1500;
34
- function getChannelConfig(cfg) {
35
- return cfg?.channels?.[CHANNEL_ID$3];
36
- }
37
- function parseList(raw) {
38
- if (!raw) return [];
39
- return (Array.isArray(raw) ? raw : typeof raw === "string" ? normalizeStringEntries(raw.split(",")) : [raw]).map((entry) => normalizeSmsAllowFrom(String(entry))).filter(Boolean);
40
- }
41
- function parseTextChunkLimit(raw) {
42
- if (typeof raw === "number" && Number.isSafeInteger(raw) && raw > 0) return raw;
43
- if (typeof raw === "string" && /^\d+$/.test(raw.trim())) return parseStrictPositiveInteger(raw.trim()) ?? DEFAULT_TEXT_CHUNK_LIMIT;
44
- return DEFAULT_TEXT_CHUNK_LIMIT;
45
- }
46
- function firstNonBlankEnv(...values) {
47
- return values.find((value) => value?.trim());
48
- }
49
- function hasBaseAccount(channelCfg) {
50
- return [
51
- channelCfg?.accountSid,
52
- channelCfg?.fromNumber,
53
- channelCfg?.messagingServiceSid,
54
- process.env.TWILIO_ACCOUNT_SID,
55
- process.env.TWILIO_AUTH_TOKEN,
56
- process.env.TWILIO_PHONE_NUMBER,
57
- process.env.TWILIO_SMS_FROM,
58
- process.env.TWILIO_MESSAGING_SERVICE_SID
59
- ].some((value) => hasConfiguredAccountValue(value)) || hasConfiguredSecretInput(channelCfg?.authToken);
60
- }
61
- const { listAccountIds: listSmsAccountIds, resolveDefaultAccountId: resolveDefaultSmsAccountId, resolveAccountConfig: resolveMergedSmsAccountConfig } = createAccountListHelpers(CHANNEL_ID$3, {
62
- fallbackAccountIdWhenEmpty: false,
63
- hasImplicitDefaultAccount: (cfg) => hasBaseAccount(getChannelConfig(cfg)),
64
- omitKeys: ["defaultAccount"]
65
- });
66
- function resolveSmsAccount(cfg, accountId) {
67
- const channelCfg = getChannelConfig(cfg) ?? {};
68
- const id = normalizeOptionalAccountId(accountId) ?? resolveDefaultSmsAccountId(cfg);
69
- const accountConfig = resolveAccountEntry(channelCfg.accounts, id);
70
- const merged = resolveMergedSmsAccountConfig(cfg, id);
71
- const useEnvFallbacks = id === DEFAULT_ACCOUNT_ID$1;
72
- const envAccountSid = useEnvFallbacks ? process.env.TWILIO_ACCOUNT_SID : void 0;
73
- const envAuthToken = useEnvFallbacks ? process.env.TWILIO_AUTH_TOKEN : void 0;
74
- const envFromNumber = useEnvFallbacks ? firstNonBlankEnv(process.env.TWILIO_PHONE_NUMBER, process.env.TWILIO_SMS_FROM) : void 0;
75
- const envMessagingServiceSid = useEnvFallbacks ? process.env.TWILIO_MESSAGING_SERVICE_SID : void 0;
76
- const envWebhookPath = useEnvFallbacks ? process.env.SMS_WEBHOOK_PATH : void 0;
77
- const envPublicWebhookUrl = useEnvFallbacks ? process.env.SMS_PUBLIC_WEBHOOK_URL : void 0;
78
- const envAllowFrom = useEnvFallbacks ? process.env.SMS_ALLOWED_USERS : void 0;
79
- const envTextChunkLimit = useEnvFallbacks ? process.env.SMS_TEXT_CHUNK_LIMIT : void 0;
80
- const envDisableSignatureValidation = useEnvFallbacks ? process.env.SMS_DANGEROUSLY_DISABLE_SIGNATURE_VALIDATION : void 0;
81
- const webhookPath = (merged.webhookPath ?? envWebhookPath ?? DEFAULT_WEBHOOK_PATH).trim();
82
- const publicWebhookUrl = (merged.publicWebhookUrl ?? envPublicWebhookUrl ?? "").trim();
83
- const authToken = normalizeResolvedSecretInputString({
84
- value: merged.authToken ?? envAuthToken,
85
- path: id === DEFAULT_ACCOUNT_ID$1 ? "channels.sms.authToken" : `channels.sms.accounts.${id}.authToken`
86
- }) ?? "";
87
- return {
88
- accountId: id,
89
- enabled: channelCfg.enabled !== false && accountConfig?.enabled !== false,
90
- accountSid: (merged.accountSid ?? envAccountSid ?? "").trim(),
91
- authToken,
92
- fromNumber: normalizeSmsPhoneNumber(merged.fromNumber ?? envFromNumber ?? ""),
93
- messagingServiceSid: (merged.messagingServiceSid ?? envMessagingServiceSid ?? "").trim(),
94
- defaultTo: normalizeSmsPhoneNumber(merged.defaultTo ?? ""),
95
- webhookPath: webhookPath || DEFAULT_WEBHOOK_PATH,
96
- publicWebhookUrl,
97
- dangerouslyDisableSignatureValidation: merged.dangerouslyDisableSignatureValidation === true || envDisableSignatureValidation === "true",
98
- dmPolicy: merged.dmPolicy ?? "pairing",
99
- allowFrom: parseList(merged.allowFrom ?? envAllowFrom),
100
- textChunkLimit: parseTextChunkLimit(merged.textChunkLimit ?? envTextChunkLimit)
101
- };
102
- }
103
- function inspectSmsAccount(cfg, accountId) {
104
- const account = resolveSmsAccount(cfg, accountId);
105
- const configured = isSmsAccountConfigured(account);
106
- return {
107
- enabled: account.enabled,
108
- configured,
109
- tokenStatus: account.authToken ? "available" : "missing",
110
- webhookPath: account.webhookPath,
111
- signatureValidation: account.dangerouslyDisableSignatureValidation ? "configured" : !account.publicWebhookUrl ? "missing-public-url" : parseSmsPublicWebhookUrl(account.publicWebhookUrl) ? "configured" : "invalid-public-url"
112
- };
113
- }
114
- function isSmsAccountConfigured(account) {
115
- return Boolean(account.accountSid && account.authToken && (account.fromNumber || account.messagingServiceSid));
116
- }
117
- //#endregion
118
27
  //#region extensions/sms/src/config-schema.ts
119
28
  const SecretInputSchema = buildSecretInputSchema();
120
- const SmsChannelConfigSchema = buildChannelConfigSchema(buildMultiAccountChannelSchema(z.object({
29
+ const SmsAccountConfigSchema = z.object({
121
30
  name: z.string().optional(),
122
31
  enabled: z.boolean().optional(),
123
32
  configWrites: z.boolean().optional(),
33
+ mediaMaxMb: z.number().positive().optional(),
124
34
  accountSid: z.string().optional(),
125
35
  authToken: SecretInputSchema.optional(),
126
36
  fromNumber: z.string().optional(),
@@ -132,7 +42,8 @@ const SmsChannelConfigSchema = buildChannelConfigSchema(buildMultiAccountChannel
132
42
  dmPolicy: DmPolicySchema.optional().default("pairing"),
133
43
  allowFrom: AllowFromListSchema,
134
44
  textChunkLimit: z.number().int().positive().optional()
135
- }).strict(), {
45
+ }).strict();
46
+ const SmsConfigSchema = buildMultiAccountChannelSchema(SmsAccountConfigSchema, {
136
47
  optionalAccount: true,
137
48
  refine: (value, ctx) => {
138
49
  requireChannelOpenAllowFrom({
@@ -143,7 +54,8 @@ const SmsChannelConfigSchema = buildChannelConfigSchema(buildMultiAccountChannel
143
54
  requireOpenAllowFrom
144
55
  });
145
56
  }
146
- }), { uiHints: {
57
+ });
58
+ const SmsChannelConfigSchema = buildChannelConfigSchema(SmsConfigSchema, { uiHints: {
147
59
  "": {
148
60
  label: "SMS",
149
61
  help: "Twilio SMS/MMS channel configuration for inbound webhooks and outbound replies."
@@ -198,7 +110,7 @@ const SmsChannelConfigSchema = buildChannelConfigSchema(buildMultiAccountChannel
198
110
  //#endregion
199
111
  //#region extensions/sms/src/delivery-observations.ts
200
112
  const DELIVERY_NAMESPACE = "twilio-delivery-observations-v1";
201
- const DELIVERY_RETENTION_MS = 720 * 60 * 60 * 1e3;
113
+ const DELIVERY_RETENTION_MS = 2592e6;
202
114
  const DELIVERY_MAX_MESSAGES = 5e3;
203
115
  const DELIVERY_STATUS_RANK = {
204
116
  accepted: 10,
@@ -464,7 +376,8 @@ function throwSmsPartialDeliveryError(error, results, kind) {
464
376
  });
465
377
  }
466
378
  function toSmsPlainText(text) {
467
- return stripMarkdown(sanitizeAssistantVisibleText(text), {
379
+ const visibleText = sanitizeAssistantVisibleText(text);
380
+ return stripMarkdown(visibleText, {
468
381
  assistantTranscriptRoleHeaders: true,
469
382
  assistantTranscriptRolePrefix: SMS_ASSISTANT_TRANSCRIPT_ROLE_PREFIX,
470
383
  linkStyle: "label-and-url"
@@ -561,7 +474,8 @@ async function prepareSmsMediaAttempt(params) {
561
474
  });
562
475
  let hostedMedia;
563
476
  try {
564
- const { prepareHostedSmsMedia } = await import("./media-C_8jX0L8.js");
477
+ const { prepareHostedSmsMedia } = await import("./media-BDbaClzL.js");
478
+ assertSmsCredentialOwnerAvailable(params.account);
565
479
  const prepared = await prepareHostedSmsMedia({
566
480
  account: params.account,
567
481
  mediaUrl: params.mediaUrl,
@@ -692,7 +606,7 @@ async function dispatchSmsInboundEvent(params) {
692
606
  params.log?.warn?.(`SMS sender ${from} is not authorized`);
693
607
  return;
694
608
  }
695
- const materialized = params.msg.media.length > 0 || (params.msg.unavailableMediaCount ?? 0) > 0 ? await (await import("./media-C_8jX0L8.js")).materializeSmsInboundMedia({
609
+ const materialized = params.msg.media.length > 0 || (params.msg.unavailableMediaCount ?? 0) > 0 ? await (await import("./media-BDbaClzL.js")).materializeSmsInboundMedia({
696
610
  account: params.account,
697
611
  msg: params.msg,
698
612
  mediaRuntime: params.channelRuntime,
@@ -918,7 +832,7 @@ function createSmsIngressSpool(params) {
918
832
  pollIntervalMs: SMS_INGRESS_DRAIN_INTERVAL_MS,
919
833
  retention: {
920
834
  pruneIntervalMs: 0,
921
- completedTtlMs: 1440 * 60 * 1e3,
835
+ completedTtlMs: 864e5,
922
836
  failedMaxEntries: 1e3
923
837
  },
924
838
  appendRetryDelaysMs: [0],
@@ -1025,6 +939,7 @@ function createSmsWebhookHandler(params) {
1025
939
  }
1026
940
  throw error;
1027
941
  }
942
+ assertSmsCredentialOwnerAvailable(params.account);
1028
943
  if (!params.account.dangerouslyDisableSignatureValidation) {
1029
944
  if (!verifyTwilioSignature({
1030
945
  signature: headerValue(req.headers["x-twilio-signature"]),
@@ -1176,7 +1091,7 @@ async function registerSmsWebhookRoute(params) {
1176
1091
  throwOnFailure: true,
1177
1092
  log: (msg) => params.log?.info?.(msg),
1178
1093
  handler: async (req, res) => {
1179
- const { tryHandleHostedSmsMediaRequest } = await import("./media-C_8jX0L8.js");
1094
+ const { tryHandleHostedSmsMediaRequest } = await import("./media-BDbaClzL.js");
1180
1095
  if (await tryHandleHostedSmsMediaRequest(req, res, params.account.accountId)) return true;
1181
1096
  return await webhookHandler(req, res);
1182
1097
  }
@@ -1512,7 +1427,8 @@ const smsConfigAdapter = createHybridChannelConfigAdapter({
1512
1427
  "dangerouslyDisableSignatureValidation",
1513
1428
  "dmPolicy",
1514
1429
  "allowFrom",
1515
- "textChunkLimit"
1430
+ "textChunkLimit",
1431
+ "mediaMaxMb"
1516
1432
  ],
1517
1433
  resolveAllowFrom: (account) => account.allowFrom,
1518
1434
  formatAllowFrom: (allowFrom) => normalizeStringEntries(allowFrom.map((entry) => normalizeSmsAllowFrom(String(entry)))),
@@ -1745,7 +1661,7 @@ const smsMessageAdapter = defineChannelMessageAdapter({
1745
1661
  afterSendFailure: async (ctx) => {
1746
1662
  if (ctx.kind !== "media") return;
1747
1663
  const attemptToken = resolveSmsAttachmentAttemptToken(ctx.attemptToken);
1748
- if (!attemptToken || attemptToken.platformDispatchStarted) return;
1664
+ if (!attemptToken || attemptToken.platformDispatchStarted && !(ctx.error instanceof PlatformMessageNotDispatchedError)) return;
1749
1665
  await attemptToken.attempt.cleanupHostedMedia();
1750
1666
  }
1751
1667
  },
@@ -0,0 +1,26 @@
1
+ import { DEFAULT_ACCOUNT_ID, hasConfiguredAccountValue } from "openclaw/plugin-sdk/account-core";
2
+ //#region extensions/sms/configured-state.ts
3
+ function hasConfiguredSmsAccount(account, env) {
4
+ const hasAccount = hasConfiguredAccountValue(account?.accountSid ?? env.TWILIO_ACCOUNT_SID);
5
+ const hasToken = hasConfiguredAccountValue(account?.authToken ?? env.TWILIO_AUTH_TOKEN);
6
+ const fromNumber = [env.TWILIO_PHONE_NUMBER, env.TWILIO_SMS_FROM].find((value) => hasConfiguredAccountValue(value));
7
+ const hasSender = hasConfiguredAccountValue(account?.fromNumber ?? fromNumber) || hasConfiguredAccountValue(account?.messagingServiceSid ?? env.TWILIO_MESSAGING_SERVICE_SID);
8
+ return hasAccount && hasToken && hasSender;
9
+ }
10
+ /** Require a complete Twilio identity and sender, scoped to each enabled account. */
11
+ function hasConfiguredSmsChannelState(params) {
12
+ const channel = params.cfg.channels?.sms;
13
+ if (channel?.enabled === false) return false;
14
+ const defaultAccount = channel?.accounts?.[DEFAULT_ACCOUNT_ID];
15
+ const { accounts: _accounts, defaultAccount: _defaultAccount, ...defaults } = channel ?? {};
16
+ if (defaultAccount?.enabled !== false && hasConfiguredSmsAccount(defaultAccount ? {
17
+ ...defaults,
18
+ ...defaultAccount
19
+ } : channel, params.env ?? process.env)) return true;
20
+ return Object.entries(channel?.accounts ?? {}).some(([accountId, account]) => accountId !== DEFAULT_ACCOUNT_ID && account.enabled !== false && hasConfiguredSmsAccount({
21
+ ...defaults,
22
+ ...account
23
+ }, {}));
24
+ }
25
+ //#endregion
26
+ export { hasConfiguredSmsChannelState };
@@ -1,9 +1,9 @@
1
1
  import { t as getSmsRuntime } from "./runtime-BBlPgBIF.js";
2
- import { n as TWILIO_MMS_MAX_BYTES } from "./twilio-QS1jkUGH.js";
2
+ import { m as assertSmsCredentialOwnerAvailable, n as TWILIO_MMS_MAX_BYTES } from "./twilio-BpcGZSHK.js";
3
+ import { collectErrorGraphCandidates } from "openclaw/plugin-sdk/error-runtime";
3
4
  import { resolveExpiresAtMsFromDurationMs } from "openclaw/plugin-sdk/number-runtime";
4
5
  import { createHash } from "node:crypto";
5
6
  import { formatInboundMediaUnavailableText, toInboundMediaFactsWithMetadata } from "openclaw/plugin-sdk/channel-inbound";
6
- import { collectErrorGraphCandidates } from "openclaw/plugin-sdk/error-runtime";
7
7
  import { SsrFBlockedError, safeEqualSecret } from "openclaw/plugin-sdk/security-runtime";
8
8
  import { extensionForMime } from "openclaw/plugin-sdk/media-mime";
9
9
  import { MediaFetchError, unlinkIfExists } from "openclaw/plugin-sdk/media-runtime";
@@ -15,7 +15,7 @@ const TWILIO_MEDIA_PATH_RE = /^\/2010-04-01\/Accounts\/([^/]+)\/Messages\/([^/]+
15
15
  const TWILIO_MEDIA_TOTAL_TIMEOUT_MS = 6e4;
16
16
  const TWILIO_MEDIA_RESPONSE_HEADER_TIMEOUT_MS = 3e4;
17
17
  const TWILIO_MEDIA_READ_IDLE_TIMEOUT_MS = 3e4;
18
- const TWILIO_MEDIA_BATCH_TIMEOUT_MS = 4 * 6e4;
18
+ const TWILIO_MEDIA_BATCH_TIMEOUT_MS = 24e4;
19
19
  const TWILIO_MEDIA_RETRY = {
20
20
  attempts: 2,
21
21
  minDelayMs: 500,
@@ -78,13 +78,13 @@ const TWILIO_MMS_EXTENSION_BY_TYPE = {
78
78
  "video/quicktime": ".mov",
79
79
  "video/webm": ".webm"
80
80
  };
81
- const SMS_OUTBOUND_MEDIA_TTL_MS = 10 * 6e4;
81
+ const SMS_OUTBOUND_MEDIA_TTL_MS = 6e5;
82
82
  const SMS_OUTBOUND_MEDIA_ID_RE = /^[a-f0-9]{24}$/;
83
83
  const SMS_OUTBOUND_MEDIA_TOKEN_PARAM_PREFIX = "__openclaw_mms_token";
84
84
  const SMS_OUTBOUND_MEDIA_NAMESPACE = "hosted-outbound-media";
85
85
  const SMS_OUTBOUND_MEDIA_CHUNKS_NAMESPACE = "hosted-outbound-media-chunks";
86
86
  const SMS_OUTBOUND_MEDIA_MAX_ENTRIES = 64;
87
- const SMS_OUTBOUND_MEDIA_MAX_CHUNK_ROWS = SMS_OUTBOUND_MEDIA_MAX_ENTRIES * 160;
87
+ const SMS_OUTBOUND_MEDIA_MAX_CHUNK_ROWS = 10240;
88
88
  const hostedSmsMediaStores = /* @__PURE__ */ new Map();
89
89
  let hostedSmsMediaRuntime;
90
90
  function normalizeBasePath(path) {
@@ -180,7 +180,7 @@ async function prepareHostedSmsMedia(params) {
180
180
  mediaUrl: params.mediaUrl,
181
181
  routePath: route.localRoutePath,
182
182
  publicBaseUrl: route.publicBaseUrl,
183
- maxBytes: aggregateMediaBudget,
183
+ maxBytes: Math.min(params.account.mediaMaxBytes ?? aggregateMediaBudget, aggregateMediaBudget),
184
184
  mediaAccess
185
185
  }));
186
186
  const id = stagedUrl.pathname.split("/").at(-1) ?? "";
@@ -276,7 +276,12 @@ async function materializeSmsInboundMedia(params) {
276
276
  let remainingBytes = TWILIO_MMS_MAX_BYTES;
277
277
  let unavailableCount = declaredUnavailableCount;
278
278
  const batchTimeoutSignal = AbortSignal.timeout(TWILIO_MEDIA_BATCH_TIMEOUT_MS);
279
- const abortSignal = params.abortSignal ? AbortSignal.any([params.abortSignal, batchTimeoutSignal]) : batchTimeoutSignal;
279
+ const credentialAbortController = new AbortController();
280
+ const abortSignal = AbortSignal.any([
281
+ credentialAbortController.signal,
282
+ batchTimeoutSignal,
283
+ ...params.abortSignal ? [params.abortSignal] : []
284
+ ]);
280
285
  const savedMedia = [];
281
286
  try {
282
287
  for (const [index, media] of params.msg.media.entries()) {
@@ -291,13 +296,21 @@ async function materializeSmsInboundMedia(params) {
291
296
  accountSid: callbackAccountSid,
292
297
  messageSid: params.msg.messageSid
293
298
  }),
299
+ beforeRequest: () => {
300
+ try {
301
+ assertSmsCredentialOwnerAvailable(params.account);
302
+ } catch (error) {
303
+ credentialAbortController.abort(error);
304
+ throw error;
305
+ }
306
+ },
294
307
  requestInit: {
295
308
  headers: { authorization: `Basic ${Buffer.from(`${params.account.accountSid}:${params.account.authToken}`).toString("base64")}` },
296
309
  signal: abortSignal
297
310
  },
298
311
  filePathHint: inboundMediaFileName(media.contentType, index),
299
312
  fallbackContentType: media.contentType,
300
- maxBytes: remainingBytes,
313
+ maxBytes: Math.min(params.account.mediaMaxBytes ?? remainingBytes, remainingBytes),
301
314
  ssrfPolicy: { hostnameAllowlist: [TWILIO_API_HOSTNAME] },
302
315
  timeoutMs: TWILIO_MEDIA_TOTAL_TIMEOUT_MS,
303
316
  responseHeaderTimeoutMs: TWILIO_MEDIA_RESPONSE_HEADER_TIMEOUT_MS,
@@ -1,8 +1,18 @@
1
+ import { normalizeOptionalAccountId } from "openclaw/plugin-sdk/account-id";
2
+ import { PlatformMessageNotDispatchedError, formatErrorMessage } from "openclaw/plugin-sdk/error-runtime";
3
+ import { normalizeStringEntries } from "openclaw/plugin-sdk/string-coerce-runtime";
4
+ import { createAccountListHelpers, resolveChannelMediaMaxBytes } from "openclaw/plugin-sdk/account-helpers";
5
+ import { DEFAULT_ACCOUNT_ID as DEFAULT_ACCOUNT_ID$1, hasConfiguredAccountValue, resolveAccountEntry } from "openclaw/plugin-sdk/account-resolution";
6
+ import { parseStrictPositiveInteger } from "openclaw/plugin-sdk/number-runtime";
7
+ import { hasConfiguredSecretInput, resolveSecretInputString } from "openclaw/plugin-sdk/secret-input";
1
8
  import { isIP } from "node:net";
2
9
  import { fetchWithSsrFGuard, isBlockedHostnameOrIp } from "openclaw/plugin-sdk/ssrf-runtime";
3
10
  import { createHmac } from "node:crypto";
4
11
  import { readRequestBodyWithLimit } from "openclaw/plugin-sdk/webhook-ingress";
12
+ import { assertSecretOwnerAvailable } from "openclaw/plugin-sdk/channel-secret-owner-runtime";
13
+ import { getRuntimeConfigSnapshot } from "openclaw/plugin-sdk/runtime-config-snapshot";
5
14
  import * as querystring from "node:querystring";
15
+ import { redactToolPayloadText } from "openclaw/plugin-sdk/logging-core";
6
16
  import { readResponseTextPrefix, readResponseWithLimit } from "openclaw/plugin-sdk/response-limit-runtime";
7
17
  import { safeEqualSecret } from "openclaw/plugin-sdk/security-runtime";
8
18
  //#region extensions/sms/src/phone.ts
@@ -92,20 +102,131 @@ function resolveTwilioStatusCallbackUrl(publicWebhookUrl) {
92
102
  return callbackUrl;
93
103
  }
94
104
  //#endregion
105
+ //#region extensions/sms/src/accounts.ts
106
+ const CHANNEL_ID = "sms";
107
+ const DEFAULT_WEBHOOK_PATH = "/webhooks/sms";
108
+ const DEFAULT_TEXT_CHUNK_LIMIT = 1500;
109
+ function getChannelConfig(cfg) {
110
+ return cfg?.channels?.[CHANNEL_ID];
111
+ }
112
+ function parseList(raw) {
113
+ if (!raw) return [];
114
+ return (Array.isArray(raw) ? raw : typeof raw === "string" ? normalizeStringEntries(raw.split(",")) : [raw]).map((entry) => normalizeSmsAllowFrom(String(entry))).filter(Boolean);
115
+ }
116
+ function parseTextChunkLimit(raw) {
117
+ if (typeof raw === "number" && Number.isSafeInteger(raw) && raw > 0) return raw;
118
+ if (typeof raw === "string" && /^\d+$/.test(raw.trim())) return parseStrictPositiveInteger(raw.trim()) ?? DEFAULT_TEXT_CHUNK_LIMIT;
119
+ return DEFAULT_TEXT_CHUNK_LIMIT;
120
+ }
121
+ function firstNonBlankEnv(...values) {
122
+ return values.find((value) => value?.trim());
123
+ }
124
+ function hasBaseAccount(channelCfg) {
125
+ return [
126
+ channelCfg?.accountSid,
127
+ channelCfg?.fromNumber,
128
+ channelCfg?.messagingServiceSid,
129
+ process.env.TWILIO_ACCOUNT_SID,
130
+ process.env.TWILIO_AUTH_TOKEN,
131
+ process.env.TWILIO_PHONE_NUMBER,
132
+ process.env.TWILIO_SMS_FROM,
133
+ process.env.TWILIO_MESSAGING_SERVICE_SID
134
+ ].some((value) => hasConfiguredAccountValue(value)) || hasConfiguredSecretInput(channelCfg?.authToken);
135
+ }
136
+ const { listAccountIds: listSmsAccountIds, resolveDefaultAccountId: resolveDefaultSmsAccountId, resolveAccountConfig: resolveMergedSmsAccountConfig } = createAccountListHelpers(CHANNEL_ID, {
137
+ fallbackAccountIdWhenEmpty: false,
138
+ hasImplicitDefaultAccount: (cfg) => hasBaseAccount(getChannelConfig(cfg)),
139
+ omitKeys: ["defaultAccount"]
140
+ });
141
+ function resolveSmsAccount(cfg, accountId) {
142
+ return readSmsAccount(cfg, accountId, "strict").account;
143
+ }
144
+ function readSmsAccount(cfg, accountId, mode) {
145
+ const channelCfg = getChannelConfig(cfg) ?? {};
146
+ const id = normalizeOptionalAccountId(accountId) ?? resolveDefaultSmsAccountId(cfg);
147
+ const accountConfig = resolveAccountEntry(channelCfg.accounts, id);
148
+ const merged = resolveMergedSmsAccountConfig(cfg, id);
149
+ const useEnvFallbacks = id === DEFAULT_ACCOUNT_ID$1;
150
+ const envAccountSid = useEnvFallbacks ? process.env.TWILIO_ACCOUNT_SID : void 0;
151
+ const envAuthToken = useEnvFallbacks ? process.env.TWILIO_AUTH_TOKEN : void 0;
152
+ const envFromNumber = useEnvFallbacks ? firstNonBlankEnv(process.env.TWILIO_PHONE_NUMBER, process.env.TWILIO_SMS_FROM) : void 0;
153
+ const envMessagingServiceSid = useEnvFallbacks ? process.env.TWILIO_MESSAGING_SERVICE_SID : void 0;
154
+ const envWebhookPath = useEnvFallbacks ? process.env.SMS_WEBHOOK_PATH : void 0;
155
+ const envPublicWebhookUrl = useEnvFallbacks ? process.env.SMS_PUBLIC_WEBHOOK_URL : void 0;
156
+ const envAllowFrom = useEnvFallbacks ? process.env.SMS_ALLOWED_USERS : void 0;
157
+ const envTextChunkLimit = useEnvFallbacks ? process.env.SMS_TEXT_CHUNK_LIMIT : void 0;
158
+ const envDisableSignatureValidation = useEnvFallbacks ? process.env.SMS_DANGEROUSLY_DISABLE_SIGNATURE_VALIDATION : void 0;
159
+ const webhookPath = (merged.webhookPath ?? envWebhookPath ?? DEFAULT_WEBHOOK_PATH).trim();
160
+ const publicWebhookUrl = (merged.publicWebhookUrl ?? envPublicWebhookUrl ?? "").trim();
161
+ const authToken = resolveSecretInputString({
162
+ value: merged.authToken ?? envAuthToken,
163
+ path: id === DEFAULT_ACCOUNT_ID$1 ? "channels.sms.authToken" : `channels.sms.accounts.${id}.authToken`,
164
+ mode
165
+ });
166
+ return {
167
+ account: {
168
+ accountId: id,
169
+ enabled: channelCfg.enabled !== false && accountConfig?.enabled !== false,
170
+ accountSid: (merged.accountSid ?? envAccountSid ?? "").trim(),
171
+ authToken: authToken.value ?? "",
172
+ fromNumber: normalizeSmsPhoneNumber(merged.fromNumber ?? envFromNumber ?? ""),
173
+ messagingServiceSid: (merged.messagingServiceSid ?? envMessagingServiceSid ?? "").trim(),
174
+ defaultTo: normalizeSmsPhoneNumber(merged.defaultTo ?? ""),
175
+ webhookPath: webhookPath || DEFAULT_WEBHOOK_PATH,
176
+ publicWebhookUrl,
177
+ dangerouslyDisableSignatureValidation: merged.dangerouslyDisableSignatureValidation === true || envDisableSignatureValidation === "true",
178
+ dmPolicy: merged.dmPolicy ?? "pairing",
179
+ allowFrom: parseList(merged.allowFrom ?? envAllowFrom),
180
+ textChunkLimit: parseTextChunkLimit(merged.textChunkLimit ?? envTextChunkLimit),
181
+ mediaMaxBytes: resolveChannelMediaMaxBytes({
182
+ cfg,
183
+ accountId: id,
184
+ resolveChannelLimitMb: () => merged.mediaMaxMb
185
+ })
186
+ },
187
+ tokenStatus: authToken.status
188
+ };
189
+ }
190
+ function inspectSmsAccount(cfg, accountId) {
191
+ const { account, tokenStatus } = readSmsAccount(cfg, accountId, "inspect");
192
+ const configured = Boolean(account.accountSid && tokenStatus !== "missing" && (account.fromNumber || account.messagingServiceSid));
193
+ return {
194
+ accountId: account.accountId,
195
+ name: account.fromNumber || account.messagingServiceSid || "SMS",
196
+ enabled: account.enabled,
197
+ configured,
198
+ tokenStatus,
199
+ webhookPath: account.webhookPath,
200
+ signatureValidation: account.dangerouslyDisableSignatureValidation ? "configured" : !account.publicWebhookUrl ? "missing-public-url" : parseSmsPublicWebhookUrl(account.publicWebhookUrl) ? "configured" : "invalid-public-url"
201
+ };
202
+ }
203
+ function isSmsAccountConfigured(account) {
204
+ return Boolean(account.accountSid && account.authToken && (account.fromNumber || account.messagingServiceSid));
205
+ }
206
+ //#endregion
207
+ //#region extensions/sms/src/credential-availability.ts
208
+ function assertSmsCredentialOwnerAvailable(account) {
209
+ assertSecretOwnerAvailable("account", `sms:${account.accountId}`);
210
+ const runtimeConfig = getRuntimeConfigSnapshot();
211
+ if (!runtimeConfig) return;
212
+ const current = resolveSmsAccount(runtimeConfig, account.accountId);
213
+ if (current.accountSid !== account.accountSid || current.authToken !== account.authToken) throw new Error(`SMS credentials changed for ${account.accountId}; retry the operation.`);
214
+ }
215
+ //#endregion
95
216
  //#region extensions/sms/src/twilio.ts
96
217
  const TWILIO_ACCOUNTS_URL = "https://api.twilio.com/2010-04-01/Accounts";
97
218
  const TWILIO_MESSAGING_URL = "https://messaging.twilio.com/v1";
98
219
  const TWILIO_API_HOSTNAME = "api.twilio.com";
99
220
  const TWILIO_MESSAGING_HOSTNAME = "messaging.twilio.com";
100
221
  const TWILIO_API_TIMEOUT_MS = 3e4;
101
- const TWILIO_API_SUCCESS_BODY_LIMIT_BYTES = 1 * 1024 * 1024;
102
- const TWILIO_API_ERROR_BODY_LIMIT_BYTES = 8 * 1024;
222
+ const TWILIO_API_SUCCESS_BODY_LIMIT_BYTES = 1048576;
223
+ const TWILIO_API_ERROR_BODY_LIMIT_BYTES = 8192;
103
224
  const TRUNCATED_RESPONSE_SUFFIX = "... [truncated]";
104
- const WEBHOOK_BODY_LIMIT_BYTES = 32 * 1024;
225
+ const WEBHOOK_BODY_LIMIT_BYTES = 32768;
105
226
  const WEBHOOK_BODY_TIMEOUT_MS = 5e3;
106
227
  const TWILIO_MESSAGE_BODY_MAX_LENGTH = 1600;
107
228
  const TWILIO_MMS_MAX_OUTBOUND_MEDIA_COUNT = 10;
108
- const TWILIO_MMS_MAX_BYTES = 5 * 1024 * 1024;
229
+ const TWILIO_MMS_MAX_BYTES = 5242880;
109
230
  const SMS_MAX_INBOUND_MEDIA_DOWNLOADS = 10;
110
231
  const TWILIO_CHANNEL_ADDRESS_RE = /^([a-z][a-z0-9-]*):(.*)$/i;
111
232
  function firstString(value) {
@@ -170,12 +291,13 @@ function resolveTwilioWebhookSignatureUrl(params) {
170
291
  }
171
292
  var TwilioSmsApiError = class extends Error {
172
293
  constructor(httpStatus, responseText, operation = "send") {
173
- const parsed = parseTwilioApiError(responseText);
174
- const detail = parsed.message ?? (responseText || "unknown");
294
+ const redactedResponseText = redactToolPayloadText(responseText);
295
+ const parsed = parseTwilioApiError(redactedResponseText);
296
+ const detail = parsed.message ?? (redactedResponseText || "unknown");
175
297
  super(`Twilio SMS ${operation} failed (${httpStatus}): ${detail}`);
176
298
  this.name = "TwilioSmsApiError";
177
299
  this.httpStatus = httpStatus;
178
- this.responseText = responseText;
300
+ this.responseText = redactedResponseText;
179
301
  this.twilioCode = parsed.code;
180
302
  }
181
303
  };
@@ -292,6 +414,13 @@ function normalizeRequestHeaders(headers) {
292
414
  if (Array.isArray(headers)) return Object.fromEntries(headers.map(([key, value]) => [key, value]));
293
415
  return Object.fromEntries(Object.entries(headers));
294
416
  }
417
+ function assertTwilioRequestCredentialsAvailable(account) {
418
+ try {
419
+ assertSmsCredentialOwnerAvailable(account);
420
+ } catch (error) {
421
+ throw new PlatformMessageNotDispatchedError(`SMS request stopped before Twilio dispatch: ${formatErrorMessage(error)}`, { cause: error });
422
+ }
423
+ }
295
424
  async function requestTwilioApi(params) {
296
425
  const init = {
297
426
  ...params.init,
@@ -301,6 +430,7 @@ async function requestTwilioApi(params) {
301
430
  }
302
431
  };
303
432
  if (params.fetchImpl) {
433
+ assertTwilioRequestCredentialsAvailable(params.account);
304
434
  const response = await params.fetchImpl(params.url, init);
305
435
  return {
306
436
  ok: response.ok,
@@ -308,9 +438,18 @@ async function requestTwilioApi(params) {
308
438
  text: await readTwilioApiResponseText(response)
309
439
  };
310
440
  }
441
+ let requestDispatched = false;
311
442
  const guarded = await fetchWithSsrFGuard({
312
443
  url: params.url,
313
444
  init,
445
+ beforeRequest: () => {
446
+ if (requestDispatched) {
447
+ assertSmsCredentialOwnerAvailable(params.account);
448
+ return;
449
+ }
450
+ assertTwilioRequestCredentialsAvailable(params.account);
451
+ requestDispatched = true;
452
+ },
314
453
  auditContext: "sms-twilio-api",
315
454
  policy: { allowedHostnames: [params.allowedHostname] },
316
455
  requireHttps: true,
@@ -416,6 +555,7 @@ async function listTwilioMessages(params) {
416
555
  return parseTwilioListPayload(response.text, "messages", parseTwilioMessageLogEntry);
417
556
  }
418
557
  async function sendSmsViaTwilio(params) {
558
+ assertSmsCredentialOwnerAvailable(params.account);
419
559
  if (!params.account.fromNumber && !params.account.messagingServiceSid) throw new Error("Twilio SMS send requires fromNumber or messagingServiceSid.");
420
560
  if (params.text && params.text.length > 1600) throw new Error(`Twilio SMS/MMS Body supports at most ${TWILIO_MESSAGE_BODY_MAX_LENGTH} characters.`);
421
561
  const mediaUrls = (params.mediaUrls ?? []).map((url) => url.trim()).filter(Boolean);
@@ -453,4 +593,4 @@ async function sendSmsViaTwilio(params) {
453
593
  };
454
594
  }
455
595
  //#endregion
456
- export { normalizeSmsAllowFrom as _, listTwilioMessages as a, resolveTwilioMessageSid as c, retrieveTwilioMessagingService as d, sendSmsViaTwilio as f, looksLikeSmsPhoneNumber as g, resolveTwilioStatusCallbackUrl as h, listTwilioIncomingPhoneNumbers as i, resolveTwilioWebhookSignatureUrl as l, parseSmsPublicWebhookUrl as m, TWILIO_MMS_MAX_BYTES as n, readTwilioWebhookForm as o, verifyTwilioSignature as p, buildTwilioInboundMessage as r, resolveTwilioInboundSender as s, TWILIO_MESSAGE_BODY_MAX_LENGTH as t, respondTwiml as u, normalizeSmsPhoneNumber as v };
596
+ export { normalizeSmsPhoneNumber as C, normalizeSmsAllowFrom as S, listSmsAccountIds as _, listTwilioMessages as a, resolveTwilioStatusCallbackUrl as b, resolveTwilioMessageSid as c, retrieveTwilioMessagingService as d, sendSmsViaTwilio as f, isSmsAccountConfigured as g, inspectSmsAccount as h, listTwilioIncomingPhoneNumbers as i, resolveTwilioWebhookSignatureUrl as l, assertSmsCredentialOwnerAvailable as m, TWILIO_MMS_MAX_BYTES as n, readTwilioWebhookForm as o, verifyTwilioSignature as p, buildTwilioInboundMessage as r, resolveTwilioInboundSender as s, TWILIO_MESSAGE_BODY_MAX_LENGTH as t, respondTwiml as u, resolveDefaultSmsAccountId as v, looksLikeSmsPhoneNumber as x, resolveSmsAccount as y };
@@ -28,6 +28,10 @@
28
28
  "configWrites": {
29
29
  "type": "boolean"
30
30
  },
31
+ "mediaMaxMb": {
32
+ "type": "number",
33
+ "exclusiveMinimum": 0
34
+ },
31
35
  "accountSid": {
32
36
  "type": "string"
33
37
  },
@@ -195,6 +199,10 @@
195
199
  "configWrites": {
196
200
  "type": "boolean"
197
201
  },
202
+ "mediaMaxMb": {
203
+ "type": "number",
204
+ "exclusiveMinimum": 0
205
+ },
198
206
  "accountSid": {
199
207
  "type": "string"
200
208
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openclaw/sms",
3
- "version": "2026.8.1-beta.3",
3
+ "version": "2026.8.2",
4
4
  "description": "OpenClaw SMS/MMS channel plugin for Twilio messages.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -23,12 +23,11 @@
23
23
  "TWILIO_AUTH_TOKEN",
24
24
  "TWILIO_PHONE_NUMBER",
25
25
  "TWILIO_SMS_FROM",
26
- "TWILIO_MESSAGING_SERVICE_SID",
27
- "SMS_PUBLIC_WEBHOOK_URL",
28
- "SMS_WEBHOOK_PATH",
29
- "SMS_ALLOWED_USERS"
26
+ "TWILIO_MESSAGING_SERVICE_SID"
30
27
  ]
31
- }
28
+ },
29
+ "specifier": "./dist/configured-state.js",
30
+ "exportName": "hasConfiguredSmsChannelState"
32
31
  },
33
32
  "label": "SMS",
34
33
  "selectionLabel": "SMS (Twilio)",
@@ -124,10 +123,10 @@
124
123
  }
125
124
  },
126
125
  "compat": {
127
- "pluginApi": ">=2026.8.1-beta.3"
126
+ "pluginApi": ">=2026.8.2"
128
127
  },
129
128
  "build": {
130
- "openclawVersion": "2026.8.1-beta.3",
129
+ "openclawVersion": "2026.8.2",
131
130
  "bundledDist": false
132
131
  },
133
132
  "install": {
@@ -151,7 +150,7 @@
151
150
  "README.md"
152
151
  ],
153
152
  "peerDependencies": {
154
- "openclaw": ">=2026.8.1-beta.3"
153
+ "openclaw": ">=2026.8.2"
155
154
  },
156
155
  "peerDependenciesMeta": {
157
156
  "openclaw": {