@chat-adapter/whatsapp 4.20.0 → 4.20.2
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/README.md +130 -17
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
[](https://www.npmjs.com/package/@chat-adapter/whatsapp)
|
|
4
4
|
[](https://www.npmjs.com/package/@chat-adapter/whatsapp)
|
|
5
5
|
|
|
6
|
-
WhatsApp adapter for [Chat SDK](https://chat-sdk.dev
|
|
6
|
+
WhatsApp Business Cloud adapter for [Chat SDK](https://chat-sdk.dev), using the [WhatsApp Business Cloud API](https://developers.facebook.com/docs/whatsapp/cloud-api).
|
|
7
7
|
|
|
8
8
|
## Installation
|
|
9
9
|
|
|
10
10
|
```bash
|
|
11
|
-
|
|
11
|
+
pnpm add @chat-adapter/whatsapp
|
|
12
12
|
```
|
|
13
13
|
|
|
14
14
|
## Usage
|
|
@@ -23,18 +23,65 @@ const bot = new Chat({
|
|
|
23
23
|
whatsapp: createWhatsAppAdapter(),
|
|
24
24
|
},
|
|
25
25
|
});
|
|
26
|
+
|
|
27
|
+
bot.onNewMention(async (thread, message) => {
|
|
28
|
+
await thread.post("Hello from WhatsApp!");
|
|
29
|
+
});
|
|
26
30
|
```
|
|
27
31
|
|
|
28
32
|
When using `createWhatsAppAdapter()` without arguments, credentials are auto-detected from environment variables.
|
|
29
33
|
|
|
34
|
+
## WhatsApp Business setup
|
|
35
|
+
|
|
36
|
+
### 1. Create a Meta app
|
|
37
|
+
|
|
38
|
+
1. Go to [developers.facebook.com/apps](https://developers.facebook.com/apps)
|
|
39
|
+
2. Click **Create App**, select **Business** type
|
|
40
|
+
3. Add the **WhatsApp** product to your app
|
|
41
|
+
4. Go to **WhatsApp > API Setup** and note your **Phone Number ID** and **Access Token**
|
|
42
|
+
|
|
43
|
+
### 2. Configure webhooks
|
|
44
|
+
|
|
45
|
+
1. Go to **WhatsApp > Configuration** in your Meta app
|
|
46
|
+
2. Set **Callback URL** to `https://your-domain.com/api/webhooks/whatsapp`
|
|
47
|
+
3. Set **Verify Token** to a secret string of your choice (this becomes `WHATSAPP_VERIFY_TOKEN`)
|
|
48
|
+
4. Subscribe to the `messages` webhook field
|
|
49
|
+
|
|
50
|
+
### 3. Get credentials
|
|
51
|
+
|
|
52
|
+
From your Meta app dashboard, copy:
|
|
53
|
+
|
|
54
|
+
- **App Secret** (under **App Settings > Basic**) as `WHATSAPP_APP_SECRET`
|
|
55
|
+
- **Access Token** (under **WhatsApp > API Setup**) as `WHATSAPP_ACCESS_TOKEN`
|
|
56
|
+
- **Phone Number ID** (under **WhatsApp > API Setup**) as `WHATSAPP_PHONE_NUMBER_ID`
|
|
57
|
+
|
|
58
|
+
For production, generate a permanent **System User Token** instead of the temporary access token.
|
|
59
|
+
|
|
60
|
+
## Configuration
|
|
61
|
+
|
|
62
|
+
All options are auto-detected from environment variables when not provided. You can call `createWhatsAppAdapter()` with no arguments if the env vars are set.
|
|
63
|
+
|
|
64
|
+
| Option | Required | Description |
|
|
65
|
+
|--------|----------|-------------|
|
|
66
|
+
| `accessToken` | No* | Meta access token. Auto-detected from `WHATSAPP_ACCESS_TOKEN` |
|
|
67
|
+
| `appSecret` | No* | App secret for webhook verification. Auto-detected from `WHATSAPP_APP_SECRET` |
|
|
68
|
+
| `phoneNumberId` | No* | Bot's phone number ID. Auto-detected from `WHATSAPP_PHONE_NUMBER_ID` |
|
|
69
|
+
| `verifyToken` | No* | Webhook verification secret. Auto-detected from `WHATSAPP_VERIFY_TOKEN` |
|
|
70
|
+
| `apiVersion` | No | Graph API version (defaults to `v21.0`) |
|
|
71
|
+
| `userName` | No | Bot username for self-message detection. Auto-detected from `WHATSAPP_BOT_USERNAME` (defaults to `whatsapp-bot`) |
|
|
72
|
+
| `logger` | No | Logger instance (defaults to `ConsoleLogger("info")`) |
|
|
73
|
+
|
|
74
|
+
*Required at runtime — either via config or environment variable.
|
|
75
|
+
|
|
30
76
|
## Environment variables
|
|
31
77
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
78
|
+
```bash
|
|
79
|
+
WHATSAPP_ACCESS_TOKEN=... # Meta access token (permanent or system user token)
|
|
80
|
+
WHATSAPP_APP_SECRET=... # App secret for X-Hub-Signature-256 verification
|
|
81
|
+
WHATSAPP_PHONE_NUMBER_ID=... # Bot's phone number ID from Meta dashboard
|
|
82
|
+
WHATSAPP_VERIFY_TOKEN=... # User-defined secret for webhook verification
|
|
83
|
+
WHATSAPP_BOT_USERNAME=... # Optional, defaults to "whatsapp-bot"
|
|
84
|
+
```
|
|
38
85
|
|
|
39
86
|
## Webhook setup
|
|
40
87
|
|
|
@@ -56,18 +103,65 @@ export async function POST(request: Request) {
|
|
|
56
103
|
}
|
|
57
104
|
```
|
|
58
105
|
|
|
106
|
+
## Features
|
|
107
|
+
|
|
108
|
+
### Messaging
|
|
109
|
+
|
|
110
|
+
| Feature | Supported |
|
|
111
|
+
|---------|-----------|
|
|
112
|
+
| Post message | Yes |
|
|
113
|
+
| Edit message | No (WhatsApp limitation) |
|
|
114
|
+
| Delete message | No (WhatsApp limitation) |
|
|
115
|
+
| Streaming | Buffered (accumulates then sends) |
|
|
116
|
+
| Mark as read | Yes |
|
|
117
|
+
| Auto-chunking | Yes (splits at 4096 chars) |
|
|
118
|
+
|
|
119
|
+
### Rich content
|
|
120
|
+
|
|
121
|
+
| Feature | Supported |
|
|
122
|
+
|---------|-----------|
|
|
123
|
+
| Interactive buttons | Yes (up to 3) |
|
|
124
|
+
| Button title limit | 20 characters |
|
|
125
|
+
| List messages | Yes |
|
|
126
|
+
| Text fallback | Yes (for >3 buttons) |
|
|
127
|
+
|
|
128
|
+
### Conversations
|
|
129
|
+
|
|
130
|
+
| Feature | Supported |
|
|
131
|
+
|---------|-----------|
|
|
132
|
+
| Reactions | Yes (add and remove) |
|
|
133
|
+
| Typing indicator | No (not supported by Cloud API) |
|
|
134
|
+
| DMs | Yes |
|
|
135
|
+
| Open DM | Yes |
|
|
136
|
+
|
|
137
|
+
### Incoming message types
|
|
138
|
+
|
|
139
|
+
| Type | Supported |
|
|
140
|
+
|------|-----------|
|
|
141
|
+
| Text | Yes |
|
|
142
|
+
| Images | Yes (with captions) |
|
|
143
|
+
| Documents | Yes (with captions) |
|
|
144
|
+
| Audio / Voice | Yes |
|
|
145
|
+
| Video | Yes (with captions) |
|
|
146
|
+
| Stickers | Yes |
|
|
147
|
+
| Locations | Yes (converted to map URL) |
|
|
148
|
+
| Interactive replies | Yes (button and list) |
|
|
149
|
+
| Reactions | Yes |
|
|
150
|
+
|
|
151
|
+
### Message history
|
|
152
|
+
|
|
153
|
+
| Feature | Supported |
|
|
154
|
+
|---------|-----------|
|
|
155
|
+
| Fetch messages | No (Cloud API limitation) |
|
|
156
|
+
| Fetch thread info | Yes |
|
|
157
|
+
|
|
59
158
|
## Interactive messages
|
|
60
159
|
|
|
61
160
|
Card elements are automatically converted to WhatsApp interactive messages:
|
|
62
161
|
|
|
63
|
-
- **3 or fewer buttons** — rendered as WhatsApp reply buttons
|
|
162
|
+
- **3 or fewer buttons** — rendered as WhatsApp reply buttons (max 20 chars per title)
|
|
64
163
|
- **More than 3 buttons** — falls back to formatted text
|
|
65
|
-
|
|
66
|
-
## Limitations
|
|
67
|
-
|
|
68
|
-
- **No message editing** — `editMessage()` throws (WhatsApp limitation)
|
|
69
|
-
- **No message deletion** — `deleteMessage()` throws (WhatsApp limitation)
|
|
70
|
-
- **No message history API** — `fetchMessages()` returns empty results
|
|
164
|
+
- **Max body text** — 1024 characters
|
|
71
165
|
|
|
72
166
|
## Thread ID format
|
|
73
167
|
|
|
@@ -77,9 +171,28 @@ whatsapp:{phoneNumberId}:{userWaId}
|
|
|
77
171
|
|
|
78
172
|
Example: `whatsapp:1234567890:15551234567`
|
|
79
173
|
|
|
80
|
-
##
|
|
174
|
+
## Troubleshooting
|
|
175
|
+
|
|
176
|
+
### Webhook verification failing
|
|
177
|
+
|
|
178
|
+
- Confirm `WHATSAPP_VERIFY_TOKEN` matches the value you entered in the Meta dashboard
|
|
179
|
+
- Ensure your endpoint returns the `hub.challenge` value for GET requests
|
|
180
|
+
|
|
181
|
+
### Messages not arriving
|
|
182
|
+
|
|
183
|
+
- Check that you subscribed to the `messages` webhook field in Meta app settings
|
|
184
|
+
- Verify `WHATSAPP_APP_SECRET` is correct — signature verification silently rejects invalid payloads
|
|
185
|
+
- Ensure your phone number is registered and verified in the WhatsApp Business dashboard
|
|
186
|
+
|
|
187
|
+
### "Invalid signature" errors
|
|
188
|
+
|
|
189
|
+
- Double-check `WHATSAPP_APP_SECRET` matches the value under **App Settings > Basic**
|
|
190
|
+
- The adapter uses HMAC-SHA256 to verify the `X-Hub-Signature-256` header
|
|
191
|
+
|
|
192
|
+
### Token expired
|
|
81
193
|
|
|
82
|
-
|
|
194
|
+
- Temporary tokens from the API Setup page expire after 24 hours
|
|
195
|
+
- For production, create a **System User** in Meta Business Suite and generate a permanent token
|
|
83
196
|
|
|
84
197
|
## License
|
|
85
198
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chat-adapter/whatsapp",
|
|
3
|
-
"version": "4.20.
|
|
3
|
+
"version": "4.20.2",
|
|
4
4
|
"description": "WhatsApp adapter for chat - WhatsApp Business Cloud API",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
"dist"
|
|
17
17
|
],
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@chat-adapter/shared": "4.20.
|
|
20
|
-
"chat": "4.20.
|
|
19
|
+
"@chat-adapter/shared": "4.20.2",
|
|
20
|
+
"chat": "4.20.2"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@types/node": "^25.3.2",
|