@openclaw/sms 2026.9.1-beta.1 → 2026.9.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.
|
@@ -1,126 +1,36 @@
|
|
|
1
1
|
import { t as getSmsRuntime } from "./runtime-BBlPgBIF.js";
|
|
2
|
-
import {
|
|
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 "./twilio-J4cwlx0M.js";
|
|
3
3
|
import { n as collectRuntimeConfigAssignments, r as secretTargetRegistryEntries } from "./secret-contract-Cp0f-YPc.js";
|
|
4
|
-
import { DEFAULT_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 {
|
|
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";
|
|
21
19
|
import { createHash } from "node:crypto";
|
|
22
20
|
import { channelBlockedPatch, channelReadyPatch, channelStoppedPatch } from "openclaw/plugin-sdk/gateway-runtime";
|
|
23
21
|
import { createFixedWindowRateLimiter, isRequestBodyLimitError, registerPluginHttpRoute, resolveRequestClientIp } from "openclaw/plugin-sdk/webhook-ingress";
|
|
24
|
-
import { runDetachedWebhookWork } from "openclaw/plugin-sdk/webhook-request-guards";
|
|
22
|
+
import { createWebhookInFlightLimiter, runDetachedWebhookWork, sendHttpRequestRejection } from "openclaw/plugin-sdk/webhook-request-guards";
|
|
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
|
|
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
|
-
})
|
|
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 =
|
|
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
|
-
|
|
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-
|
|
477
|
+
const { prepareHostedSmsMedia } = await import("./media-Cle9pp18.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-
|
|
609
|
+
const materialized = params.msg.media.length > 0 || (params.msg.unavailableMediaCount ?? 0) > 0 ? await (await import("./media-Cle9pp18.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:
|
|
835
|
+
completedTtlMs: 864e5,
|
|
922
836
|
failedMaxEntries: 1e3
|
|
923
837
|
},
|
|
924
838
|
appendRetryDelaysMs: [0],
|
|
@@ -955,6 +869,7 @@ function createSmsIngressSpool(params) {
|
|
|
955
869
|
//#endregion
|
|
956
870
|
//#region extensions/sms/src/webhook.ts
|
|
957
871
|
const INVALID_REQUEST_MAX_REQUESTS = 300;
|
|
872
|
+
const PRE_AUTH_MAX_IN_FLIGHT = 64;
|
|
958
873
|
const INBOUND_DISPATCH_MAX_REQUESTS = 30;
|
|
959
874
|
const DELIVERY_CALLBACK_MAX_REQUESTS = 3e3;
|
|
960
875
|
const DELIVERY_CALLBACK_WINDOW_MS = 6e4;
|
|
@@ -995,6 +910,11 @@ function rejectInvalidRequestRateLimit(params) {
|
|
|
995
910
|
}
|
|
996
911
|
function createSmsWebhookHandler(params) {
|
|
997
912
|
let deliveryRecorder = params.delivery;
|
|
913
|
+
const preAuthInFlightLimiter = createWebhookInFlightLimiter({
|
|
914
|
+
maxInFlightPerKey: PRE_AUTH_MAX_IN_FLIGHT,
|
|
915
|
+
maxTrackedKeys: 1
|
|
916
|
+
});
|
|
917
|
+
const preAuthInFlightKey = accountRouteRateLimitKey(params.account);
|
|
998
918
|
const deliveryCallbackRateLimiter = createFixedWindowRateLimiter({
|
|
999
919
|
maxRequests: DELIVERY_CALLBACK_MAX_REQUESTS,
|
|
1000
920
|
windowMs: DELIVERY_CALLBACK_WINDOW_MS,
|
|
@@ -1015,41 +935,56 @@ function createSmsWebhookHandler(params) {
|
|
|
1015
935
|
subject: clientAddress
|
|
1016
936
|
});
|
|
1017
937
|
const invalidRequestRateLimited = invalidRequestRateLimiter.isRateLimited(clientAddressKey);
|
|
938
|
+
if (!preAuthInFlightLimiter.tryAcquire(preAuthInFlightKey)) {
|
|
939
|
+
params.log?.warn?.("SMS webhook pre-authentication concurrency limit exceeded");
|
|
940
|
+
await sendHttpRequestRejection(req, res, 429, "Rate limit exceeded", TWIML_CONTENT_TYPE);
|
|
941
|
+
return true;
|
|
942
|
+
}
|
|
1018
943
|
let form;
|
|
1019
944
|
try {
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
945
|
+
try {
|
|
946
|
+
form = await readTwilioWebhookForm(req);
|
|
947
|
+
} catch (error) {
|
|
948
|
+
if (isRequestBodyLimitError(error, "PAYLOAD_TOO_LARGE")) {
|
|
949
|
+
await sendHttpRequestRejection(req, res, 413, "Payload too large", TWIML_CONTENT_TYPE);
|
|
950
|
+
return true;
|
|
951
|
+
}
|
|
952
|
+
if (isRequestBodyLimitError(error, "REQUEST_BODY_TIMEOUT")) {
|
|
953
|
+
res.setHeader("cache-control", "no-store");
|
|
954
|
+
await sendHttpRequestRejection(req, res, 500, "Internal Server Error", "text/plain; charset=utf-8");
|
|
955
|
+
return true;
|
|
956
|
+
}
|
|
957
|
+
throw error;
|
|
1025
958
|
}
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
959
|
+
assertSmsCredentialOwnerAvailable(params.account);
|
|
960
|
+
if (!params.account.dangerouslyDisableSignatureValidation) {
|
|
961
|
+
if (!verifyTwilioSignature({
|
|
962
|
+
signature: headerValue(req.headers["x-twilio-signature"]),
|
|
963
|
+
url: resolveTwilioWebhookSignatureUrl({
|
|
964
|
+
req,
|
|
965
|
+
publicWebhookUrl: params.account.publicWebhookUrl
|
|
966
|
+
}),
|
|
967
|
+
authToken: params.account.authToken,
|
|
968
|
+
form
|
|
969
|
+
})) {
|
|
970
|
+
if (invalidRequestRateLimited) return rejectInvalidRequestRateLimit({
|
|
971
|
+
key: clientAddressKey,
|
|
972
|
+
log: params.log,
|
|
973
|
+
res
|
|
974
|
+
});
|
|
975
|
+
params.log?.warn?.("SMS webhook rejected invalid Twilio signature");
|
|
976
|
+
respondTwiml(res, 403, "Invalid signature");
|
|
977
|
+
return true;
|
|
978
|
+
}
|
|
1046
979
|
}
|
|
980
|
+
if (invalidRequestRateLimited && params.account.dangerouslyDisableSignatureValidation) return rejectInvalidRequestRateLimit({
|
|
981
|
+
key: clientAddressKey,
|
|
982
|
+
log: params.log,
|
|
983
|
+
res
|
|
984
|
+
});
|
|
985
|
+
} finally {
|
|
986
|
+
preAuthInFlightLimiter.release(preAuthInFlightKey);
|
|
1047
987
|
}
|
|
1048
|
-
if (invalidRequestRateLimited && params.account.dangerouslyDisableSignatureValidation) return rejectInvalidRequestRateLimit({
|
|
1049
|
-
key: clientAddressKey,
|
|
1050
|
-
log: params.log,
|
|
1051
|
-
res
|
|
1052
|
-
});
|
|
1053
988
|
if (isTwilioDeliveryStatusForm(form)) {
|
|
1054
989
|
if (params.account.dangerouslyDisableSignatureValidation && inboundDispatchRateLimiter.isRateLimited(clientAddressKey)) {
|
|
1055
990
|
params.log?.warn?.("SMS webhook callback rate limit exceeded");
|
|
@@ -1176,7 +1111,7 @@ async function registerSmsWebhookRoute(params) {
|
|
|
1176
1111
|
throwOnFailure: true,
|
|
1177
1112
|
log: (msg) => params.log?.info?.(msg),
|
|
1178
1113
|
handler: async (req, res) => {
|
|
1179
|
-
const { tryHandleHostedSmsMediaRequest } = await import("./media-
|
|
1114
|
+
const { tryHandleHostedSmsMediaRequest } = await import("./media-Cle9pp18.js");
|
|
1180
1115
|
if (await tryHandleHostedSmsMediaRequest(req, res, params.account.accountId)) return true;
|
|
1181
1116
|
return await webhookHandler(req, res);
|
|
1182
1117
|
}
|
|
@@ -1512,7 +1447,8 @@ const smsConfigAdapter = createHybridChannelConfigAdapter({
|
|
|
1512
1447
|
"dangerouslyDisableSignatureValidation",
|
|
1513
1448
|
"dmPolicy",
|
|
1514
1449
|
"allowFrom",
|
|
1515
|
-
"textChunkLimit"
|
|
1450
|
+
"textChunkLimit",
|
|
1451
|
+
"mediaMaxMb"
|
|
1516
1452
|
],
|
|
1517
1453
|
resolveAllowFrom: (account) => account.allowFrom,
|
|
1518
1454
|
formatAllowFrom: (allowFrom) => normalizeStringEntries(allowFrom.map((entry) => normalizeSmsAllowFrom(String(entry)))),
|
|
@@ -1745,7 +1681,7 @@ const smsMessageAdapter = defineChannelMessageAdapter({
|
|
|
1745
1681
|
afterSendFailure: async (ctx) => {
|
|
1746
1682
|
if (ctx.kind !== "media") return;
|
|
1747
1683
|
const attemptToken = resolveSmsAttachmentAttemptToken(ctx.attemptToken);
|
|
1748
|
-
if (!attemptToken || attemptToken.platformDispatchStarted) return;
|
|
1684
|
+
if (!attemptToken || attemptToken.platformDispatchStarted && !(ctx.error instanceof PlatformMessageNotDispatchedError)) return;
|
|
1749
1685
|
await attemptToken.attempt.cleanupHostedMedia();
|
|
1750
1686
|
}
|
|
1751
1687
|
},
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { t as getSmsRuntime } from "./runtime-BBlPgBIF.js";
|
|
2
|
-
import { n as TWILIO_MMS_MAX_BYTES } from "./twilio-
|
|
2
|
+
import { h as assertSmsCredentialOwnerAvailable, n as TWILIO_MMS_MAX_BYTES } from "./twilio-J4cwlx0M.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 =
|
|
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 =
|
|
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 =
|
|
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
|
|
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 =
|
|
102
|
-
const TWILIO_API_ERROR_BODY_LIMIT_BYTES =
|
|
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 =
|
|
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 =
|
|
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
|
|
174
|
-
const
|
|
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 =
|
|
300
|
+
this.responseText = redactedResponseText;
|
|
179
301
|
this.twilioCode = parsed.code;
|
|
180
302
|
}
|
|
181
303
|
};
|
|
@@ -251,12 +373,14 @@ function resolveTwilioMessageSid(form) {
|
|
|
251
373
|
async function readTwilioWebhookForm(req) {
|
|
252
374
|
return parseTwilioFormBody(await readRequestBodyWithLimit(req, {
|
|
253
375
|
maxBytes: WEBHOOK_BODY_LIMIT_BYTES,
|
|
254
|
-
timeoutMs: WEBHOOK_BODY_TIMEOUT_MS
|
|
376
|
+
timeoutMs: WEBHOOK_BODY_TIMEOUT_MS,
|
|
377
|
+
destroyOnLimit: false
|
|
255
378
|
}));
|
|
256
379
|
}
|
|
380
|
+
const TWIML_CONTENT_TYPE = "text/xml; charset=utf-8";
|
|
257
381
|
function respondTwiml(res, statusCode, body = "") {
|
|
258
382
|
res.statusCode = statusCode;
|
|
259
|
-
res.setHeader("content-type",
|
|
383
|
+
res.setHeader("content-type", TWIML_CONTENT_TYPE);
|
|
260
384
|
res.end(body || "<Response></Response>");
|
|
261
385
|
}
|
|
262
386
|
function twilioApiUrl(accountSid, path, query) {
|
|
@@ -292,6 +416,13 @@ function normalizeRequestHeaders(headers) {
|
|
|
292
416
|
if (Array.isArray(headers)) return Object.fromEntries(headers.map(([key, value]) => [key, value]));
|
|
293
417
|
return Object.fromEntries(Object.entries(headers));
|
|
294
418
|
}
|
|
419
|
+
function assertTwilioRequestCredentialsAvailable(account) {
|
|
420
|
+
try {
|
|
421
|
+
assertSmsCredentialOwnerAvailable(account);
|
|
422
|
+
} catch (error) {
|
|
423
|
+
throw new PlatformMessageNotDispatchedError(`SMS request stopped before Twilio dispatch: ${formatErrorMessage(error)}`, { cause: error });
|
|
424
|
+
}
|
|
425
|
+
}
|
|
295
426
|
async function requestTwilioApi(params) {
|
|
296
427
|
const init = {
|
|
297
428
|
...params.init,
|
|
@@ -301,6 +432,7 @@ async function requestTwilioApi(params) {
|
|
|
301
432
|
}
|
|
302
433
|
};
|
|
303
434
|
if (params.fetchImpl) {
|
|
435
|
+
assertTwilioRequestCredentialsAvailable(params.account);
|
|
304
436
|
const response = await params.fetchImpl(params.url, init);
|
|
305
437
|
return {
|
|
306
438
|
ok: response.ok,
|
|
@@ -308,9 +440,18 @@ async function requestTwilioApi(params) {
|
|
|
308
440
|
text: await readTwilioApiResponseText(response)
|
|
309
441
|
};
|
|
310
442
|
}
|
|
443
|
+
let requestDispatched = false;
|
|
311
444
|
const guarded = await fetchWithSsrFGuard({
|
|
312
445
|
url: params.url,
|
|
313
446
|
init,
|
|
447
|
+
beforeRequest: () => {
|
|
448
|
+
if (requestDispatched) {
|
|
449
|
+
assertSmsCredentialOwnerAvailable(params.account);
|
|
450
|
+
return;
|
|
451
|
+
}
|
|
452
|
+
assertTwilioRequestCredentialsAvailable(params.account);
|
|
453
|
+
requestDispatched = true;
|
|
454
|
+
},
|
|
314
455
|
auditContext: "sms-twilio-api",
|
|
315
456
|
policy: { allowedHostnames: [params.allowedHostname] },
|
|
316
457
|
requireHttps: true,
|
|
@@ -416,6 +557,7 @@ async function listTwilioMessages(params) {
|
|
|
416
557
|
return parseTwilioListPayload(response.text, "messages", parseTwilioMessageLogEntry);
|
|
417
558
|
}
|
|
418
559
|
async function sendSmsViaTwilio(params) {
|
|
560
|
+
assertSmsCredentialOwnerAvailable(params.account);
|
|
419
561
|
if (!params.account.fromNumber && !params.account.messagingServiceSid) throw new Error("Twilio SMS send requires fromNumber or messagingServiceSid.");
|
|
420
562
|
if (params.text && params.text.length > 1600) throw new Error(`Twilio SMS/MMS Body supports at most ${TWILIO_MESSAGE_BODY_MAX_LENGTH} characters.`);
|
|
421
563
|
const mediaUrls = (params.mediaUrls ?? []).map((url) => url.trim()).filter(Boolean);
|
|
@@ -453,4 +595,4 @@ async function sendSmsViaTwilio(params) {
|
|
|
453
595
|
};
|
|
454
596
|
}
|
|
455
597
|
//#endregion
|
|
456
|
-
export { normalizeSmsAllowFrom as _,
|
|
598
|
+
export { normalizeSmsAllowFrom as C, looksLikeSmsPhoneNumber as S, isSmsAccountConfigured as _, listTwilioIncomingPhoneNumbers as a, resolveSmsAccount as b, resolveTwilioInboundSender as c, respondTwiml as d, retrieveTwilioMessagingService as f, inspectSmsAccount as g, assertSmsCredentialOwnerAvailable as h, buildTwilioInboundMessage as i, resolveTwilioMessageSid as l, verifyTwilioSignature as m, TWILIO_MMS_MAX_BYTES as n, listTwilioMessages as o, sendSmsViaTwilio as p, TWIML_CONTENT_TYPE as r, readTwilioWebhookForm as s, TWILIO_MESSAGE_BODY_MAX_LENGTH as t, resolveTwilioWebhookSignatureUrl as u, listSmsAccountIds as v, normalizeSmsPhoneNumber as w, resolveTwilioStatusCallbackUrl as x, resolveDefaultSmsAccountId as y };
|
package/openclaw.plugin.json
CHANGED
|
@@ -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.9.1
|
|
3
|
+
"version": "2026.9.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.9.1
|
|
126
|
+
"pluginApi": ">=2026.9.1"
|
|
127
127
|
},
|
|
128
128
|
"build": {
|
|
129
|
-
"openclawVersion": "2026.9.1
|
|
129
|
+
"openclawVersion": "2026.9.1",
|
|
130
130
|
"bundledDist": false
|
|
131
131
|
},
|
|
132
132
|
"install": {
|
|
@@ -150,7 +150,7 @@
|
|
|
150
150
|
"README.md"
|
|
151
151
|
],
|
|
152
152
|
"peerDependencies": {
|
|
153
|
-
"openclaw": ">=2026.9.1
|
|
153
|
+
"openclaw": ">=2026.9.1"
|
|
154
154
|
},
|
|
155
155
|
"peerDependenciesMeta": {
|
|
156
156
|
"openclaw": {
|