@daolmedo/openclaw-twilio-whatsapp 1.1.27 → 1.1.28

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.
Files changed (2) hide show
  1. package/dist/index.js +33 -1
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,6 +1,11 @@
1
1
  // index.ts
2
2
  import { defineChannelPluginEntry } from "openclaw/plugin-sdk/channel-core";
3
3
 
4
+ // src/channel.ts
5
+ import {
6
+ buildChannelOutboundSessionRoute
7
+ } from "openclaw/plugin-sdk/channel-core";
8
+
4
9
  // src/accounts.ts
5
10
  var getTwilioChannelConfig = (cfg) => cfg.channels && cfg.channels["twilio-whatsapp"] ? cfg.channels["twilio-whatsapp"] : void 0;
6
11
  function listTwilioAccountIds(cfg) {
@@ -35,7 +40,10 @@ function findTwilioAccountByPhoneNumber(cfg, phoneNumber) {
35
40
  return void 0;
36
41
  }
37
42
  function normalizePhoneNumber(phone) {
38
- return phone.replace(/^whatsapp:/, "").replace(/\s+/g, "");
43
+ return phone.trim().replace(/^(?:(?:twilio-whatsapp|whatsapp):)+/i, "").replace(/\s+/g, "");
44
+ }
45
+ function looksLikePhoneNumber(phone) {
46
+ return /^\+[1-9]\d{6,14}$/.test(normalizePhoneNumber(phone));
39
47
  }
40
48
 
41
49
  // src/outbound-adapter.ts
@@ -163,6 +171,21 @@ function getRuntimeForPhoneNumber(phoneNumber) {
163
171
  }
164
172
 
165
173
  // src/channel.ts
174
+ function resolveTwilioWhatsappOutboundSessionRoute(params) {
175
+ const to = normalizePhoneNumber(params.resolvedTarget?.to ?? params.target);
176
+ if (!looksLikePhoneNumber(to)) return null;
177
+ return buildChannelOutboundSessionRoute({
178
+ cfg: params.cfg,
179
+ agentId: params.agentId,
180
+ channel: "twilio-whatsapp",
181
+ accountId: params.accountId,
182
+ recipientSessionExact: true,
183
+ peer: { kind: "direct", id: to },
184
+ chatType: "direct",
185
+ from: `whatsapp:${to}`,
186
+ to: `whatsapp:${to}`
187
+ });
188
+ }
166
189
  var twilioWhatsappPlugin = {
167
190
  id: "twilio-whatsapp",
168
191
  meta: {
@@ -196,6 +219,15 @@ var twilioWhatsappPlugin = {
196
219
  return listTwilioAccountIds(cfg).length > 0;
197
220
  }
198
221
  },
222
+ messaging: {
223
+ targetPrefixes: ["whatsapp"],
224
+ normalizeTarget: normalizePhoneNumber,
225
+ resolveOutboundSessionRoute: resolveTwilioWhatsappOutboundSessionRoute,
226
+ targetResolver: {
227
+ looksLikeId: (raw, normalized) => looksLikePhoneNumber(normalized ?? raw),
228
+ hint: "<+15551234567>"
229
+ }
230
+ },
199
231
  outbound: twilioWhatsappOutbound,
200
232
  message: twilioWhatsappMessageAdapter,
201
233
  gateway: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@daolmedo/openclaw-twilio-whatsapp",
3
- "version": "1.1.27",
3
+ "version": "1.1.28",
4
4
  "description": "Twilio WhatsApp channel plugin for OpenClaw (Cody ISV)",
5
5
  "type": "module",
6
6
  "engines": {