@theokit/gateway-whatsapp 0.6.0 → 0.8.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.8.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 9d477da: Export a `ChannelDescriptor` with env bindings: `whatsappChannel` (variants `cloud` and `baileys`), `teamsChannel` and `googleChatChannel`, for `createChannels` and `configFromEnv`. The `@theokit/gateway` peer range is now `>=0.20.0 <1.0.0`.
8
+
9
+ ## 0.7.0
10
+
11
+ ### Minor Changes
12
+
13
+ - 2831ca3: Report `capabilities.maxMessageChars` from the splitter limit, and `capabilities.threads` (true for Discord, Telegram and Slack).
14
+
3
15
  ## 0.6.0
4
16
 
5
17
  ### Minor Changes
package/README.md CHANGED
@@ -207,3 +207,37 @@ PUPPETEER_EXECUTABLE_PATH=/usr/bin/google-chrome node your-app.js
207
207
  The bridge spawns without an explicit `env`, so it inherits yours and the variable
208
208
  reaches Puppeteer. `WhatsAppBaileysBackend` needs no browser at all, which is the reason
209
209
  it exists (B-001).
210
+
211
+ ## Capabilities
212
+
213
+ `adapter.capabilities.maxMessageChars` is `4096` (the splitter limit) and `threads` is `false`. See `@theokit/gateway` for the field meanings.
214
+
215
+ ## Channel descriptor
216
+
217
+ `whatsappChannel` describes the channel as data, for `createChannels` and `configFromEnv` from
218
+ `@theokit/gateway`. It has two variants, chosen with `selectVariant(whatsappChannel, name)`; the
219
+ descriptor itself is the `cloud` shape.
220
+
221
+ | Variant | Field | Env | Required | Secret |
222
+ | --- | --- | --- | --- | --- |
223
+ | `cloud` | `accessToken` | `WHATSAPP_ACCESS_TOKEN` | yes | yes |
224
+ | `cloud` | `phoneNumberId` | `WHATSAPP_PHONE_NUMBER_ID` | yes | no |
225
+ | `cloud` | `appSecret` | `WHATSAPP_APP_SECRET` | yes | yes |
226
+ | `cloud` | `verifyToken` | `WHATSAPP_VERIFY_TOKEN` | no | yes |
227
+ | `baileys` | `sessionDir` | `WHATSAPP_SESSION_DIR` | yes | no |
228
+ | `baileys` | `botPhoneId` | `WHATSAPP_BOT_PHONE_ID` | no | no |
229
+ | both | `requireMention` | `WHATSAPP_REQUIRE_MENTION` | no | no |
230
+
231
+ `verifyToken` is not an adapter option: it is kept so the webhook half can answer Meta's
232
+ subscription check.
233
+
234
+ ```ts
235
+ import { configFromEnv, createChannels, selectVariant } from "@theokit/gateway";
236
+ import { whatsappChannel } from "@theokit/gateway-whatsapp";
237
+
238
+ const descriptor = selectVariant(whatsappChannel, "cloud");
239
+ const { config, missing } = configFromEnv(descriptor, process.env, "APP_");
240
+ const { adapters, rejected } = createChannels([{ descriptor, config }]);
241
+ ```
242
+
243
+ `create` refuses a value of the wrong type with `ConfigurationError` (`invalid_config`, naming the key).
package/dist/index.cjs CHANGED
@@ -1868,6 +1868,9 @@ function requireNonEmpty(entries) {
1868
1868
  }
1869
1869
  }
