@theokit/gateway-whatsapp 0.7.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/dist/index.d.cts CHANGED
@@ -1289,6 +1289,62 @@ declare class LineBuffer {
1289
1289
  get pending(): string;
1290
1290
  }
1291
1291
 
1292
+ /**
1293
+ * `whatsappChannel` — the WhatsApp channel described as data.
1294
+ *
1295
+ * Typed locally on purpose: this package declares `@theokit/gateway` as a peer, and a published
1296
+ * `.d.ts` naming a core type an older release lacks would break a consumer on that floor. The object
1297
+ * is structurally a `ChannelDescriptor`; the integration package assigns it to one.
1298
+ *
1299
+ * Two variants pick the backend: `cloud` (Meta Cloud API) and `baileys` (WhatsApp Web multi-device).
1300
+ * The parent descriptor itself describes the cloud shape; `selectVariant(whatsappChannel, "baileys")`
1301
+ * picks the other.
1302
+ */
1303
+
1304
+ type Config = Readonly<Record<string, unknown>>;
1305
+ /** One configuration field, shaped like the core's `ChannelConfigField` (typed locally). */
1306
+ interface ConfigField {
1307
+ readonly key: string;
1308
+ readonly required: boolean;
1309
+ readonly secret: boolean;
1310
+ readonly description: string;
1311
+ readonly env?: string;
1312
+ }
1313
+ declare function createCloud(config: Config): WhatsAppAdapter;
1314
+ declare function createBaileys(config: Config): WhatsAppAdapter;
1315
+ /**
1316
+ * The WhatsApp channel. The descriptor itself is the `cloud` shape; `variants.cloud` and
1317
+ * `variants.baileys` are the two backends, chosen with `selectVariant`.
1318
+ *
1319
+ * `create` refuses a value of the wrong type with this package's `ConfigurationError`
1320
+ * (`invalid_config`) and performs no network call.
1321
+ *
1322
+ * @public
1323
+ */
1324
+ declare const whatsappChannel: {
1325
+ variants: {
1326
+ cloud: {
1327
+ platform: "whatsapp";
1328
+ transport: "socket";
1329
+ senderIdentity: "authenticated";
1330
+ config: readonly ConfigField[];
1331
+ create: typeof createCloud;
1332
+ };
1333
+ baileys: {
1334
+ platform: "whatsapp";
1335
+ transport: "socket";
1336
+ senderIdentity: "authenticated";
1337
+ config: readonly ConfigField[];
1338
+ create: typeof createBaileys;
1339
+ };
1340
+ };
1341
+ platform: "whatsapp";
1342
+ transport: "socket";
1343
+ senderIdentity: "authenticated";
1344
+ config: readonly ConfigField[];
1345
+ create: typeof createCloud;
1346
+ };
1347
+
1292
1348
  /**
1293
1349
  * Per-backend HTTP/IPC error → canonical `WhatsAppSendResult.error` shape.
1294
1350
  *
@@ -1365,4 +1421,4 @@ declare function mapWhatsAppWebError(ipcError: string | undefined): ErrorPayload
1365
1421
  /** Split `text` into chunks of at most `WHATSAPP_MAX_TEXT` characters. */
1366
1422
  declare function splitForWhatsApp(text: string): string[];
1367
1423
 
