@elizaos/plugin-whatsapp 2.0.0-alpha.9 → 2.0.3-beta.5

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 (56) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +176 -0
  3. package/auto-enable.ts +21 -0
  4. package/dist/.tsbuildinfo +1 -0
  5. package/dist/accounts.d.ts +205 -0
  6. package/dist/accounts.d.ts.map +1 -0
  7. package/dist/api/whatsapp-routes.d.ts +53 -0
  8. package/dist/api/whatsapp-routes.d.ts.map +1 -0
  9. package/dist/baileys/auth.d.ts +10 -0
  10. package/dist/baileys/auth.d.ts.map +1 -0
  11. package/dist/baileys/connection.d.ts +19 -0
  12. package/dist/baileys/connection.d.ts.map +1 -0
  13. package/dist/baileys/message-adapter.d.ts +14 -0
  14. package/dist/baileys/message-adapter.d.ts.map +1 -0
  15. package/dist/baileys/qr-code.d.ts +6 -0
  16. package/dist/baileys/qr-code.d.ts.map +1 -0
  17. package/dist/client.d.ts +99 -0
  18. package/dist/client.d.ts.map +1 -0
  19. package/dist/clients/baileys-client.d.ts +18 -0
  20. package/dist/clients/baileys-client.d.ts.map +1 -0
  21. package/dist/clients/factory.d.ts +6 -0
  22. package/dist/clients/factory.d.ts.map +1 -0
  23. package/dist/clients/interface.d.ts +10 -0
  24. package/dist/clients/interface.d.ts.map +1 -0
  25. package/dist/config.d.ts +135 -0
  26. package/dist/config.d.ts.map +1 -0
  27. package/dist/connector-account-provider.d.ts +19 -0
  28. package/dist/connector-account-provider.d.ts.map +1 -0
  29. package/dist/index.d.ts +14 -2
  30. package/dist/index.d.ts.map +1 -0
  31. package/dist/index.js +2526 -854
  32. package/dist/index.js.map +23 -19
  33. package/dist/media.d.ts +2 -0
  34. package/dist/media.d.ts.map +1 -0
  35. package/dist/normalize.d.ts +69 -0
  36. package/dist/normalize.d.ts.map +1 -0
  37. package/dist/pairing-service.d.ts +41 -0
  38. package/dist/pairing-service.d.ts.map +1 -0
  39. package/dist/qrcode-terminal-types.d.ts +6 -0
  40. package/dist/qrcode-terminal-types.d.ts.map +1 -0
  41. package/dist/runtime-service.d.ts +125 -0
  42. package/dist/runtime-service.d.ts.map +1 -0
  43. package/dist/services/whatsapp-pairing.d.ts +41 -0
  44. package/dist/services/whatsapp-pairing.d.ts.map +1 -0
  45. package/dist/setup-routes.d.ts +26 -0
  46. package/dist/setup-routes.d.ts.map +1 -0
  47. package/dist/types.d.ts +370 -0
  48. package/dist/types.d.ts.map +1 -0
  49. package/dist/utils/config-detector.d.ts +3 -0
  50. package/dist/utils/config-detector.d.ts.map +1 -0
  51. package/dist/webhook-auth.d.ts +11 -0
  52. package/dist/webhook-auth.d.ts.map +1 -0
  53. package/dist/workflow-credential-provider.d.ts +21 -0
  54. package/dist/workflow-credential-provider.d.ts.map +1 -0
  55. package/package.json +162 -131
  56. package/registry-entry.json +128 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Shaw Walters and elizaOS Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,176 @@