1870
1870
  var WhatsAppAdapter = class _WhatsAppAdapter extends gateway.BasePlatformAdapter {
1871
+ get capabilities() {
1872
+ return { ...super.capabilities, maxMessageChars: WHATSAPP_MAX_TEXT, threads: false };
1873
+ }
1871
1874
  platform = "whatsapp";
1872
1875
  backendImpl;
1873
1876
  /**
@@ -1936,14 +1939,14 @@ var WhatsAppAdapter = class _WhatsAppAdapter extends gateway.BasePlatformAdapter
1936
1939
  * @throws {ConfigurationError} when a required option is missing or empty.
1937
1940
  * @public
1938
1941
  */
1939
- static from(options, common = {}) {
1942
+ static from(options, common2 = {}) {
1940
1943
  switch (options.backend) {
1941
1944
  case "cloud":
1942
- return _WhatsAppAdapter.fromCloud(options.cloud, common);
1945
+ return _WhatsAppAdapter.fromCloud(options.cloud, common2);
1943
1946
  case "web":
1944
- return _WhatsAppAdapter.fromWeb(options.web, common);
1947
+ return _WhatsAppAdapter.fromWeb(options.web, common2);
1945
1948
  case "baileys":
1946
- return _WhatsAppAdapter.fromBaileys(options.baileys, common);
1949
+ return _WhatsAppAdapter.fromBaileys(options.baileys, common2);
1947
1950
  }
1948
1951
  }
1949
1952
  /**
@@ -2192,6 +2195,125 @@ var WhatsAppAdapter = class _WhatsAppAdapter extends gateway.BasePlatformAdapter
2192
2195
  }
2193
2196
  };
2194
2197
 
2198
+ // src/channel.ts
2199
+ function invalid(key, expected) {
2200
+ return new ConfigurationError({
2201
+ code: "invalid_config",
2202
+ message: `gateway-whatsapp: config.${key} must be ${expected}`,
2203
+ detail: key
2204
+ });
2205
+ }
2206
+ function read(config, key, kind) {
2207
+ const value = config[key];
2208
+ if (value === void 0 || value === null || value === "") return void 0;
2209
+ if (kind === "string" && typeof value === "string") return value;
2210
+ if (kind === "boolean" && typeof value === "boolean") return value;
2211
+ if (kind === "boolean" && (value === "true" || value === "false")) return value === "true";
2212
+ throw invalid(key, kind === "string" ? "a string" : 'a boolean or the string "true" or "false"');
2213
+ }
2214
+ function requiredString(config, key) {
2215
+ const value = config[key] === "" ? "" : read(config, key, "string");
2216
+ if (typeof value !== "string") throw invalid(key, "a string");
2217
+ return value;
2218
+ }
2219
+ var REQUIRE_MENTION = {
2220
+ key: "requireMention",
2221
+ required: false,
2222
+ secret: false,
2223
+ env: "WHATSAPP_REQUIRE_MENTION",
2224
+ description: "Whether group messages must mention the bot. Default true."
2225
+ };
2226
+ var CLOUD_CONFIG = [
2227
+ {
2228
+ key: "accessToken",
2229
+ required: true,
2230
+ secret: true,
2231
+ env: "WHATSAPP_ACCESS_TOKEN",
2232
+ description: "The Meta Cloud API access token."
2233
+ },
2234
+ {
2235
+ key: "phoneNumberId",
2236
+ required: true,
2237
+ secret: false,
2238
+ env: "WHATSAPP_PHONE_NUMBER_ID",
2239
+ description: "The Cloud API phone number id the adapter answers for."
2240
+ },
2241
+ {
2242
+ key: "appSecret",
2243
+ required: true,
2244
+ secret: true,
2245
+ env: "WHATSAPP_APP_SECRET",
2246
+ description: "The Meta app secret that signs inbound webhooks."
2247
+ },
2248
+ {
2249
+ key: "verifyToken",
2250
+ required: false,
2251
+ secret: true,
2252
+ env: "WHATSAPP_VERIFY_TOKEN",
2253
+ description: "The token Meta's webhook subscription check sends; not an adapter option, kept so the webhook half can answer it."
2254
+ },
2255
+ REQUIRE_MENTION
2256
+ ];
2257
+ var BAILEYS_CONFIG = [
2258
+ {
2259
+ key: "sessionDir",
2260
+ required: true,
2261
+ secret: false,
2262
+ env: "WHATSAPP_SESSION_DIR",
2263
+ description: "Directory where the Baileys session (credentials) is stored."
2264
+ },
2265
+ {
2266
+ key: "botPhoneId",
2267
+ required: false,
2268
+ secret: false,
2269
+ env: "WHATSAPP_BOT_PHONE_ID",
2270
+ description: "The bot's own number; with requireMention (default), a group message must mention it or is dropped."
2271
+ },
2272
+ REQUIRE_MENTION
2273
+ ];
2274
+ function common(config) {
2275
+ const requireMention = read(config, "requireMention", "boolean");
2276
+ const botPhoneId = read(config, "botPhoneId", "string");
2277
+ return {
2278
+ ...requireMention === void 0 ? {} : { requireMention },
2279
+ ...botPhoneId === void 0 ? {} : { botPhoneId }
2280
+ };
2281
+ }
2282
+ function createCloud(config) {
2283
+ const accessToken = requiredString(config, "accessToken");
2284
+ const phoneNumberId = requiredString(config, "phoneNumberId");
2285
+ const appSecret = requiredString(config, "appSecret");
2286
+ read(config, "verifyToken", "string");
2287
+ const opts = common(config);
2288
+ return WhatsAppAdapter.from(
2289
+ { backend: "cloud", cloud: { accessToken, phoneNumberId, appSecret } },
2290
+ opts
2291
+ );
2292
+ }
2293
+ function createBaileys(config) {
2294
+ const sessionDir = requiredString(config, "sessionDir");
2295
+ const opts = common(config);
2296
+ return WhatsAppAdapter.from({ backend: "baileys", baileys: { sessionDir } }, opts);
2297
+ }
2298
+ var cloudChannel = {
2299
+ platform: "whatsapp",
2300
+ transport: "socket",
2301
+ senderIdentity: "authenticated",
2302
+ config: CLOUD_CONFIG,
2303
+ create: createCloud
2304
+ };
2305
+ var baileysChannel = {
2306
+ platform: "whatsapp",
2307
+ transport: "socket",
2308
+ senderIdentity: "authenticated",
2309
+ config: BAILEYS_CONFIG,
2310
+ create: createBaileys
2311
+ };
2312
+ var whatsappChannel = {
2313
+ ...cloudChannel,
2314
+ variants: { cloud: cloudChannel, baileys: baileysChannel }
2315
+ };
2316
+
2195
2317
  exports.ConfigurationError = ConfigurationError;
2196
2318
  exports.LineBuffer = LineBuffer;
2197
2319
  exports.WhatsAppAdapter = WhatsAppAdapter;
@@ -2213,5 +2335,6 @@ exports.parseWebhookPayload = parseWebhookPayload;
2213
2335
  exports.splitForWhatsApp = splitForWhatsApp;
2214
2336
  exports.verifyWebhookSignature = verifyWebhookSignature;
2215
2337
  exports.verifyWebhookSubscription = verifyWebhookSubscription;
2338
+ exports.whatsappChannel = whatsappChannel;
2216
2339
  //# sourceMappingURL=index.cjs.map
2217
2340
  //# sourceMappingURL=index.cjs.map