1368
- export { type BaileysSocketFactory, type BaileysSocketLike, type BaileysSocketOptions, ConfigurationError, type ConfigurationErrorOptions, type IpcCommand, type IpcEvent, LineBuffer, type MetaTemplateComponent, type MetaWebhookEnvelope, WhatsAppAdapter, type WhatsAppAdapterCommonOptions, type WhatsAppAdapterOptions, type WhatsAppBackend, WhatsAppBaileysBackend, type WhatsAppBaileysBackendOptions, type WhatsAppBaileysConfig, WhatsAppBridgeError, WhatsAppCloudBackend, type WhatsAppCloudBackendOptions, type WhatsAppCloudConfig, WhatsAppConnectTimeoutError, type WhatsAppInboundEvent, type WhatsAppOutboundMessage, type WhatsAppPairingState, type WhatsAppSendResult, type WhatsAppStatusReceipt, WhatsAppWebBackend, type WhatsAppWebBackendOptions, type WhatsAppWebConfig, createBaileysSocket, defaultBridgeScriptPath, digitsOnly, formatCommand, mapWhatsAppCloudError, mapWhatsAppWebError, normalizeInboundMessages, normalizeStatusReceipts, parseEvent, parseWebhookPayload, splitForWhatsApp, verifyWebhookSignature, verifyWebhookSubscription };
1424
+ export { type BaileysSocketFactory, type BaileysSocketLike, type BaileysSocketOptions, ConfigurationError, type ConfigurationErrorOptions, type IpcCommand, type IpcEvent, LineBuffer, type MetaTemplateComponent, type MetaWebhookEnvelope, WhatsAppAdapter, type WhatsAppAdapterCommonOptions, type WhatsAppAdapterOptions, type WhatsAppBackend, WhatsAppBaileysBackend, type WhatsAppBaileysBackendOptions, type WhatsAppBaileysConfig, WhatsAppBridgeError, WhatsAppCloudBackend, type WhatsAppCloudBackendOptions, type WhatsAppCloudConfig, WhatsAppConnectTimeoutError, type WhatsAppInboundEvent, type WhatsAppOutboundMessage, type WhatsAppPairingState, type WhatsAppSendResult, type WhatsAppStatusReceipt, WhatsAppWebBackend, type WhatsAppWebBackendOptions, type WhatsAppWebConfig, createBaileysSocket, defaultBridgeScriptPath, digitsOnly, formatCommand, mapWhatsAppCloudError, mapWhatsAppWebError, normalizeInboundMessages, normalizeStatusReceipts, parseEvent, parseWebhookPayload, splitForWhatsApp, verifyWebhookSignature, verifyWebhookSubscription, whatsappChannel };
package/dist/index.d.ts CHANGED
@@ -1289,6 +1289,62 @@ declare class LineBuffer {
1289
1289
  get pending(): string;
1290
1290
  }
1291
1291
 
1292
+ /**
1293
+ * `whatsappChannel` — the WhatsApp channel described as data.
1294
+ *
1295
+ * Typed locally on purpose: this package declares `@theokit/gateway` as a peer, and a published
1296
+ * `.d.ts` naming a core type an older release lacks would break a consumer on that floor. The object
1297
+ * is structurally a `ChannelDescriptor`; the integration package assigns it to one.
1298
+ *
1299
+ * Two variants pick the backend: `cloud` (Meta Cloud API) and `baileys` (WhatsApp Web multi-device).
1300
+ * The parent descriptor itself describes the cloud shape; `selectVariant(whatsappChannel, "baileys")`
1301
+ * picks the other.
1302
+ */
1303
+
1304
+ type Config = Readonly<Record<string, unknown>>;
1305
+ /** One configuration field, shaped like the core's `ChannelConfigField` (typed locally). */
1306
+ interface ConfigField {
1307
+ readonly key: string;
1308
+ readonly required: boolean;
1309
+ readonly secret: boolean;
1310
+ readonly description: string;
1311
+ readonly env?: string;
1312
+ }
1313
+ declare function createCloud(config: Config): WhatsAppAdapter;
1314
+ declare function createBaileys(config: Config): WhatsAppAdapter;
1315
+ /**
1316
+ * The WhatsApp channel. The descriptor itself is the `cloud` shape; `variants.cloud` and
1317
+ * `variants.baileys` are the two backends, chosen with `selectVariant`.
1318
+ *
1319
+ * `create` refuses a value of the wrong type with this package's `ConfigurationError`
1320
+ * (`invalid_config`) and performs no network call.
1321
+ *
1322
+ * @public
1323
+ */
1324
+ declare const whatsappChannel: {
1325
+ variants: {
1326
+ cloud: {
1327
+ platform: "whatsapp";
1328
+ transport: "socket";
1329
+ senderIdentity: "authenticated";
1330
+ config: readonly ConfigField[];
1331
+ create: typeof createCloud;
1332
+ };
1333
+ baileys: {
1334
+ platform: "whatsapp";
1335
+ transport: "socket";
1336
+ senderIdentity: "authenticated";
1337
+ config: readonly ConfigField[];
1338
+ create: typeof createBaileys;
1339
+ };
1340
+ };
1341
+ platform: "whatsapp";
1342
+ transport: "socket";
1343
+ senderIdentity: "authenticated";
1344
+ config: readonly ConfigField[];
1345
+ create: typeof createCloud;
1346
+ };
1347
+
1292
1348
  /**
1293
1349
  * Per-backend HTTP/IPC error → canonical `WhatsAppSendResult.error` shape.
1294
1350
  *
@@ -1365,4 +1421,4 @@ declare function mapWhatsAppWebError(ipcError: string | undefined): ErrorPayload
1365
1421
  /** Split `text` into chunks of at most `WHATSAPP_MAX_TEXT` characters. */