1
+ # @elizaos/plugin-whatsapp
2
+
3
+ WhatsApp plugin for elizaOS. Connects Eliza agents to WhatsApp via the **WhatsApp Cloud API** (Meta Business) or **Baileys** (personal account / QR-code auth).
4
+
5
+ ## Capabilities
6
+
7
+ - Send and receive text messages (inbound messages ingested into agent memory)
8
+ - Send emoji reactions, remove reactions
9
+ - Support for media captions (image, video, document) on inbound messages
10
+ - Interactive message content extraction (button replies, list replies)
11
+ - Location and reaction message handling
12
+ - Baileys QR-code pairing with session persistence
13
+ - Multi-account support (multiple WhatsApp numbers per agent)
14
+ - DM and group access policies (open / allowlist / pairing / disabled)
15
+ - Webhook verification and `X-Hub-Signature-256` security for Cloud API
16
+
17
+ ## Installation
18
+
19
+ ```bash
20
+ npm install @elizaos/plugin-whatsapp
21
+ ```
22
+
23
+ ## Enabling the Plugin
24
+
25
+ Add the plugin to your character file:
26
+
27
+ ```typescript
28
+ import whatsappPlugin from "@elizaos/plugin-whatsapp";
29
+
30
+ export const character = {
31
+ // ...
32
+ plugins: [whatsappPlugin],
33
+ };
34
+ ```
35
+
36
+ The plugin also auto-enables when a `connectors.whatsapp` block is present in agent config.
37
+
38
+ ## Configuration
39
+
40
+ ### Cloud API (Meta Business)
41
+
42
+ | Variable | Required | Description |
43
+ |----------|----------|-------------|
44
+ | `WHATSAPP_ACCESS_TOKEN` | Yes | Long-lived access token from Meta Business Manager |
45
+ | `WHATSAPP_PHONE_NUMBER_ID` | Yes | Phone number ID registered in Meta Business |
46
+ | `WHATSAPP_APP_SECRET` | Yes (webhooks) | App Secret for `X-Hub-Signature-256` verification on incoming webhook POSTs |
47
+ | `WHATSAPP_WEBHOOK_VERIFY_TOKEN` | No | Token for Meta's one-time GET webhook subscribe handshake |
48
+ | `WHATSAPP_BUSINESS_ACCOUNT_ID` | No | WABA ID (informational only) |
49
+ | `WHATSAPP_API_VERSION` | No | Graph API version string (default: `v24.0`) |
50
+
51
+ ### Baileys (personal account / QR auth)
52
+
53
+ | Variable | Required | Description |
54
+ |----------|----------|-------------|
55
+ | `WHATSAPP_AUTH_DIR` | Yes (Baileys) | Directory to persist multi-file Baileys auth state |
56
+ | `WHATSAPP_SESSION_PATH` | No | Alternative name for `WHATSAPP_AUTH_DIR` |
57
+ | `WHATSAPP_AUTH_METHOD` | No | Force transport: `cloudapi` or `baileys` (overrides auto-detection) |
58
+
59
+ **Transport detection:** `WHATSAPP_AUTH_METHOD` wins when set. Otherwise: `WHATSAPP_AUTH_DIR` present → Baileys; `WHATSAPP_ACCESS_TOKEN` + `WHATSAPP_PHONE_NUMBER_ID` present → Cloud API. Baileys takes precedence when both are set.
60
+
61
+ ### Access Control
62
+
63
+ | Variable | Default | Description |
64
+ |----------|---------|-------------|
65
+ | `WHATSAPP_DM_POLICY` | `pairing` | `open`, `allowlist`, `pairing`, or `disabled` |
66
+ | `WHATSAPP_GROUP_POLICY` | `allowlist` | `open`, `allowlist`, or `disabled` |
67
+ | `WHATSAPP_ALLOW_FROM` | — | Comma-separated E.164 numbers allowed in DMs (when policy is `allowlist`) |
68
+ | `WHATSAPP_GROUP_ALLOW_FROM` | — | Comma-separated E.164 numbers allowed as group senders |
69
+
70
+ ### Agent Behavior
71
+
72
+ | Variable | Default | Description |
73
+ |----------|---------|-------------|
74
+ | `WHATSAPP_AUTO_REPLY` | `false` | When `true`, inbound messages trigger automatic agent replies. Off by default — messages are stored in memory only |
75
+
76
+ ## Usage
77
+
78
+ ### Accessing the Service
79
+
80
+ ```typescript
81
+ import type { WhatsAppConnectorService } from "@elizaos/plugin-whatsapp";
82
+
83
+ const service = runtime.getService<WhatsAppConnectorService>("whatsapp");
84
+ ```
85
+
86
+ ### Sending a Text Message
87
+
88
+ ```typescript
89
+ await service?.sendMessage({
90
+ type: "text",
91
+ to: "+14155552671", // E.164 format for Cloud API; JID or E.164 for Baileys
92
+ content: "Hello from elizaOS!",
93
+ });
94
+ ```
95
+
96
+ ### Sending a Message with Reply Threading
97
+
98
+ ```typescript
99
+ await service?.sendMessage({
100
+ type: "text",
101
+ to: "+14155552671",
102
+ content: "This is a reply",
103
+ replyToMessageId: "wamid.xxxxx",
104
+ });
105
+ ```
106
+
107
+ ### Creating a Low-Level Client
108
+
109
+ Use `ClientFactory` when you need direct access to Cloud API media endpoints:
110
+
111
+ ```typescript
112
+ import { ClientFactory } from "@elizaos/plugin-whatsapp";
113
+
114
+ // Cloud API
115
+ const client = ClientFactory.create({ accessToken: "...", phoneNumberId: "..." });
116
+
117
+ // Baileys
118
+ const client = ClientFactory.create({ authMethod: "baileys", authDir: "./wa-auth" });
119
+ ```
120
+
121
+ ### Webhook Setup (Cloud API)
122
+
123
+ The plugin automatically registers these HTTP routes on the agent:
124
+
125
+ - `GET /api/whatsapp/webhook` — Meta subscription verification (public)
126
+ - `POST /api/whatsapp/webhook` — Incoming message delivery (validates `X-Hub-Signature-256`)
127
+
128
+ Point your Meta App webhook URL to `https://<your-agent-host>/api/whatsapp/webhook`.
129
+
130
+ ### QR Pairing (Baileys)
131
+
132
+ Start a pairing session via the agent's HTTP API:
133
+
134
+ ```bash
135
+ # Start pairing
136
+ curl -X POST http://localhost:31337/api/whatsapp/pair \
137
+ -H "Content-Type: application/json" \
138
+ -d '{"accountId": "default"}'
139
+
140
+ # Check status
141
+ curl http://localhost:31337/api/whatsapp/status?accountId=default
142
+
143
+ # Stop pairing
144
+ curl -X POST http://localhost:31337/api/whatsapp/pair/stop \
145
+ -H "Content-Type: application/json" \
146
+ -d '{"accountId": "default"}'
147
+
148
+ # Logout and remove auth state
149
+ curl -X POST http://localhost:31337/api/whatsapp/disconnect \
150
+ -H "Content-Type: application/json" \
151
+ -d '{"accountId": "default"}'
152
+ ```
153
+
154
+ ## Multi-Account
155
+
156
+ Configure multiple WhatsApp accounts under `character.settings.whatsapp.accounts.<id>`. Each entry accepts the same fields as the top-level config (`authDir`, `accessToken`, `phoneNumberId`, `dmPolicy`, `groupPolicy`, etc.) plus an optional `name` for display.
157
+
158
+ ## Message Connector Protocol
159
+
160
+ `WhatsAppConnectorService` registers with the elizaOS message connector system. Supported capabilities: `send_message`, `read_messages`, `search_messages`, `send_reaction`, `contact_resolution`, `chat_context`, `get_user`. Target kinds: `phone`, `contact`, `user`, `group`, `room`.
161
+
162
+ Use `source: "whatsapp"` when targeting WhatsApp from an orchestrator or workflow.
163
+
164
+ ## Troubleshooting
165
+
166
+ **Messages not delivered:** Ensure phone numbers are in E.164 format (e.g. `+14155552671`). For Cloud API, bare number strings (no `+`) also work.
167
+
168
+ **Webhook verification fails:** Confirm `WHATSAPP_WEBHOOK_VERIFY_TOKEN` in your env matches the token configured in the Meta Developer Portal webhook settings.
169
+
170
+ **Webhook POST rejected (401):** Set `WHATSAPP_APP_SECRET` to the App Secret shown in your Meta App dashboard.
171
+
172
+ **Baileys QR not appearing:** Start a session with `POST /api/whatsapp/pair`, then poll `GET /api/whatsapp/status` (the status advances to `waiting_for_qr`). The QR itself is delivered as a `whatsapp-qr` event with a `qrDataUrl` field broadcast over the agent's WebSocket — render that data URL.
173
+
174
+ ## License
175
+
176
+ MIT
package/auto-enable.ts ADDED
@@ -0,0 +1,21 @@
1
+ // Auto-enable check for @elizaos/plugin-whatsapp.
2
+ //
3
+ // Plugin manifest entry-point — referenced by package.json's
4
+ // `elizaos.plugin.autoEnableModule`. Keep this module light: env reads only,
5
+ // no service init, no transitive imports of the full plugin runtime. The
6
+ // auto-enable engine loads dozens of these per boot.
7
+ import type { PluginAutoEnableContext } from "@elizaos/core";
8
+
9
+ /** Enable when a `whatsapp` connector block is present and not explicitly disabled. */
10
+ export function shouldEnable(ctx: PluginAutoEnableContext): boolean {
11
+ const c = (ctx.config.connectors as Record<string, unknown> | undefined)
12
+ ?.whatsapp;
13
+ if (!c || typeof c !== "object") return false;
14
+ const config = c as Record<string, unknown>;
15
+ if (config.enabled === false) return false;
16
+ // The full per-connector field check (token/phoneNumberId) lives in the
17
+ // central engine's isConnectorConfigured. We delegate to a simple "block
18
+ // present + not explicitly disabled" check here; the central engine's
19
+ // stricter check remains as a fallback during migration.
20
+ return true;
21
+ }