@owlmeans/bot-whatsapp 0.0.0-stage → 0.2.0-alpha.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.
Files changed (60) hide show
  1. package/README.md +74 -2
  2. package/agent-meta/manifest.json +16 -0
  3. package/agent-meta/skills/bot-whatsapp/SKILL.md +104 -0
  4. package/build/api.d.ts +7 -0
  5. package/build/api.d.ts.map +1 -0
  6. package/build/api.js +50 -0
  7. package/build/api.js.map +1 -0
  8. package/build/append.d.ts +10 -0
  9. package/build/append.d.ts.map +1 -0
  10. package/build/append.js +13 -0
  11. package/build/append.js.map +1 -0
  12. package/build/consts.d.ts +57 -0
  13. package/build/consts.d.ts.map +1 -0
  14. package/build/consts.js +183 -0
  15. package/build/consts.js.map +1 -0
  16. package/build/errors.d.ts +22 -0
  17. package/build/errors.d.ts.map +1 -0
  18. package/build/errors.js +34 -0
  19. package/build/errors.js.map +1 -0
  20. package/build/index.d.ts +7 -0
  21. package/build/index.d.ts.map +1 -0
  22. package/build/index.js +6 -0
  23. package/build/index.js.map +1 -0
  24. package/build/mock.d.ts +9 -0
  25. package/build/mock.d.ts.map +1 -0
  26. package/build/mock.js +198 -0
  27. package/build/mock.js.map +1 -0
  28. package/build/normalize.d.ts +4 -0
  29. package/build/normalize.d.ts.map +1 -0
  30. package/build/normalize.js +109 -0
  31. package/build/normalize.js.map +1 -0
  32. package/build/plugin.d.ts +13 -0
  33. package/build/plugin.d.ts.map +1 -0
  34. package/build/plugin.js +147 -0
  35. package/build/plugin.js.map +1 -0
  36. package/build/signature.d.ts +4 -0
  37. package/build/signature.d.ts.map +1 -0
  38. package/build/signature.js +20 -0
  39. package/build/signature.js.map +1 -0
  40. package/build/types.d.ts +179 -0
  41. package/build/types.d.ts.map +1 -0
  42. package/build/types.js +2 -0
  43. package/build/types.js.map +1 -0
  44. package/package.json +56 -4
  45. package/src/api.ts +62 -0
  46. package/src/append.ts +18 -0
  47. package/src/consts.ts +206 -0
  48. package/src/errors.ts +37 -0
  49. package/src/index.ts +6 -0
  50. package/src/mock.ts +243 -0
  51. package/src/normalize.ts +131 -0
  52. package/src/plugin.ts +183 -0
  53. package/src/signature.ts +27 -0
  54. package/src/types.ts +174 -0
  55. package/tests/context.ts +85 -0
  56. package/tests/descriptor.spec.ts +64 -0
  57. package/tests/mock-ids.spec.ts +38 -0
  58. package/tests/tsconfig.json +12 -0
  59. package/tests/whatsapp.spec.ts +485 -0
  60. package/tsconfig.json +16 -0