1366
1422
  declare function splitForWhatsApp(text: string): string[];
1367
1423
 
1368
- export { type BaileysSocketFactory, type BaileysSocketLike, type BaileysSocketOptions, ConfigurationError, type ConfigurationErrorOptions, type IpcCommand, type IpcEvent, LineBuffer, type MetaTemplateComponent, type MetaWebhookEnvelope, WhatsAppAdapter, type WhatsAppAdapterCommonOptions, type WhatsAppAdapterOptions, type WhatsAppBackend, WhatsAppBaileysBackend, type WhatsAppBaileysBackendOptions, type WhatsAppBaileysConfig, WhatsAppBridgeError, WhatsAppCloudBackend, type WhatsAppCloudBackendOptions, type WhatsAppCloudConfig, WhatsAppConnectTimeoutError, type WhatsAppInboundEvent, type WhatsAppOutboundMessage, type WhatsAppPairingState, type WhatsAppSendResult, type WhatsAppStatusReceipt, WhatsAppWebBackend, type WhatsAppWebBackendOptions, type WhatsAppWebConfig, createBaileysSocket, defaultBridgeScriptPath, digitsOnly, formatCommand, mapWhatsAppCloudError, mapWhatsAppWebError, normalizeInboundMessages, normalizeStatusReceipts, parseEvent, parseWebhookPayload, splitForWhatsApp, verifyWebhookSignature, verifyWebhookSubscription };
1424
+ export { type BaileysSocketFactory, type BaileysSocketLike, type BaileysSocketOptions, ConfigurationError, type ConfigurationErrorOptions, type IpcCommand, type IpcEvent, LineBuffer, type MetaTemplateComponent, type MetaWebhookEnvelope, WhatsAppAdapter, type WhatsAppAdapterCommonOptions, type WhatsAppAdapterOptions, type WhatsAppBackend, WhatsAppBaileysBackend, type WhatsAppBaileysBackendOptions, type WhatsAppBaileysConfig, WhatsAppBridgeError, WhatsAppCloudBackend, type WhatsAppCloudBackendOptions, type WhatsAppCloudConfig, WhatsAppConnectTimeoutError, type WhatsAppInboundEvent, type WhatsAppOutboundMessage, type WhatsAppPairingState, type WhatsAppSendResult, type WhatsAppStatusReceipt, WhatsAppWebBackend, type WhatsAppWebBackendOptions, type WhatsAppWebConfig, createBaileysSocket, defaultBridgeScriptPath, digitsOnly, formatCommand, mapWhatsAppCloudError, mapWhatsAppWebError, normalizeInboundMessages, normalizeStatusReceipts, parseEvent, parseWebhookPayload, splitForWhatsApp, verifyWebhookSignature, verifyWebhookSubscription, whatsappChannel };
package/dist/index.js CHANGED
@@ -1915,14 +1915,14 @@ var WhatsAppAdapter = class _WhatsAppAdapter extends BasePlatformAdapter {
1915
1915
  * @throws {ConfigurationError} when a required option is missing or empty.
1916
1916
  * @public
1917
1917
  */
1918
- static from(options, common = {}) {
1918
+ static from(options, common2 = {}) {
1919
1919
  switch (options.backend) {
1920
1920
  case "cloud":
1921
- return _WhatsAppAdapter.fromCloud(options.cloud, common);
1921
+ return _WhatsAppAdapter.fromCloud(options.cloud, common2);
1922
1922
  case "web":
1923
- return _WhatsAppAdapter.fromWeb(options.web, common);
1923
+ return _WhatsAppAdapter.fromWeb(options.web, common2);
1924
1924
  case "baileys":
1925
- return _WhatsAppAdapter.fromBaileys(options.baileys, common);
1925
+ return _WhatsAppAdapter.fromBaileys(options.baileys, common2);
1926
1926
  }
1927
1927
  }
1928
1928
  /**
@@ -2171,6 +2171,125 @@ var WhatsAppAdapter = class _WhatsAppAdapter extends BasePlatformAdapter {
2171
2171
  }
2172
2172
  };
2173
2173
 
2174
- export { ConfigurationError, LineBuffer, WhatsAppAdapter, WhatsAppBaileysBackend, WhatsAppBridgeError, WhatsAppCloudBackend, WhatsAppConnectTimeoutError, WhatsAppWebBackend, createBaileysSocket, defaultBridgeScriptPath, digitsOnly, formatCommand, mapWhatsAppCloudError, mapWhatsAppWebError, normalizeInboundMessages, normalizeStatusReceipts, parseEvent, parseWebhookPayload, splitForWhatsApp, verifyWebhookSignature, verifyWebhookSubscription };
2174
+ // src/channel.ts
2175
+ function invalid(key, expected) {
2176
+ return new ConfigurationError({
2177
+ code: "invalid_config",
2178
+ message: `gateway-whatsapp: config.${key} must be ${expected}`,
2179
+ detail: key
2180
+ });
2181
+ }
2182
+ function read(config, key, kind) {
2183
+ const value = config[key];
2184
+ if (value === void 0 || value === null || value === "") return void 0;
2185
+ if (kind === "string" && typeof value === "string") return value;
2186
+ if (kind === "boolean" && typeof value === "boolean") return value;
2187
+ if (kind === "boolean" && (value === "true" || value === "false")) return value === "true";
2188
+ throw invalid(key, kind === "string" ? "a string" : 'a boolean or the string "true" or "false"');
2189
+ }
2190
+ function requiredString(config, key) {
2191
+ const value = config[key] === "" ? "" : read(config, key, "string");
2192
+ if (typeof value !== "string") throw invalid(key, "a string");
2193
+ return value;
2194
+ }
2195
+ var REQUIRE_MENTION = {
2196
+ key: "requireMention",
2197
+ required: false,
2198
+ secret: false,
2199
+ env: "WHATSAPP_REQUIRE_MENTION",
2200
+ description: "Whether group messages must mention the bot. Default true."
2201
+ };
2202
+ var CLOUD_CONFIG = [
2203
+ {
2204
+ key: "accessToken",
2205
+ required: true,
2206
+ secret: true,
2207
+ env: "WHATSAPP_ACCESS_TOKEN",
2208
+ description: "The Meta Cloud API access token."
2209
+ },
2210
+ {
2211
+ key: "phoneNumberId",
2212
+ required: true,
2213
+ secret: false,
2214
+ env: "WHATSAPP_PHONE_NUMBER_ID",
2215
+ description: "The Cloud API phone number id the adapter answers for."
2216
+ },
2217
+ {
2218
+ key: "appSecret",
2219
+ required: true,
2220
+ secret: true,
2221
+ env: "WHATSAPP_APP_SECRET",
2222
+ description: "The Meta app secret that signs inbound webhooks."
2223
+ },
2224
+ {
2225
+ key: "verifyToken",
2226
+ required: false,
2227
+ secret: true,
2228
+ env: "WHATSAPP_VERIFY_TOKEN",
2229
+ description: "The token Meta's webhook subscription check sends; not an adapter option, kept so the webhook half can answer it."
2230
+ },
2231
+ REQUIRE_MENTION
2232
+ ];
2233
+ var BAILEYS_CONFIG = [
2234
+ {
2235
+ key: "sessionDir",
2236
+ required: true,
2237
+ secret: false,
2238
+ env: "WHATSAPP_SESSION_DIR",
2239
+ description: "Directory where the Baileys session (credentials) is stored."
2240
+ },
2241
+ {
2242
+ key: "botPhoneId",
2243
+ required: false,
2244
+ secret: false,
2245
+ env: "WHATSAPP_BOT_PHONE_ID",
2246
+ description: "The bot's own number; with requireMention (default), a group message must mention it or is dropped."
2247
+ },
2248
+ REQUIRE_MENTION
2249
+ ];
2250
+ function common(config) {
2251
+ const requireMention = read(config, "requireMention", "boolean");
2252
+ const botPhoneId = read(config, "botPhoneId", "string");
2253
+ return {
2254
+ ...requireMention === void 0 ? {} : { requireMention },
2255
+ ...botPhoneId === void 0 ? {} : { botPhoneId }
2256
+ };
2257
+ }
2258
+ function createCloud(config) {
2259
+ const accessToken = requiredString(config, "accessToken");
2260
+ const phoneNumberId = requiredString(config, "phoneNumberId");
2261
+ const appSecret = requiredString(config, "appSecret");
2262
+ read(config, "verifyToken", "string");
2263
+ const opts = common(config);
2264
+ return WhatsAppAdapter.from(
2265
+ { backend: "cloud", cloud: { accessToken, phoneNumberId, appSecret } },
2266
+ opts
2267
+ );
2268
+ }
2269
+ function createBaileys(config) {
2270
+ const sessionDir = requiredString(config, "sessionDir");
2271
+ const opts = common(config);
2272
+ return WhatsAppAdapter.from({ backend: "baileys", baileys: { sessionDir } }, opts);
2273
+ }
2274
+ var cloudChannel = {
2275
+ platform: "whatsapp",
2276
+ transport: "socket",
2277
+ senderIdentity: "authenticated",
2278
+ config: CLOUD_CONFIG,
2279
+ create: createCloud
2280
+ };
2281
+ var baileysChannel = {
2282
+ platform: "whatsapp",
2283
+ transport: "socket",
2284
+ senderIdentity: "authenticated",
2285
+ config: BAILEYS_CONFIG,
2286
+ create: createBaileys
2287
+ };
2288
+ var whatsappChannel = {
2289
+ ...cloudChannel,
2290
+ variants: { cloud: cloudChannel, baileys: baileysChannel }
2291
+ };
2292
+
2293
+ export { ConfigurationError, LineBuffer, WhatsAppAdapter, WhatsAppBaileysBackend, WhatsAppBridgeError, WhatsAppCloudBackend, WhatsAppConnectTimeoutError, WhatsAppWebBackend, createBaileysSocket, defaultBridgeScriptPath, digitsOnly, formatCommand, mapWhatsAppCloudError, mapWhatsAppWebError, normalizeInboundMessages, normalizeStatusReceipts, parseEvent, parseWebhookPayload, splitForWhatsApp, verifyWebhookSignature, verifyWebhookSubscription, whatsappChannel };
2175
2294
  //# sourceMappingURL=index.js.map
2176
2295
  //# sourceMappingURL=index.js.map