@openclaw/sms 2026.6.11 → 2026.6.34
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/channel-plugin-api.js +129 -37
- package/npm-shrinkwrap.json +2 -2
- package/package.json +4 -4
|
@@ -6,14 +6,15 @@ import { createMessageReceiptFromOutboundResults, defineChannelMessageAdapter, w
|
|
|
6
6
|
import { createConditionalWarningCollector } from "openclaw/plugin-sdk/channel-policy";
|
|
7
7
|
import { createEmptyChannelDirectoryAdapter } from "openclaw/plugin-sdk/directory-runtime";
|
|
8
8
|
import { normalizeStringEntries } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
9
|
-
import { chunkTextForOutbound, stripMarkdown } from "openclaw/plugin-sdk/text-chunking";
|
|
9
|
+
import { chunkTextForOutbound, sanitizeAssistantVisibleText, stripMarkdown } from "openclaw/plugin-sdk/text-chunking";
|
|
10
10
|
import { DEFAULT_ACCOUNT_ID as DEFAULT_ACCOUNT_ID$1, listCombinedAccountIds, resolveAccountEntry, resolveListedDefaultAccountId, resolveMergedAccountConfig } from "openclaw/plugin-sdk/account-resolution";
|
|
11
11
|
import { parseStrictInteger } from "openclaw/plugin-sdk/number-runtime";
|
|
12
12
|
import { buildSecretInputSchema, hasConfiguredSecretInput, normalizeResolvedSecretInputString } from "openclaw/plugin-sdk/secret-input";
|
|
13
13
|
import { AllowFromListSchema, DmPolicySchema, buildChannelConfigSchema, requireOpenAllowFrom } from "openclaw/plugin-sdk/channel-config-primitives";
|
|
14
14
|
import { requireChannelOpenAllowFrom } from "openclaw/plugin-sdk/extension-shared";
|
|
15
15
|
import { z } from "zod";
|
|
16
|
-
import { createFixedWindowRateLimiter, readRequestBodyWithLimit, registerPluginHttpRoute } from "openclaw/plugin-sdk/webhook-ingress";
|
|
16
|
+
import { createFixedWindowRateLimiter, readRequestBodyWithLimit, registerPluginHttpRoute, resolveRequestClientIp } from "openclaw/plugin-sdk/webhook-ingress";
|
|
17
|
+
import { performance } from "node:perf_hooks";
|
|
17
18
|
import { resolveStableChannelMessageIngress } from "openclaw/plugin-sdk/channel-ingress-runtime";
|
|
18
19
|
import { createChannelPairingChallengeIssuer } from "openclaw/plugin-sdk/channel-pairing";
|
|
19
20
|
import { createHmac, timingSafeEqual } from "node:crypto";
|
|
@@ -262,17 +263,16 @@ function requestSearch(req) {
|
|
|
262
263
|
return "";
|
|
263
264
|
}
|
|
264
265
|
}
|
|
265
|
-
function
|
|
266
|
+
function stripUrlFragment(url) {
|
|
266
267
|
const hashIndex = url.indexOf("#");
|
|
267
|
-
return
|
|
268
|
+
return hashIndex === -1 ? url : url.slice(0, hashIndex);
|
|
268
269
|
}
|
|
269
270
|
function resolveTwilioWebhookSignatureUrl(params) {
|
|
270
|
-
|
|
271
|
+
const signatureBaseUrl = stripUrlFragment(params.publicWebhookUrl);
|
|
272
|
+
if (signatureBaseUrl.includes("?")) return signatureBaseUrl;
|
|
271
273
|
const search = requestSearch(params.req);
|
|
272
|
-
if (!search) return
|
|
273
|
-
|
|
274
|
-
if (hashIndex === -1) return `${params.publicWebhookUrl}${search}`;
|
|
275
|
-
return `${params.publicWebhookUrl.slice(0, hashIndex)}${search}${params.publicWebhookUrl.slice(hashIndex)}`;
|
|
274
|
+
if (!search) return signatureBaseUrl;
|
|
275
|
+
return `${signatureBaseUrl}${search}`;
|
|
276
276
|
}
|
|
277
277
|
var TwilioSmsApiError = class extends Error {
|
|
278
278
|
constructor(httpStatus, responseText, operation = "send") {
|
|
@@ -538,7 +538,7 @@ async function sendSmsViaTwilio(params) {
|
|
|
538
538
|
//#endregion
|
|
539
539
|
//#region extensions/sms/src/send.ts
|
|
540
540
|
function toSmsPlainText(text) {
|
|
541
|
-
return stripMarkdown(text.replace(/```[^\n]*\n?([\s\S]*?)```/g, (_match, body) => body.trim()).replace(/\[([^\]]+)\]\((https?:\/\/[^)\s]+)\)/g, (_match, label, url) => {
|
|
541
|
+
return stripMarkdown(sanitizeAssistantVisibleText(text).replace(/```[^\n]*\n?([\s\S]*?)```/g, (_match, body) => body.trim()).replace(/\[([^\]]+)\]\((https?:\/\/[^)\s]+)\)/g, (_match, label, url) => {
|
|
542
542
|
const cleanLabel = label.trim();
|
|
543
543
|
const cleanUrl = url.trim();
|
|
544
544
|
return cleanLabel && cleanLabel !== cleanUrl ? `${cleanLabel} (${cleanUrl})` : cleanUrl;
|
|
@@ -561,6 +561,7 @@ async function sendSmsTextChunks(params) {
|
|
|
561
561
|
//#region extensions/sms/src/inbound.ts
|
|
562
562
|
const CHANNEL_ID$2 = "sms";
|
|
563
563
|
async function authorizeSmsSender(params) {
|
|
564
|
+
const commandRequested = params.channelRuntime.commands.shouldComputeCommandAuthorized(params.rawBody, params.cfg);
|
|
564
565
|
return await resolveStableChannelMessageIngress({
|
|
565
566
|
channelId: CHANNEL_ID$2,
|
|
566
567
|
accountId: params.account.accountId,
|
|
@@ -580,7 +581,11 @@ async function authorizeSmsSender(params) {
|
|
|
580
581
|
},
|
|
581
582
|
event: { mayPair: true },
|
|
582
583
|
dmPolicy: params.account.dmPolicy,
|
|
583
|
-
allowFrom: params.account.allowFrom
|
|
584
|
+
allowFrom: params.account.allowFrom,
|
|
585
|
+
command: commandRequested ? {
|
|
586
|
+
cfg: params.cfg,
|
|
587
|
+
modeWhenAccessGroupsOff: "configured"
|
|
588
|
+
} : void 0
|
|
584
589
|
});
|
|
585
590
|
}
|
|
586
591
|
async function issueSmsPairingChallenge(params) {
|
|
@@ -615,7 +620,8 @@ async function dispatchSmsInboundEvent(params) {
|
|
|
615
620
|
cfg: params.cfg,
|
|
616
621
|
account: params.account,
|
|
617
622
|
channelRuntime: params.channelRuntime,
|
|
618
|
-
from
|
|
623
|
+
from,
|
|
624
|
+
rawBody: params.msg.body
|
|
619
625
|
});
|
|
620
626
|
if (!auth.senderAccess.allowed) {
|
|
621
627
|
if (auth.senderAccess.decision === "pairing") {
|
|
@@ -640,6 +646,9 @@ async function dispatchSmsInboundEvent(params) {
|
|
|
640
646
|
}
|
|
641
647
|
});
|
|
642
648
|
const sessionKey = route.sessionKey;
|
|
649
|
+
const commandRequested = auth.commandAccess.requested;
|
|
650
|
+
const commandAuthorized = auth.commandAccess.authorized;
|
|
651
|
+
const isTextCommand = params.channelRuntime.commands.isControlCommandMessage(params.msg.body, params.cfg);
|
|
643
652
|
await params.channelRuntime.inbound.run({
|
|
644
653
|
channel: CHANNEL_ID$2,
|
|
645
654
|
accountId: params.account.accountId,
|
|
@@ -680,8 +689,15 @@ async function dispatchSmsInboundEvent(params) {
|
|
|
680
689
|
commandBody: input.textForCommands,
|
|
681
690
|
bodyForAgent: input.textForAgent
|
|
682
691
|
},
|
|
692
|
+
access: commandRequested ? { commands: { authorized: commandAuthorized } } : void 0,
|
|
693
|
+
command: isTextCommand ? {
|
|
694
|
+
kind: "text-slash",
|
|
695
|
+
body: input.textForCommands,
|
|
696
|
+
authorized: commandAuthorized
|
|
697
|
+
} : void 0,
|
|
683
698
|
extra: {
|
|
684
699
|
MessageSid: params.msg.messageSid,
|
|
700
|
+
SenderE164: from,
|
|
685
701
|
To: params.msg.to
|
|
686
702
|
}
|
|
687
703
|
});
|
|
@@ -719,48 +735,94 @@ async function dispatchSmsInboundEvent(params) {
|
|
|
719
735
|
}
|
|
720
736
|
//#endregion
|
|
721
737
|
//#region extensions/sms/src/webhook.ts
|
|
722
|
-
const
|
|
723
|
-
|
|
738
|
+
const INVALID_REQUEST_MAX_REQUESTS = 300;
|
|
739
|
+
const CALLBACK_DISPATCH_MAX_REQUESTS = 30;
|
|
740
|
+
const invalidRequestRateLimiter = createFixedWindowRateLimiter({
|
|
741
|
+
maxRequests: INVALID_REQUEST_MAX_REQUESTS,
|
|
742
|
+
windowMs: 6e4,
|
|
743
|
+
maxTrackedKeys: 5e3
|
|
744
|
+
});
|
|
745
|
+
const callbackDispatchRateLimiter = createFixedWindowRateLimiter({
|
|
746
|
+
maxRequests: CALLBACK_DISPATCH_MAX_REQUESTS,
|
|
724
747
|
windowMs: 6e4,
|
|
725
748
|
maxTrackedKeys: 5e3
|
|
726
749
|
});
|
|
727
750
|
const REPLAY_CACHE_TTL_MS = 10 * 6e4;
|
|
728
751
|
const REPLAY_CACHE_MAX_KEYS = 1e4;
|
|
729
|
-
const
|
|
752
|
+
const replayGuardsByAccount = /* @__PURE__ */ new Map();
|
|
753
|
+
function createSmsWebhookReplayGuard(options = {}) {
|
|
754
|
+
const ttlMs = options.ttlMs ?? REPLAY_CACHE_TTL_MS;
|
|
755
|
+
const maxKeys = options.maxKeys ?? REPLAY_CACHE_MAX_KEYS;
|
|
756
|
+
const now = options.now ?? (() => performance.now());
|
|
757
|
+
const entries = /* @__PURE__ */ new Map();
|
|
758
|
+
const pruneExpired = (nowMs) => {
|
|
759
|
+
for (const [key, expiresAt] of entries) {
|
|
760
|
+
if (expiresAt > nowMs) break;
|
|
761
|
+
entries.delete(key);
|
|
762
|
+
}
|
|
763
|
+
};
|
|
764
|
+
return { remember: (messageSid) => {
|
|
765
|
+
const nowMs = now();
|
|
766
|
+
pruneExpired(nowMs);
|
|
767
|
+
if (entries.has(messageSid)) return { kind: "replayed" };
|
|
768
|
+
if (entries.size >= maxKeys) {
|
|
769
|
+
const oldestExpiresAt = entries.values().next().value ?? nowMs;
|
|
770
|
+
return {
|
|
771
|
+
kind: "saturated",
|
|
772
|
+
retryAfterMs: Math.max(0, oldestExpiresAt - nowMs)
|
|
773
|
+
};
|
|
774
|
+
}
|
|
775
|
+
entries.set(messageSid, nowMs + ttlMs);
|
|
776
|
+
return { kind: "accepted" };
|
|
777
|
+
} };
|
|
778
|
+
}
|
|
779
|
+
function resolveSmsWebhookReplayGuard(account) {
|
|
780
|
+
const key = `${account.accountId}\0${account.accountSid}`;
|
|
781
|
+
const existing = replayGuardsByAccount.get(key);
|
|
782
|
+
if (existing) return existing;
|
|
783
|
+
const created = createSmsWebhookReplayGuard();
|
|
784
|
+
replayGuardsByAccount.set(key, created);
|
|
785
|
+
return created;
|
|
786
|
+
}
|
|
730
787
|
function headerValue(value) {
|
|
731
788
|
if (Array.isArray(value)) return value[0];
|
|
732
789
|
return value;
|
|
733
790
|
}
|
|
734
|
-
function
|
|
735
|
-
return req.socket?.remoteAddress ?? "unknown";
|
|
791
|
+
function resolvedClientAddress(params) {
|
|
792
|
+
return resolveRequestClientIp(params.req, params.cfg.gateway?.trustedProxies, params.cfg.gateway?.allowRealIpFallback === true) ?? params.req.socket?.remoteAddress ?? "unknown";
|
|
736
793
|
}
|
|
737
|
-
function
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
const key = `${params.accountId}:${params.messageSid}`;
|
|
744
|
-
if ((replayCache.get(key) ?? 0) > now) return false;
|
|
745
|
-
replayCache.set(key, now + REPLAY_CACHE_TTL_MS);
|
|
794
|
+
function rateLimitKey(params) {
|
|
795
|
+
return `${params.account.accountId}:${params.account.webhookPath}:${params.clientAddress}`;
|
|
796
|
+
}
|
|
797
|
+
function rejectInvalidRequestRateLimit(params) {
|
|
798
|
+
params.log?.warn?.(`SMS webhook invalid-request rate limit exceeded for ${params.key}`);
|
|
799
|
+
respondTwiml(params.res, 429, "Rate limit exceeded");
|
|
746
800
|
return true;
|
|
747
801
|
}
|
|
748
|
-
function createSmsWebhookHandler(params) {
|
|
802
|
+
function createSmsWebhookHandler(params, webhookReplayGuard = resolveSmsWebhookReplayGuard(params.account)) {
|
|
749
803
|
return async (req, res) => {
|
|
750
804
|
if (req.method !== "POST") {
|
|
751
805
|
respondTwiml(res, 405, "Method not allowed");
|
|
752
806
|
return true;
|
|
753
807
|
}
|
|
754
|
-
const
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
808
|
+
const clientAddress = resolvedClientAddress({
|
|
809
|
+
cfg: params.cfg,
|
|
810
|
+
req
|
|
811
|
+
});
|
|
812
|
+
const key = rateLimitKey({
|
|
813
|
+
account: params.account,
|
|
814
|
+
clientAddress
|
|
815
|
+
});
|
|
816
|
+
const invalidRequestRateLimited = invalidRequestRateLimiter.isRateLimited(key);
|
|
760
817
|
let form;
|
|
761
818
|
try {
|
|
762
819
|
form = await readTwilioWebhookForm(req);
|
|
763
820
|
} catch {
|
|
821
|
+
if (invalidRequestRateLimited) return rejectInvalidRequestRateLimit({
|
|
822
|
+
key,
|
|
823
|
+
log: params.log,
|
|
824
|
+
res
|
|
825
|
+
});
|
|
764
826
|
respondTwiml(res, 400, "Invalid request body");
|
|
765
827
|
return true;
|
|
766
828
|
}
|
|
@@ -774,6 +836,11 @@ function createSmsWebhookHandler(params) {
|
|
|
774
836
|
authToken: params.account.authToken,
|
|
775
837
|
form
|
|
776
838
|
})) {
|
|
839
|
+
if (invalidRequestRateLimited) return rejectInvalidRequestRateLimit({
|
|
840
|
+
key,
|
|
841
|
+
log: params.log,
|
|
842
|
+
res
|
|
843
|
+
});
|
|
777
844
|
params.log?.warn?.("SMS webhook rejected invalid Twilio signature");
|
|
778
845
|
respondTwiml(res, 403, "Invalid signature");
|
|
779
846
|
return true;
|
|
@@ -781,22 +848,47 @@ function createSmsWebhookHandler(params) {
|
|
|
781
848
|
}
|
|
782
849
|
const msg = buildTwilioInboundMessage(form);
|
|
783
850
|
if (!msg) {
|
|
851
|
+
if (invalidRequestRateLimited) return rejectInvalidRequestRateLimit({
|
|
852
|
+
key,
|
|
853
|
+
log: params.log,
|
|
854
|
+
res
|
|
855
|
+
});
|
|
784
856
|
respondTwiml(res, 400, "Missing SMS payload");
|
|
785
857
|
return true;
|
|
786
858
|
}
|
|
787
859
|
if (msg.accountSid && msg.accountSid !== params.account.accountSid) {
|
|
860
|
+
if (invalidRequestRateLimited) return rejectInvalidRequestRateLimit({
|
|
861
|
+
key,
|
|
862
|
+
log: params.log,
|
|
863
|
+
res
|
|
864
|
+
});
|
|
788
865
|
params.log?.warn?.("SMS webhook rejected mismatched Twilio AccountSid");
|
|
789
866
|
respondTwiml(res, 403, "Invalid account");
|
|
790
867
|
return true;
|
|
791
868
|
}
|
|
792
|
-
if (
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
869
|
+
if (invalidRequestRateLimited && params.account.dangerouslyDisableSignatureValidation) return rejectInvalidRequestRateLimit({
|
|
870
|
+
key,
|
|
871
|
+
log: params.log,
|
|
872
|
+
res
|
|
873
|
+
});
|
|
874
|
+
if (callbackDispatchRateLimiter.isRateLimited(key)) {
|
|
875
|
+
params.log?.warn?.(`SMS webhook rate limit exceeded for ${key}`);
|
|
876
|
+
respondTwiml(res, 429, "Rate limit exceeded");
|
|
877
|
+
return true;
|
|
878
|
+
}
|
|
879
|
+
const replayDecision = webhookReplayGuard.remember(msg.messageSid);
|
|
880
|
+
if (replayDecision.kind === "replayed") {
|
|
796
881
|
params.log?.warn?.(`SMS webhook ignored replayed message ${msg.messageSid}`);
|
|
797
882
|
respondTwiml(res, 200);
|
|
798
883
|
return true;
|
|
799
884
|
}
|
|
885
|
+
if (replayDecision.kind === "saturated") {
|
|
886
|
+
const retryAfterSeconds = Math.max(1, Math.ceil(replayDecision.retryAfterMs / 1e3));
|
|
887
|
+
params.log?.warn?.("SMS webhook replay cache is full of unexpired message SIDs");
|
|
888
|
+
res.setHeader("Retry-After", String(retryAfterSeconds));
|
|
889
|
+
respondTwiml(res, 429, "Replay cache saturated");
|
|
890
|
+
return true;
|
|
891
|
+
}
|
|
800
892
|
dispatchSmsInboundEvent({
|
|
801
893
|
cfg: params.cfg,
|
|
802
894
|
account: params.account,
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openclaw/sms",
|
|
3
|
-
"version": "2026.6.
|
|
3
|
+
"version": "2026.6.34",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@openclaw/sms",
|
|
9
|
-
"version": "2026.6.
|
|
9
|
+
"version": "2026.6.34",
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"zod": "4.4.3"
|
|
12
12
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openclaw/sms",
|
|
3
|
-
"version": "2026.6.
|
|
3
|
+
"version": "2026.6.34",
|
|
4
4
|
"description": "OpenClaw SMS channel plugin for Twilio text messages.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -26,10 +26,10 @@
|
|
|
26
26
|
"quickstartAllowFrom": true
|
|
27
27
|
},
|
|
28
28
|
"compat": {
|
|
29
|
-
"pluginApi": ">=2026.6.
|
|
29
|
+
"pluginApi": ">=2026.6.34"
|
|
30
30
|
},
|
|
31
31
|
"build": {
|
|
32
|
-
"openclawVersion": "2026.6.
|
|
32
|
+
"openclawVersion": "2026.6.34",
|
|
33
33
|
"bundledDist": false
|
|
34
34
|
},
|
|
35
35
|
"install": {
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"README.md"
|
|
55
55
|
],
|
|
56
56
|
"peerDependencies": {
|
|
57
|
-
"openclaw": ">=2026.6.
|
|
57
|
+
"openclaw": ">=2026.6.34"
|
|
58
58
|
},
|
|
59
59
|
"peerDependenciesMeta": {
|
|
60
60
|
"openclaw": {
|