package/README.md CHANGED
@@ -1,3 +1,75 @@
1
- # Temporary Holding Version
1
+ # @owlmeans/bot-whatsapp
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The WhatsApp plugin of OwlMeans chat bots: a `BotPlatformPlugin` for `@owlmeans/server-bot` over
4
+ the WhatsApp Cloud API (Graph): the phone number is verified, Meta's GET handshake answers `hub.challenge`, every delivery's `X-Hub-Signature-256` is checked over the raw body, and text messages, replies and reactions are sent; the webhook is set up by hand in the Meta app (the connection's setup steps carry the callback URL and the generated verify token). It ships the platform's descriptor (`WHATSAPP_DESCRIPTOR` — credentials with their labels and
5
+ hints in eight languages, receive modes, actions, setup hint) that the
6
+ `@owlmeans/web-bot` panels draw through `platform.list`, and an API-faithful mock the platform's tests,
7
+ the runtime smoke and end-to-end runs use. It lives in OwlMeans connect because it names a provider;
8
+ the bot runtime and contract it plugs into are in common, which never depends on it.
9
+
10
+ ## Installation
11
+
12
+ ```bash
13
+ bun add @owlmeans/bot-whatsapp@^0.2.0-alpha.0
14
+ ```
15
+
16
+ ## Usage
17
+
18
+ Registration is explicit — importing the package registers nothing:
19
+
20
+ ```typescript
21
+ import { makeBotService } from '@owlmeans/server-bot'
22
+ import { whatsappBotPlatform } from '@owlmeans/bot-whatsapp'
23
+
24
+ export const makeService = () => makeBotService({
25
+ secret: () => process.env.APP_SECRET ?? '',
26
+ platforms: [whatsappBotPlatform], // beside the other platforms the product supports
27
+ })
28
+
29
+ // or, on a context whose bot service may not exist yet:
30
+ import { appendWhatsAppBotPlatform } from '@owlmeans/bot-whatsapp'
31
+ appendWhatsAppBotPlatform(context)
32
+ ```
33
+
34
+ ## The platform
35
+
36
+ | | |
37
+ |---|---|
38
+ | Id (stored, in the hook URL) | `whatsapp` (`WHATSAPP_PLATFORM`) |
39
+ | Credentials | `accessToken`, `phoneNumberId`, `appSecret`, `verifyToken` (generated by the server) |
40
+ | Receive | webhook (manual) |
41
+ | Actions | reply, send, react — no delete, mute or ban |
42
+ | Refusals | `WhatsAppApiError` (`bot:platform:whatsapp:<Graph code>:<message>`, `code`, `status`) — subclasses of `BotErrorPlatform`, travelling under its type name |
43
+ | Options | `makeWhatsAppBotPlatform({ … })`: `base`, `version` — the Graph host and version |
44
+
45
+ ## API
46
+
47
+ - `whatsappBotPlatform` — the ready instance; `makeWhatsAppBotPlatform(options?)` — a configured one;
48
+ `appendWhatsAppBotPlatform(context, options?, alias?)` — register on the context's bot service
49
+ - `WHATSAPP_PLATFORM`, `WHATSAPP_DESCRIPTOR`, `WHATSAPP_CREDENTIALS`, `WHATSAPP_HINT`, `whatsappSignatureHelper` and the protocol constants
50
+ - the native payload types and the plugin's options
51
+
52
+ The `bot-whatsapp` skill covers every API call the plugin makes, its normalization and its mock; the
53
+ `server-bot` skill (common) covers the plugin interface, the mock transport and the runtime.
54
+
55
+ ## Related packages
56
+
57
+ - `@owlmeans/server-bot` — the bot runtime this plugs into (common)
58
+ - `@owlmeans/bot` — the contract: the descriptor, connections, updates, the errors (common)
59
+ - `@owlmeans/web-bot` — the panels that draw the descriptor (common)
60
+
61
+ <!-- owlmeans:agent-guidance:start -->
62
+ ## Agent guidance
63
+
64
+ This package ships embedded agent skills under `agent-meta/`. After installing your
65
+ `@owlmeans/*` packages, run the OwlMeans agent-skills installer to place them into
66
+ your project's skill store (`.agents/skills/`):
67
+
68
+ ```sh
69
+ npx @owlmeans/agent-skills@^0.2.0-alpha.0
70
+ ```
71
+
72
+ The embedded files are version-matched to this package release. Do not edit them
73
+ directly — they are regenerated on each publish. To contribute guidance edits,
74
+ open a PR against the source monorepo.
75
+ <!-- owlmeans:agent-guidance:end -->
@@ -0,0 +1,16 @@
1
+ {
2
+ "schemaVersion": 3,
3
+ "package": "@owlmeans/bot-whatsapp",
4
+ "version": "0.2.0-alpha.0",
5
+ "generatedAt": "2026-11-09T19:45:13.355Z",
6
+ "canonicalRepo": "https://github.com/owlmeans/connect",
7
+ "entries": [
8
+ {
9
+ "kind": "skill",
10
+ "name": "bot-whatsapp",
11
+ "category": "package-specific",
12
+ "file": "skills/bot-whatsapp/SKILL.md",
13
+ "canonicalPath": ".agents/skills/bot-whatsapp/SKILL.md"
14
+ }
15
+ ]
16
+ }
@@ -0,0 +1,104 @@
1
+ ---
2
+ name: bot-whatsapp
3
+ description: "How to use @owlmeans/bot-whatsapp (OwlMeans connect) — the WhatsApp Cloud API plugin of @owlmeans/server-bot: registering it (makeWhatsAppBotPlatform, whatsappBotPlatform, appendWhatsAppBotPlatform), its descriptor (access token, phone number id, app secret, the generated verify token; labels and hints in eight languages), the Cloud API calls each step makes, the GET handshake and the X-Hub-Signature-256 check, the manual setup steps, its normalization (one number per connection, the 24-hour window) and its mock. Auto-invoked when wiring WhatsApp into a bot service, debugging a WhatsApp connection, webhook or refusal, or testing against the WhatsApp mock."
4
+ user-invocable: false
5
+ ---
6
+ <!-- AUTO-GENERATED — do not edit. Regenerate via sync-agent-meta. -->
7
+
8
+ # @owlmeans/bot-whatsapp
9
+
10
+ **Layer:** Server (a platform plugin)
11
+ **Repo:** OwlMeans connect (`@owlmeans/bot-whatsapp`) — the WhatsApp-specific half; the bot runtime it plugs
12
+ into (`@owlmeans/server-bot`) and the contract (`@owlmeans/bot`) are in common, which never depends on it
13
+ **Install:** `"@owlmeans/bot-whatsapp": "^0.2.0-alpha.0"` in the backend's `dependencies`
14
+
15
+ The WhatsApp plugin (Cloud API: manual webhook): a `BotPlatformPlugin` over server-bot's public helpers, its
16
+ descriptor (`WHATSAPP_DESCRIPTOR` — the data the panels draw through `platform.list`, its labels and hints
17
+ in the eight panel languages) and its API-faithful mock. The plugin interface, the rules every plugin
18
+ follows and the mock transport are the `server-bot` skill's `platforms` part.
19
+
20
+ ## Registration — explicit, never a side-effect import
21
+
22
+ ```ts
23
+ import { makeBotService } from '@owlmeans/server-bot'
24
+ import { whatsappBotPlatform } from '@owlmeans/bot-whatsapp'
25
+
26
+ makeBotService({ secret, platforms: [whatsappBotPlatform /* , the other platforms the product supports */] })
27
+ // or, on a context whose bot service exists (appendBot's defaults otherwise):
28
+ appendWhatsAppBotPlatform(context, options?) // = appendBot(context).register(makeWhatsAppBotPlatform(options))
29
+ ```
30
+
31
+ | Export | What it is |
32
+ |---|---|
33
+ | `whatsappBotPlatform` | the ready instance — its `mock` holds the mock state of every mock connection it serves |
34
+ | `makeWhatsAppBotPlatform({ base, version })` | a configured plugin (a test or a proxy) |
35
+ | `appendWhatsAppBotPlatform(ctx, options?, alias?)` | registers a configured plugin on the context's bot service |
36
+ | `WHATSAPP_PLATFORM` (`'whatsapp'`), `WHATSAPP_DESCRIPTOR`, `WHATSAPP_CREDENTIALS`, `WHATSAPP_HINT` | the stored id and the descriptor data |
37
+ | `WhatsAppApiError` | the API refusals — subclasses of `BotErrorPlatform` declaring NO type name of their own: they travel as `BotErrorPlatform` (`bot:platform:whatsapp:<detail>`), so a refusal is rebuilt and explained where this package is not loaded |
38
+ | `WHATSAPP_*`, `WHATSAPP_DESCRIPTOR`, `whatsappSignatureHelper` | protocol constants and helpers |
39
+
40
+ - The id `whatsapp` is stored on every connection, inbox row and activity, and is the hook URL segment —
41
+ it never changes.
42
+ - The descriptor's texts are complete in `en`, `pl`, `ru`, `be`, `uk`, `es`, `de`, `fr`
43
+ (`tests/descriptor.spec.ts` holds that); a new language is added here, never in `@owlmeans/web-bot`.
44
+
45
+ ## The WhatsApp API
46
+
47
+ Docs: https://developers.facebook.com/documentation/business-messaging/whatsapp/webhooks/create-webhook-endpoint
48
+ (handshake + signature), …/webhooks/reference/messages (`text`, `interactive`, `button` payloads),
49
+ …/messages/text-messages, …/messages/contextual-replies, …/messages/reaction-messages,
50
+ …/business-phone-numbers/phone-numbers, …/support/error-codes (all under
51
+ `https://developers.facebook.com/documentation/business-messaging/whatsapp/`). Calls go to
52
+ `<base>/<version>/…` with `Authorization: Bearer <accessToken>`; `base` defaults to
53
+ `https://graph.facebook.com`, `version` to `v26.0` (`makeWhatsAppBotPlatform({ base, version })`).
54
+ A refusal is `{ error: { message, type, code, error_subcode?, fbtrace_id } }` → `WhatsAppApiError`
55
+ `bot:platform:whatsapp:<code>:<message>` (`code` = Graph code, `status` = HTTP status; build on `code`, not
56
+ the HTTP status — Meta's advice).
57
+
58
+ | Plugin step | Cloud API | Notes |
59
+ |---|---|---|
60
+ | verify | `GET /<phoneNumberId>?fields=display_phone_number,verified_name` | identity: id = phone number id, `name` = verified name, `username` = display number; codes 0 3 10 100 190 or HTTP 401/403/404 → `BotCredentialsRejected` |
61
+ | registerHook | — (`setup: 'manual'`) | `setup` steps: callback URL = `hookUrl`, verify token, subscribe to `messages`, a permanent System User token, one app per number, the 24-hour window |
62
+ | authenticate GET | `hub.mode=subscribe`, `hub.verify_token`, `hub.challenge` | token timing-safe against `verifyToken` (default: the hook secret) → `{ result: 'challenge', text: <hub.challenge> }`; else reject (`hub-mode`, `verify-token`, `hub-challenge`) |
63
+ | authenticate POST | `X-Hub-Signature-256: sha256=<hex HMAC-SHA256(appSecret, raw body)>` | over `rawBody` (Meta escapes non-ASCII as `\uXXXX`: a re-serialized body does not verify); no app secret → reject, except a MOCK connection, which signs with its hook secret |
64
+ | reply | `POST /<phoneNumberId>/messages { messaging_product: 'whatsapp', recipient_type: 'individual', to, context: { message_id }, type: 'text', text: { body } }` | body ≤ 4096 (clipped); the created message = `messages[0].id` |
65
+ | send | the same without `context` | `to` = the chat id = the customer's `wa_id` |
66
+ | react | `{ …, type: 'reaction', reaction: { message_id, emoji } }` | only to a customer's message ≤ 30 days old; a failure arrives later as a status webhook (131009) |
67
+ | delete / mute / ban | — | not in the descriptor; `act` throws `BotUnsupportedAction` defensively |
68
+
69
+ Normalization: `object: 'whatsapp_business_account'` → every `entry[].changes[]` with `field:
70
+ 'messages'` → every `value.messages[]`: `text.body`; `interactive.button_reply.title` /
71
+ `list_reply.title`; a template quick reply `button.text`; an `image`/`video`/`document` caption.
72
+ Other kinds (reaction, sticker, location, `unsupported` …) and `statuses[]` (delivery receipts) give
73
+ no update. Chat = `{ id: from, kind: private, title: profile name }` (Cloud API messages are
74
+ one-to-one), sender from `contacts[]` by `wa_id`, `addressed: true`, `platformId` = the `wamid`, a
75
+ leading `/cmd` is a command. `context.id` → `replyTo` (its sender is the bot when `context.from` is
76
+ the business display number); a `forwarded` context is no reply and carries no quoted text. A change
77
+ whose `metadata.phone_number_id` differs from the verified identity is ignored: one Meta app posts
78
+ every number's messages to ONE callback URL, so a connection keeps only its own number's. Meta
79
+ batches and retries for up to 7 days — the inbox's dedupe on the `wamid` absorbs that.
80
+
81
+ Mock (`whatsappBotPlatform.mock`, a `WhatsAppMock`): the phone number id is `phoneNumberId` or 15
82
+ digits derived from the connection id (`phoneNumberIdOf`), the display number `1555…`
83
+ (`displayNumberOf`), the verified name the connection's label. Calls are recorded as `phone-number`
84
+ (params = the query) and `messages` (params = the JSON body); a text or reaction answers a fresh
85
+ random `wamid.…` (inbound ones too), a bad body or another number id the Graph `{ error }` (code 100, subcode 33). `inbound`
86
+ writes Meta's payload for `input.text` from `input.sender.id` (a phone number stays itself; default
87
+ `15551230001`), `replyTo` as `context` (from the business when the fake API sent that id), signed
88
+ with the app secret or else the hook secret. `challenge(connection, { challenge?, verifyToken? })`
89
+ builds the GET handshake. `feed` only keeps the payload — WhatsApp has no receiver.
90
+
91
+ Not used (the contract says `setup: 'manual'`): Meta's per-number callback override, `POST
92
+ /<phoneNumberId> { webhook_configuration: { override_callback_uri, verify_token } }` (…/webhooks/override;
93
+ precedence number → business account → app), would let `registerHook` set the hook itself and lift
94
+ the one-app-per-number limit.
95
+
96
+
97
+ ## Testing
98
+
99
+ `bun test ./tests` (category A — the mock and a test `fetch`, no network): normalization over the
100
+ documented payloads, authentication, the API client and its refusals, the mock's answers and its ids'
101
+ uniqueness across lifetimes (`mock-ids.spec.ts`), the descriptor (`descriptor.spec.ts`: complete in eight
102
+ languages, a restart simulated over the same store), and the platform end to end on a mock connection
103
+ through the service (`tests/context.ts`'s `makeTestBot` registers `whatsappBotPlatform`; `botMockHelper` is
104
+ `makeBotMockHelper([whatsappBotPlatform])`).
package/build/api.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ import type { WhatsAppApiFactory } from './types.js';
2
+ /**
3
+ * The Graph API over a session: `<root>/<path>`, the access token as `Authorization: Bearer`, JSON in
4
+ * and out; a refusal is `{ error: { message, code, … } }`. The token never reaches an error message.
5
+ */
6
+ export declare const makeWhatsAppApi: WhatsAppApiFactory;
7
+ //# sourceMappingURL=api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAe,kBAAkB,EAA8C,MAAM,YAAY,CAAA;AAG7G;;;GAGG;AACH,eAAO,MAAM,eAAe,EAAE,kBAoD7B,CAAA"}
package/build/api.js ADDED
@@ -0,0 +1,50 @@
1
+ import { WHATSAPP_CALL_TIMEOUT_MS } from './consts.js';
2
+ import { WhatsAppApiError } from './errors.js';
3
+ import { botSignalHelper } from '@owlmeans/server-bot';
4
+ /**
5
+ * The Graph API over a session: `<root>/<path>`, the access token as `Authorization: Bearer`, JSON in
6
+ * and out; a refusal is `{ error: { message, code, … } }`. The token never reaches an error message.
7
+ */
8
+ export const makeWhatsAppApi = (session, root) => {
9
+ const call = async (method, path, query, body, opts) => {
10
+ const token = session.connection.credentials.accessToken ?? '';
11
+ const search = query != null && Object.keys(query).length > 0 ? `?${new URLSearchParams(query).toString()}` : '';
12
+ const name = `${method} ${path.split('/').pop() ?? ''}`;
13
+ let response;
14
+ try {
15
+ response = await session.fetch(`${root}/${path}${search}`, {
16
+ method,
17
+ headers: {
18
+ ...(token !== '' ? { authorization: `Bearer ${token}` } : {}),
19
+ ...(body != null ? { 'content-type': 'application/json' } : {}),
20
+ },
21
+ ...(body != null ? { body: JSON.stringify(body) } : {}),
22
+ signal: botSignalHelper.deadline(opts.timeoutMs ?? WHATSAPP_CALL_TIMEOUT_MS, opts.signal),
23
+ });
24
+ }
25
+ catch (error) {
26
+ if (opts.signal?.aborted === true) {
27
+ throw error;
28
+ }
29
+ // A transport error may carry the request — and its header the token: never pass it on.
30
+ const timedOut = error instanceof Error && error.name === 'TimeoutError';
31
+ throw WhatsAppApiError.of(timedOut ? 504 : 503, `${name}: ${timedOut ? 'timeout' : 'unreachable'}`);
32
+ }
33
+ let answer;
34
+ try {
35
+ answer = await response.json();
36
+ }
37
+ catch {
38
+ throw WhatsAppApiError.of(response.status, `${name}: unreadable answer`);
39
+ }
40
+ const refusal = answer?.error;
41
+ if (refusal != null || !response.ok) {
42
+ throw WhatsAppApiError.of(typeof refusal?.code === 'number' ? refusal.code : response.status, refusal?.message ?? `${name}: refused`, response.status);
43
+ }
44
+ return answer;
45
+ };
46
+ const get = async (path, query, opts = {}) => await call('GET', path, query, undefined, opts);
47
+ const post = async (path, body, opts = {}) => await call('POST', path, undefined, body, opts);
48
+ return { get, post };
49
+ };
50
+ //# sourceMappingURL=api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAA;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAE9C,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAEtD;;;GAGG;AACH,MAAM,CAAC,MAAM,eAAe,GAAuB,CAAC,OAAO,EAAE,IAAI,EAAe,EAAE;IAChF,MAAM,IAA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,CAAC,CAAA;IAEpD,MAAM,IAAI,GAAG,KAAK,EAAK,IAAY,EAAE,IAA6B,EAAE,IAAI,GAAwB,EAAE,EAAc,EAAE,CAChH,MAAM,IAAI,CAAI,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,CAAC,CAAA;IAEpD,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,CAAA;AACtB,CAAC,CAAA"}
@@ -0,0 +1,10 @@
1
+ import type { BasicContext } from '@owlmeans/context';
2
+ import { type BotPlatformPlugin } from '@owlmeans/server-bot';
3
+ import type { WhatsAppBotPlatformOptions } from './types.js';
4
+ /**
5
+ * Register the WhatsApp plugin on the context's bot service — appending the service (`appendBot`, its
6
+ * default options) when it is not there yet — and answer the plugin. Registration is explicit:
7
+ * importing this package registers nothing.
8
+ */
9
+ export declare const appendWhatsAppBotPlatform: <C extends BasicContext<any>>(context: C, opts?: WhatsAppBotPlatformOptions, alias?: string) => BotPlatformPlugin;
10
+ //# sourceMappingURL=append.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"append.d.ts","sourceRoot":"","sources":["../src/append.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AACrD,OAAO,EAA0B,KAAK,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AAErF,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,YAAY,CAAA;AAE5D;;;;GAIG;AACH,eAAO,MAAM,yBAAyB,GAAI,CAAC,SAAS,YAAY,CAAC,GAAG,CAAC,WAC1D,CAAC,SAAS,0BAA0B,UAAS,MAAM,KAC3D,iBAKF,CAAA"}
@@ -0,0 +1,13 @@
1
+ import { appendBot, BOT_SERVICE } from '@owlmeans/server-bot';
2
+ import { makeWhatsAppBotPlatform } from './plugin.js';
3
+ /**
4
+ * Register the WhatsApp plugin on the context's bot service — appending the service (`appendBot`, its
5
+ * default options) when it is not there yet — and answer the plugin. Registration is explicit:
6
+ * importing this package registers nothing.
7
+ */
8
+ export const appendWhatsAppBotPlatform = (context, opts, alias = BOT_SERVICE) => {
9
+ const plugin = makeWhatsAppBotPlatform(opts);
10
+ appendBot(context, undefined, alias).register(plugin);
11
+ return plugin;
12
+ };
13
+ //# sourceMappingURL=append.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"append.js","sourceRoot":"","sources":["../src/append.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,WAAW,EAA0B,MAAM,sBAAsB,CAAA;AACrF,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAA;AAGrD;;;;GAIG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,CACvC,OAAU,EAAE,IAAiC,EAAE,KAAK,GAAW,WAAW,EACvD,EAAE;IACrB,MAAM,MAAM,GAAG,uBAAuB,CAAC,IAAI,CAAC,CAAA;IAC5C,SAAS,CAAC,OAAO,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA;IAErD,OAAO,MAAM,CAAA;AACf,CAAC,CAAA"}
@@ -0,0 +1,57 @@
1
+ import { type BotCredentialField, type BotPlatformDescriptor, type BotTexts } from '@owlmeans/bot';
2
+ /** The Graph API host — override `base` (and `version`) through `makeWhatsAppBotPlatform`. */
3
+ export declare const WHATSAPP_API_BASE = "https://graph.facebook.com";
4
+ /** The Graph API version calls go to: `<base>/<version>/…`. */
5
+ export declare const WHATSAPP_API_VERSION = "v26.0";
6
+ /** The header Meta signs every webhook POST in (lower-cased, as servers hand it over). */
7
+ export declare const WHATSAPP_SIGNATURE_HEADER = "x-hub-signature-256";
8
+ /** What precedes the hex HMAC-SHA256 digest in the signature header. */
9
+ export declare const WHATSAPP_SIGNATURE_PREFIX = "sha256=";
10
+ /** `object` of every WhatsApp Business Account webhook payload. */
11
+ export declare const WHATSAPP_WEBHOOK_OBJECT = "whatsapp_business_account";
12
+ /** The webhook field a connection subscribes to — incoming messages and the statuses of sent ones. */
13
+ export declare const WHATSAPP_MESSAGES_FIELD = "messages";
14
+ /** The subscription handshake's `hub.mode`. */
15
+ export declare const WHATSAPP_HUB_MODE = "subscribe";
16
+ /** What `verify` reads of the business phone number. */
17
+ export declare const WHATSAPP_PHONE_FIELDS = "display_phone_number,verified_name";
18
+ /** `messaging_product` of every Cloud API message. */
19
+ export declare const WHATSAPP_MESSAGING_PRODUCT = "whatsapp";
20
+ /** How long one Graph API call may take. */
21
+ export declare const WHATSAPP_CALL_TIMEOUT_MS = 15000;
22
+ /** `text.body` limit — longer text is clipped. */
23
+ export declare const WHATSAPP_TEXT_MAX = 4096;
24
+ /** The credentials a live `verify` calls with (the app secret only signs inbound requests). */
25
+ export declare const WHATSAPP_VERIFY_CREDENTIALS: readonly string[];
26
+ /** Graph error codes that refuse the access token or the phone number id (verification fails on them). */
27
+ export declare const WHATSAPP_CREDENTIAL_ERROR_CODES: readonly number[];
28
+ /** HTTP statuses that refuse the credentials whatever the error code. */
29
+ export declare const WHATSAPP_CREDENTIAL_STATUSES: readonly number[];
30
+ /** The incoming message types whose text the bot reads (media by their caption). */
31
+ export declare const WHATSAPP_CAPTIONED_TYPES: readonly string[];
32
+ /** Where the callback URL and the verify token are pasted (the plugin's first two steps name them). */
33
+ export declare const WHATSAPP_SETUP_CONSOLE = "In the Meta App Dashboard, open WhatsApp \u2192 Configuration \u2192 Webhook and press Edit.";
34
+ /** The steps after the callback URL and the verify token. */
35
+ export declare const WHATSAPP_SETUP_STEPS: readonly string[];
36
+ /** The mock's simulated defaults: one customer writing to a test business number. */
37
+ export declare const WHATSAPP_MOCK_SENDER_ID = "15551230001";
38
+ export declare const WHATSAPP_MOCK_SENDER_NAME = "Test customer";
39
+ export declare const WHATSAPP_MOCK_BUSINESS_NAME = "Mock business";
40
+ /** A mock business number is `1555` and seven digits derived from the connection id. */
41
+ export declare const WHATSAPP_MOCK_NUMBER_PREFIX = "1555";
42
+ /** A mock phone number id is fifteen digits derived from the connection id, starting here. */
43
+ export declare const WHATSAPP_MOCK_PHONE_ID_BASE = 100000000000000;
44
+ /** Random bytes in a mock `wamid.` (as hex, the way Meta's ids carry a 20-character hex message key). */
45
+ export declare const WHATSAPP_MOCK_ID_BYTES = 10;
46
+ /** The platform id — a stored column and a hook URL segment: it never changes. */
47
+ export declare const WHATSAPP_PLATFORM = "whatsapp";
48
+ /** What a WhatsApp connection needs typed (or generated), with its labels and hints in every panel language. */
49
+ export declare const WHATSAPP_CREDENTIALS: readonly BotCredentialField[];
50
+ /** What a person does in WhatsApp itself so the bot can act — in every panel language. */
51
+ export declare const WHATSAPP_HINT: BotTexts;
52
+ /**
53
+ * The WhatsApp descriptor — what the server verifies and acts by and what the panels draw (`platform.list`).
54
+ * `actions` are the calls the required credentials allow; `note` is never listed.
55
+ */
56
+ export declare const WHATSAPP_DESCRIPTOR: BotPlatformDescriptor;
57
+ //# sourceMappingURL=consts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"consts.d.ts","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":"AAAA,OAAO,EAC0B,KAAK,kBAAkB,EAAE,KAAK,qBAAqB,EAAE,KAAK,QAAQ,EAClG,MAAM,eAAe,CAAA;AAEtB,8FAA8F;AAC9F,eAAO,MAAM,iBAAiB,+BAA+B,CAAA;AAE7D,+DAA+D;AAC/D,eAAO,MAAM,oBAAoB,UAAU,CAAA;AAE3C,0FAA0F;AAC1F,eAAO,MAAM,yBAAyB,wBAAwB,CAAA;AAE9D,wEAAwE;AACxE,eAAO,MAAM,yBAAyB,YAAY,CAAA;AAElD,mEAAmE;AACnE,eAAO,MAAM,uBAAuB,8BAA8B,CAAA;AAElE,sGAAsG;AACtG,eAAO,MAAM,uBAAuB,aAAa,CAAA;AAEjD,+CAA+C;AAC/C,eAAO,MAAM,iBAAiB,cAAc,CAAA;AAE5C,wDAAwD;AACxD,eAAO,MAAM,qBAAqB,uCAAuC,CAAA;AAEzE,sDAAsD;AACtD,eAAO,MAAM,0BAA0B,aAAa,CAAA;AAEpD,4CAA4C;AAC5C,eAAO,MAAM,wBAAwB,QAAS,CAAA;AAE9C,kDAAkD;AAClD,eAAO,MAAM,iBAAiB,OAAO,CAAA;AAErC,+FAA+F;AAC/F,eAAO,MAAM,2BAA2B,mBAAkD,CAAA;AAE1F,0GAA0G;AAC1G,eAAO,MAAM,+BAA+B,mBAAsC,CAAA;AAElF,yEAAyE;AACzE,eAAO,MAAM,4BAA4B,mBAAiC,CAAA;AAE1E,oFAAoF;AACpF,eAAO,MAAM,wBAAwB,mBAAgD,CAAA;AAErF,uGAAuG;AACvG,eAAO,MAAM,sBAAsB,iGAAuF,CAAA;AAE1H,6DAA6D;AAC7D,eAAO,MAAM,oBAAoB,mBAK/B,CAAA;AAEF,qFAAqF;AACrF,eAAO,MAAM,uBAAuB,gBAAgB,CAAA;AACpD,eAAO,MAAM,yBAAyB,kBAAkB,CAAA;AACxD,eAAO,MAAM,2BAA2B,kBAAkB,CAAA;AAC1D,wFAAwF;AACxF,eAAO,MAAM,2BAA2B,SAAS,CAAA;AACjD,8FAA8F;AAC9F,eAAO,MAAM,2BAA2B,kBAAsB,CAAA;AAC9D,yGAAyG;AACzG,eAAO,MAAM,sBAAsB,KAAK,CAAA;AAExC,kFAAkF;AAClF,eAAO,MAAM,iBAAiB,aAAa,CAAA;AAE3C,gHAAgH;AAChH,eAAO,MAAM,oBAAoB,EAAE,SAAS,kBAAkB,EAsG3B,CAAA;AAEnC,0FAA0F;AAC1F,eAAO,MAAM,aAAa,EAAE,QAS1B,CAAA;AAEF;;;GAGG;AACH,eAAO,MAAM,mBAAmB,EAAE,qBAUP,CAAA"}
@@ -0,0 +1,183 @@
1
+ import { BotActionKind, BotReceiveMode, } from '@owlmeans/bot';
2
+ /** The Graph API host — override `base` (and `version`) through `makeWhatsAppBotPlatform`. */
3
+ export const WHATSAPP_API_BASE = 'https://graph.facebook.com';
4
+ /** The Graph API version calls go to: `<base>/<version>/…`. */
5
+ export const WHATSAPP_API_VERSION = 'v26.0';
6
+ /** The header Meta signs every webhook POST in (lower-cased, as servers hand it over). */
7
+ export const WHATSAPP_SIGNATURE_HEADER = 'x-hub-signature-256';
8
+ /** What precedes the hex HMAC-SHA256 digest in the signature header. */
9
+ export const WHATSAPP_SIGNATURE_PREFIX = 'sha256=';
10
+ /** `object` of every WhatsApp Business Account webhook payload. */
11
+ export const WHATSAPP_WEBHOOK_OBJECT = 'whatsapp_business_account';
12
+ /** The webhook field a connection subscribes to — incoming messages and the statuses of sent ones. */
13
+ export const WHATSAPP_MESSAGES_FIELD = 'messages';
14
+ /** The subscription handshake's `hub.mode`. */
15
+ export const WHATSAPP_HUB_MODE = 'subscribe';
16
+ /** What `verify` reads of the business phone number. */
17
+ export const WHATSAPP_PHONE_FIELDS = 'display_phone_number,verified_name';
18
+ /** `messaging_product` of every Cloud API message. */
19
+ export const WHATSAPP_MESSAGING_PRODUCT = 'whatsapp';
20
+ /** How long one Graph API call may take. */
21
+ export const WHATSAPP_CALL_TIMEOUT_MS = 15_000;
22
+ /** `text.body` limit — longer text is clipped. */
23
+ export const WHATSAPP_TEXT_MAX = 4096;
24
+ /** The credentials a live `verify` calls with (the app secret only signs inbound requests). */
25
+ export const WHATSAPP_VERIFY_CREDENTIALS = Object.freeze(['accessToken', 'phoneNumberId']);
26
+ /** Graph error codes that refuse the access token or the phone number id (verification fails on them). */
27
+ export const WHATSAPP_CREDENTIAL_ERROR_CODES = Object.freeze([0, 3, 10, 100, 190]);
28
+ /** HTTP statuses that refuse the credentials whatever the error code. */
29
+ export const WHATSAPP_CREDENTIAL_STATUSES = Object.freeze([401, 403, 404]);
30
+ /** The incoming message types whose text the bot reads (media by their caption). */
31
+ export const WHATSAPP_CAPTIONED_TYPES = Object.freeze(['image', 'video', 'document']);
32
+ /** Where the callback URL and the verify token are pasted (the plugin's first two steps name them). */
33
+ export const WHATSAPP_SETUP_CONSOLE = 'In the Meta App Dashboard, open WhatsApp → Configuration → Webhook and press Edit.';
34
+ /** The steps after the callback URL and the verify token. */
35
+ export const WHATSAPP_SETUP_STEPS = Object.freeze([
36
+ 'Under Webhook fields, subscribe to "messages".',
37
+ 'Use a permanent System User access token with the whatsapp_business_messaging permission — the temporary token of the API Setup page expires within a day.',
38
+ 'A Meta app posts the messages of all its numbers to one callback URL: give every connected number its own app.',
39
+ 'Customers write first: WhatsApp lets the bot answer a customer within 24 hours of their last message.',
40
+ ]);
41
+ /** The mock's simulated defaults: one customer writing to a test business number. */
42
+ export const WHATSAPP_MOCK_SENDER_ID = '15551230001';
43
+ export const WHATSAPP_MOCK_SENDER_NAME = 'Test customer';
44
+ export const WHATSAPP_MOCK_BUSINESS_NAME = 'Mock business';
45
+ /** A mock business number is `1555` and seven digits derived from the connection id. */
46
+ export const WHATSAPP_MOCK_NUMBER_PREFIX = '1555';
47
+ /** A mock phone number id is fifteen digits derived from the connection id, starting here. */
48
+ export const WHATSAPP_MOCK_PHONE_ID_BASE = 100_000_000_000_000;
49
+ /** Random bytes in a mock `wamid.` (as hex, the way Meta's ids carry a 20-character hex message key). */
50
+ export const WHATSAPP_MOCK_ID_BYTES = 10;
51
+ /** The platform id — a stored column and a hook URL segment: it never changes. */
52
+ export const WHATSAPP_PLATFORM = 'whatsapp';
53
+ /** What a WhatsApp connection needs typed (or generated), with its labels and hints in every panel language. */
54
+ export const WHATSAPP_CREDENTIALS = Object.freeze([
55
+ Object.freeze({
56
+ key: 'accessToken',
57
+ secret: true,
58
+ required: true,
59
+ label: Object.freeze({
60
+ en: 'Access token',
61
+ pl: 'Token dostępu',
62
+ ru: 'Токен доступа',
63
+ be: 'Токен доступу',
64
+ uk: 'Токен доступу',
65
+ es: 'Token de acceso',
66
+ de: 'Zugriffstoken',
67
+ fr: 'Jeton d’accès',
68
+ }),
69
+ hint: Object.freeze({
70
+ en: 'A permanent system-user token of your Meta app with the WhatsApp messaging permission.',
71
+ pl: 'Stały token użytkownika systemowego Twojej aplikacji Meta z uprawnieniem do wiadomości WhatsApp.',
72
+ ru: 'Постоянный токен системного пользователя вашего приложения Meta с правом отправки сообщений WhatsApp.',
73
+ be: 'Пастаянны токен сістэмнага карыстальніка вашай праграмы Meta з правам адпраўкі паведамленняў WhatsApp.',
74
+ uk: 'Постійний токен системного користувача вашого застосунку Meta з правом надсилати повідомлення WhatsApp.',
75
+ es: 'Un token permanente de usuario del sistema de tu app de Meta con permiso de mensajería de WhatsApp.',
76
+ de: 'Ein dauerhaftes System-User-Token Ihrer Meta-App mit der Berechtigung für WhatsApp-Nachrichten.',
77
+ fr: 'Un jeton permanent d’utilisateur système de votre app Meta, avec l’autorisation de messagerie WhatsApp.',
78
+ }),
79
+ }),
80
+ Object.freeze({
81
+ key: 'phoneNumberId',
82
+ secret: false,
83
+ required: true,
84
+ label: Object.freeze({
85
+ en: 'Phone number ID',
86
+ pl: 'ID numeru telefonu',
87
+ ru: 'ID номера телефона',
88
+ be: 'ID нумара тэлефона',
89
+ uk: 'ID номера телефону',
90
+ es: 'ID del número de teléfono',
91
+ de: 'Telefonnummern-ID',
92
+ fr: 'ID du numéro de téléphone',
93
+ }),
94
+ hint: Object.freeze({
95
+ en: 'WhatsApp → API Setup in your Meta app dashboard.',
96
+ pl: 'WhatsApp → API Setup w panelu Twojej aplikacji Meta.',
97
+ ru: 'WhatsApp → API Setup в панели вашего приложения Meta.',
98
+ be: 'WhatsApp → API Setup у панэлі вашай праграмы Meta.',
99
+ uk: 'WhatsApp → API Setup у панелі вашого застосунку Meta.',
100
+ es: 'WhatsApp → API Setup en el panel de tu app de Meta.',
101
+ de: 'WhatsApp → API Setup im Dashboard Ihrer Meta-App.',
102
+ fr: 'WhatsApp → API Setup dans le tableau de bord de votre app Meta.',
103
+ }),
104
+ }),
105
+ Object.freeze({
106
+ key: 'appSecret',
107
+ secret: true,
108
+ required: true,
109
+ label: Object.freeze({
110
+ en: 'App secret',
111
+ pl: 'Sekret aplikacji',
112
+ ru: 'Секрет приложения',
113
+ be: 'Сакрэт праграмы',
114
+ uk: 'Секрет застосунку',
115
+ es: 'Secreto de la app',
116
+ de: 'App-Geheimnis',
117
+ fr: 'Clé secrète de l’app',
118
+ }),
119
+ hint: Object.freeze({
120
+ en: 'App settings → Basic in your Meta app; it proves every incoming message came from Meta.',
121
+ pl: 'App settings → Basic w Twojej aplikacji Meta; potwierdza, że każda przychodząca wiadomość pochodzi od Meta.',
122
+ ru: 'App settings → Basic в вашем приложении Meta; он подтверждает, что каждое входящее сообщение пришло от Meta.',
123
+ be: 'App settings → Basic у вашай праграме Meta; ён пацвярджае, што кожнае ўваходнае паведамленне прыйшло ад Meta.',
124
+ uk: 'App settings → Basic у вашому застосунку Meta; він підтверджує, що кожне вхідне повідомлення надійшло від Meta.',
125
+ es: 'App settings → Basic en tu app de Meta; demuestra que cada mensaje entrante viene de Meta.',
126
+ de: 'App settings → Basic in Ihrer Meta-App; es belegt, dass jede eingehende Nachricht von Meta stammt.',
127
+ fr: 'App settings → Basic dans votre app Meta ; elle prouve que chaque message entrant vient de Meta.',
128
+ }),
129
+ }),
130
+ Object.freeze({
131
+ key: 'verifyToken',
132
+ secret: true,
133
+ required: true,
134
+ generated: true,
135
+ label: Object.freeze({
136
+ en: 'Verify token',
137
+ pl: 'Token weryfikacyjny',
138
+ ru: 'Токен подтверждения',
139
+ be: 'Токен пацверджання',
140
+ uk: 'Токен підтвердження',
141
+ es: 'Token de verificación',
142
+ de: 'Verifizierungstoken',
143
+ fr: 'Jeton de vérification',
144
+ }),
145
+ hint: Object.freeze({
146
+ en: 'Created for you; paste it into the webhook settings of your Meta app.',
147
+ pl: 'Tworzony dla Ciebie; wklej go w ustawieniach webhooka Twojej aplikacji Meta.',
148
+ ru: 'Создаётся автоматически; вставьте его в настройки вебхука вашего приложения Meta.',
149
+ be: 'Ствараецца аўтаматычна; устаўце яго ў налады вэбхука вашай праграмы Meta.',
150
+ uk: 'Створюється автоматично; вставте його в налаштування вебхука вашого застосунку Meta.',
151
+ es: 'Se crea por ti; pégalo en la configuración del webhook de tu app de Meta.',
152
+ de: 'Wird für Sie erzeugt; fügen Sie es in die Webhook-Einstellungen Ihrer Meta-App ein.',
153
+ fr: 'Créé pour vous ; collez-le dans les paramètres du webhook de votre app Meta.',
154
+ }),
155
+ }),
156
+ ]);
157
+ /** What a person does in WhatsApp itself so the bot can act — in every panel language. */
158
+ export const WHATSAPP_HINT = Object.freeze({
159
+ en: 'Paste the webhook URL and the verify token below into the webhook settings of your Meta app, then subscribe to the messages field.',
160
+ pl: 'Wklej poniższy adres webhooka i token weryfikacyjny w ustawieniach webhooka Twojej aplikacji Meta, a następnie zasubskrybuj pole messages.',
161
+ ru: 'Вставьте URL вебхука и токен подтверждения ниже в настройки вебхука вашего приложения Meta, затем подпишитесь на поле messages.',
162
+ be: 'Устаўце URL вэбхука і токен пацверджання ніжэй у налады вэбхука вашай праграмы Meta, потым падпішыцеся на поле messages.',
163
+ uk: 'Вставте URL вебхука й токен підтвердження нижче в налаштування вебхука вашого застосунку Meta, потім підпишіться на поле messages.',
164
+ es: 'Pega la URL del webhook y el token de verificación de abajo en la configuración del webhook de tu app de Meta y suscríbete al campo messages.',
165
+ de: 'Fügen Sie die Webhook-URL und das Verifizierungstoken unten in die Webhook-Einstellungen Ihrer Meta-App ein und abonnieren Sie dann das Feld messages.',
166
+ fr: 'Collez l’URL du webhook et le jeton de vérification ci-dessous dans les paramètres du webhook de votre app Meta, puis abonnez-vous au champ messages.',
167
+ });
168
+ /**
169
+ * The WhatsApp descriptor — what the server verifies and acts by and what the panels draw (`platform.list`).
170
+ * `actions` are the calls the required credentials allow; `note` is never listed.
171
+ */
172
+ export const WHATSAPP_DESCRIPTOR = Object.freeze({
173
+ platform: WHATSAPP_PLATFORM,
174
+ title: 'WhatsApp',
175
+ glyph: 'phone',
176
+ credentials: WHATSAPP_CREDENTIALS,
177
+ receive: Object.freeze([BotReceiveMode.Webhook]),
178
+ actions: Object.freeze([BotActionKind.Reply, BotActionKind.Send, BotActionKind.React]),
179
+ setup: 'manual',
180
+ docs: 'https://developers.facebook.com/docs/whatsapp/cloud-api/get-started',
181
+ hint: WHATSAPP_HINT,
182
+ });
183
+ //# sourceMappingURL=consts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"consts.js","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EAAE,cAAc,GAC9B,MAAM,eAAe,CAAA;AAEtB,8FAA8F;AAC9F,MAAM,CAAC,MAAM,iBAAiB,GAAG,4BAA4B,CAAA;AAE7D,+DAA+D;AAC/D,MAAM,CAAC,MAAM,oBAAoB,GAAG,OAAO,CAAA;AAE3C,0FAA0F;AAC1F,MAAM,CAAC,MAAM,yBAAyB,GAAG,qBAAqB,CAAA;AAE9D,wEAAwE;AACxE,MAAM,CAAC,MAAM,yBAAyB,GAAG,SAAS,CAAA;AAElD,mEAAmE;AACnE,MAAM,CAAC,MAAM,uBAAuB,GAAG,2BAA2B,CAAA;AAElE,sGAAsG;AACtG,MAAM,CAAC,MAAM,uBAAuB,GAAG,UAAU,CAAA;AAEjD,+CAA+C;AAC/C,MAAM,CAAC,MAAM,iBAAiB,GAAG,WAAW,CAAA;AAE5C,wDAAwD;AACxD,MAAM,CAAC,MAAM,qBAAqB,GAAG,oCAAoC,CAAA;AAEzE,sDAAsD;AACtD,MAAM,CAAC,MAAM,0BAA0B,GAAG,UAAU,CAAA;AAEpD,4CAA4C;AAC5C,MAAM,CAAC,MAAM,wBAAwB,GAAG,MAAM,CAAA;AAE9C,kDAAkD;AAClD,MAAM,CAAC,MAAM,iBAAiB,GAAG,IAAI,CAAA;AAErC,+FAA+F;AAC/F,MAAM,CAAC,MAAM,2BAA2B,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,aAAa,EAAE,eAAe,CAAC,CAAC,CAAA;AAE1F,0GAA0G;AAC1G,MAAM,CAAC,MAAM,+BAA+B,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG,CAAC,CAA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D,EAAE,EAAE,oIAAoI;IACxI,EAAE,EAAE,4IAA4I;IAChJ,EAAE,EAAE,iIAAiI;IACrI,EAAE,EAAE,0HAA0H;IAC9H,EAAE,EAAE,oIAAoI;IACxI,EAAE,EAAE,+IAA+I;IACnJ,EAAE,EAAE,wJAAwJ;IAC5J,EAAE,EAAE,uJAAuJ;CAC5J,CAAC,CAAA;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAA0B,MAAM,CAAC,MAAM,CAAC;IACtE,QAAQ,EAAE,iBAAiB;IAC3B,KAAK,EAAE,UAAU;IACjB,KAAK,EAAE,OAAO;IACd,WAAW,EAAE,oBAAoB;IACjC,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;IAChD,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,aAAa,CAAC,KAAK,EAAE,aAAa,CAAC,IAAI,EAAE,aAAa,CAAC,KAAK,CAAC,CAAC;IACtF,KAAK,EAAE,QAAQ;IACf,IAAI,EAAE,qEAAqE;IAC3E,IAAI,EAAE,aAAa;CACpB,CAA0B,CAAA"}
@@ -0,0 +1,22 @@
1
+ import { BotErrorPlatform } from '@owlmeans/bot';
2
+ /**
3
+ * The Graph API refused a call — `bot:platform:whatsapp:<code>:<message>`, `code` being the Graph
4
+ * error code (`error.code`: 190 an expired token, 100 a bad parameter, 131047 outside the 24-hour
5
+ * window …), or the HTTP status when the answer carried none (503 unreachable, 504 timeout).
6
+ *
7
+ * Declares no type name of its own: it travels as `BotErrorPlatform`, so a refusal is rebuilt (and
8
+ * explained) wherever this package is not loaded.
9
+ */
10
+ export declare class WhatsAppApiError extends BotErrorPlatform {
11
+ /** The refusal as the Graph API stated it. */
12
+ static of(code: number | string, description: string, status?: number): WhatsAppApiError;
13
+ /** The Graph error code (or the HTTP status when there was none). */
14
+ code: number;
15
+ /** The HTTP status of the answer — not carried across a hop (500 there; the code is carried). */
16
+ status: number;
17
+ /** `message` is `<code>:<description>` — prefer {@link WhatsAppApiError.of}. */
18
+ constructor(message?: string);
19
+ /** The code is read back from the detail. */
20
+ finalizeUnmarshal(): void;
21
+ }
22
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAA;AAGhD;;;;;;;GAOG;AACH,qBAAa,gBAAiB,SAAQ,gBAAgB;IACpD,8CAA8C;IAC9C,OAAuB,EAAE,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,gBAAgB,CAIvG;IAED,qEAAqE;IAC9D,IAAI,EAAE,MAAM,CAAM;IACzB,iGAAiG;IAC1F,MAAM,EAAE,MAAM,CAAM;IAE3B,gFAAgF;IAChF,YAAY,OAAO,GAAE,MAAoB,EAGxC;IAED,6CAA6C;IAC7B,iBAAiB,IAAI,IAAI,CAIxC;CACF"}
@@ -0,0 +1,34 @@
1
+ import { BotErrorPlatform } from '@owlmeans/bot';
2
+ import { WHATSAPP_PLATFORM } from './consts.js';
3
+ /**
4
+ * The Graph API refused a call — `bot:platform:whatsapp:<code>:<message>`, `code` being the Graph
5
+ * error code (`error.code`: 190 an expired token, 100 a bad parameter, 131047 outside the 24-hour
6
+ * window …), or the HTTP status when the answer carried none (503 unreachable, 504 timeout).
7
+ *
8
+ * Declares no type name of its own: it travels as `BotErrorPlatform`, so a refusal is rebuilt (and
9
+ * explained) wherever this package is not loaded.
10
+ */
11
+ export class WhatsAppApiError extends BotErrorPlatform {
12
+ /** The refusal as the Graph API stated it. */
13
+ static of(code, description, status) {
14
+ const error = new WhatsAppApiError(`${code}:${description}`);
15
+ error.status = status ?? (Number(code) || 500);
16
+ return error;
17
+ }
18
+ /** The Graph error code (or the HTTP status when there was none). */
19
+ code = 500;
20
+ /** The HTTP status of the answer — not carried across a hop (500 there; the code is carried). */
21
+ status = 500;
22
+ /** `message` is `<code>:<description>` — prefer {@link WhatsAppApiError.of}. */
23
+ constructor(message = '500:error') {
24
+ super(`${WHATSAPP_PLATFORM}:${message}`);
25
+ this.finalizeUnmarshal();
26
+ }
27
+ /** The code is read back from the detail. */
28
+ finalizeUnmarshal() {
29
+ super.finalizeUnmarshal();
30
+ const code = Number(/^(\d+):/.exec(this.detail)?.[1]);
31
+ this.code = Number.isFinite(code) ? code : 500;
32
+ }
33
+ }
34
+ //# sourceMappingURL=errors.js.map