@elizaos/plugin-whatsapp 1.0.0 → 2.0.0-alpha.10
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.js +1508 -24
- package/dist/index.js.map +25 -1
- package/dist/src/accounts.d.ts +199 -0
- package/dist/src/accounts.d.ts.map +1 -0
- package/dist/src/actions/index.d.ts +3 -0
- package/dist/src/actions/index.d.ts.map +1 -0
- package/dist/src/actions/sendMessage.d.ts +4 -0
- package/dist/src/actions/sendMessage.d.ts.map +1 -0
- package/dist/src/actions/sendReaction.d.ts +4 -0
- package/dist/src/actions/sendReaction.d.ts.map +1 -0
- package/dist/src/baileys/auth.d.ts +10 -0
- package/dist/src/baileys/auth.d.ts.map +1 -0
- package/dist/src/baileys/connection.d.ts +19 -0
- package/dist/src/baileys/connection.d.ts.map +1 -0
- package/dist/src/baileys/index.d.ts +5 -0
- package/dist/src/baileys/index.d.ts.map +1 -0
- package/dist/src/baileys/message-adapter.d.ts +13 -0
- package/dist/src/baileys/message-adapter.d.ts.map +1 -0
- package/dist/src/baileys/qr-code.d.ts +6 -0
- package/dist/src/baileys/qr-code.d.ts.map +1 -0
- package/dist/src/client.d.ts +88 -0
- package/dist/src/client.d.ts.map +1 -0
- package/dist/src/clients/baileys-client.d.ts +17 -0
- package/dist/src/clients/baileys-client.d.ts.map +1 -0
- package/dist/src/clients/factory.d.ts +6 -0
- package/dist/src/clients/factory.d.ts.map +1 -0
- package/dist/src/clients/index.d.ts +4 -0
- package/dist/src/clients/index.d.ts.map +1 -0
- package/dist/src/clients/interface.d.ts +10 -0
- package/dist/src/clients/interface.d.ts.map +1 -0
- package/dist/src/config.d.ts +135 -0
- package/dist/src/config.d.ts.map +1 -0
- package/dist/src/handlers/index.d.ts +3 -0
- package/dist/src/handlers/index.d.ts.map +1 -0
- package/dist/src/handlers/message.handler.d.ts +8 -0
- package/dist/src/handlers/message.handler.d.ts.map +1 -0
- package/dist/src/handlers/webhook.handler.d.ts +7 -0
- package/dist/src/handlers/webhook.handler.d.ts.map +1 -0
- package/dist/src/index.d.ts +27 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/normalize.d.ts +69 -0
- package/dist/src/normalize.d.ts.map +1 -0
- package/dist/src/service.d.ts +117 -0
- package/dist/src/service.d.ts.map +1 -0
- package/dist/src/types.d.ts +367 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/utils/config-detector.d.ts +3 -0
- package/dist/src/utils/config-detector.d.ts.map +1 -0
- package/dist/src/utils/index.d.ts +3 -0
- package/dist/src/utils/index.d.ts.map +1 -0
- package/dist/src/utils/validators.d.ts +10 -0
- package/dist/src/utils/validators.d.ts.map +1 -0
- package/package.json +129 -75
- package/LICENSE +0 -21
- package/README.md +0 -226
- package/dist/index.d.ts +0 -71
package/README.md
DELETED
|
@@ -1,226 +0,0 @@
|
|
|
1
|
-
# @elizaos/plugin-whatsapp
|
|
2
|
-
|
|
3
|
-
A plugin for integrating WhatsApp Cloud API with your application, providing comprehensive messaging capabilities and webhook handling.
|
|
4
|
-
|
|
5
|
-
## Overview
|
|
6
|
-
|
|
7
|
-
This plugin provides functionality to:
|
|
8
|
-
|
|
9
|
-
- Send text and template messages via WhatsApp
|
|
10
|
-
- Handle incoming webhook events
|
|
11
|
-
- Manage message status updates
|
|
12
|
-
- Process message delivery notifications
|
|
13
|
-
- Handle authentication and session management
|
|
14
|
-
|
|
15
|
-
## Installation
|
|
16
|
-
|
|
17
|
-
```bash
|
|
18
|
-
bun add @elizaos/plugin-whatsapp
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
## Configuration
|
|
22
|
-
|
|
23
|
-
The plugin requires the following environment variables:
|
|
24
|
-
|
|
25
|
-
```env
|
|
26
|
-
WHATSAPP_ACCESS_TOKEN=your_access_token # Required: WhatsApp Cloud API access token
|
|
27
|
-
WHATSAPP_PHONE_NUMBER_ID=your_phone_number_id # Required: WhatsApp business phone number ID
|
|
28
|
-
WHATSAPP_WEBHOOK_TOKEN=your_webhook_token # Optional: Webhook verification token
|
|
29
|
-
WHATSAPP_BUSINESS_ID=your_business_id # Optional: Business account ID
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
## Usage
|
|
33
|
-
|
|
34
|
-
### Basic Setup
|
|
35
|
-
|
|
36
|
-
```typescript
|
|
37
|
-
import { WhatsAppPlugin } from "@elizaos/plugin-whatsapp";
|
|
38
|
-
|
|
39
|
-
const whatsappPlugin = new WhatsAppPlugin({
|
|
40
|
-
accessToken: "your_access_token",
|
|
41
|
-
phoneNumberId: "your_phone_number_id",
|
|
42
|
-
webhookVerifyToken: "your_webhook_verify_token",
|
|
43
|
-
businessAccountId: "your_business_account_id",
|
|
44
|
-
});
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
### Sending Messages
|
|
48
|
-
|
|
49
|
-
```typescript
|
|
50
|
-
// Send a text message
|
|
51
|
-
await whatsappPlugin.sendMessage({
|
|
52
|
-
type: "text",
|
|
53
|
-
to: "1234567890",
|
|
54
|
-
content: "Hello from WhatsApp!",
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
// Send a template message
|
|
58
|
-
await whatsappPlugin.sendMessage({
|
|
59
|
-
type: "template",
|
|
60
|
-
to: "1234567890",
|
|
61
|
-
content: {
|
|
62
|
-
name: "hello_world",
|
|
63
|
-
language: {
|
|
64
|
-
code: "en",
|
|
65
|
-
},
|
|
66
|
-
},
|
|
67
|
-
});
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
### Handling Webhooks
|
|
71
|
-
|
|
72
|
-
```typescript
|
|
73
|
-
// Verify webhook
|
|
74
|
-
app.get("/webhook", (req, res) => {
|
|
75
|
-
const verified = await whatsappPlugin.verifyWebhook(
|
|
76
|
-
req.query["hub.verify_token"]
|
|
77
|
-
);
|
|
78
|
-
if (verified) {
|
|
79
|
-
res.send(req.query["hub.challenge"]);
|
|
80
|
-
} else {
|
|
81
|
-
res.sendStatus(403);
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
// Handle webhook events
|
|
86
|
-
app.post("/webhook", (req, res) => {
|
|
87
|
-
await whatsappPlugin.handleWebhook(req.body);
|
|
88
|
-
res.sendStatus(200);
|
|
89
|
-
});
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
## Features
|
|
93
|
-
|
|
94
|
-
- Send text messages
|
|
95
|
-
- Send template messages
|
|
96
|
-
- Webhook verification
|
|
97
|
-
- Webhook event handling
|
|
98
|
-
- Message status updates
|
|
99
|
-
|
|
100
|
-
## Error Handling
|
|
101
|
-
|
|
102
|
-
The plugin throws errors in the following cases:
|
|
103
|
-
|
|
104
|
-
```typescript
|
|
105
|
-
try {
|
|
106
|
-
await whatsappPlugin.sendMessage({
|
|
107
|
-
type: "text",
|
|
108
|
-
to: "1234567890",
|
|
109
|
-
content: "Hello!",
|
|
110
|
-
});
|
|
111
|
-
} catch (error) {
|
|
112
|
-
console.error("Failed to send message:", error.message);
|
|
113
|
-
}
|
|
114
|
-
```
|
|
115
|
-
|
|
116
|
-
Common error cases:
|
|
117
|
-
|
|
118
|
-
- Invalid configuration
|
|
119
|
-
- Failed message sending
|
|
120
|
-
- Webhook verification failure
|
|
121
|
-
- Invalid webhook payload
|
|
122
|
-
|
|
123
|
-
## Best Practices
|
|
124
|
-
|
|
125
|
-
1. Always validate phone numbers before sending messages
|
|
126
|
-
2. Use template messages for first-time messages to users
|
|
127
|
-
3. Store message IDs for tracking delivery status
|
|
128
|
-
4. Implement proper error handling
|
|
129
|
-
5. Set up webhook retry mechanisms
|
|
130
|
-
6. Keep your access tokens secure
|
|
131
|
-
|
|
132
|
-
## API Reference
|
|
133
|
-
|
|
134
|
-
### Core Interfaces
|
|
135
|
-
|
|
136
|
-
```typescript
|
|
137
|
-
interface WhatsAppConfig {
|
|
138
|
-
accessToken: string;
|
|
139
|
-
phoneNumberId: string;
|
|
140
|
-
webhookVerifyToken?: string;
|
|
141
|
-
businessAccountId?: string;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
interface WhatsAppMessage {
|
|
145
|
-
type: "text" | "template";
|
|
146
|
-
to: string;
|
|
147
|
-
content: string | WhatsAppTemplate;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
interface WhatsAppTemplate {
|
|
151
|
-
name: string;
|
|
152
|
-
language: {
|
|
153
|
-
code: string;
|
|
154
|
-
};
|
|
155
|
-
components?: Array<{
|
|
156
|
-
type: string;
|
|
157
|
-
parameters: Array<{
|
|
158
|
-
type: string;
|
|
159
|
-
text?: string;
|
|
160
|
-
}>;
|
|
161
|
-
}>;
|
|
162
|
-
}
|
|
163
|
-
```
|
|
164
|
-
|
|
165
|
-
### Plugin Methods
|
|
166
|
-
|
|
167
|
-
- `sendMessage`: Send WhatsApp messages
|
|
168
|
-
- `handleWebhook`: Process incoming webhook events
|
|
169
|
-
- `verifyWebhook`: Verify webhook authenticity
|
|
170
|
-
- Message and status handlers
|
|
171
|
-
|
|
172
|
-
## Development
|
|
173
|
-
|
|
174
|
-
### Building
|
|
175
|
-
|
|
176
|
-
```bash
|
|
177
|
-
bun run build
|
|
178
|
-
```
|
|
179
|
-
|
|
180
|
-
### Testing
|
|
181
|
-
|
|
182
|
-
```bash
|
|
183
|
-
bun test
|
|
184
|
-
```
|
|
185
|
-
|
|
186
|
-
### Linting
|
|
187
|
-
|
|
188
|
-
```bash
|
|
189
|
-
bun run lint
|
|
190
|
-
```
|
|
191
|
-
|
|
192
|
-
## Security Best Practices
|
|
193
|
-
|
|
194
|
-
- Store credentials securely using environment variables
|
|
195
|
-
- Validate all phone numbers before sending messages
|
|
196
|
-
- Use template messages for first-time contacts
|
|
197
|
-
- Implement proper error handling
|
|
198
|
-
- Keep dependencies updated
|
|
199
|
-
- Monitor API usage and rate limits
|
|
200
|
-
- Use HTTPS for all API communication
|
|
201
|
-
|
|
202
|
-
## Contributing
|
|
203
|
-
|
|
204
|
-
Contributions are welcome! Please see the [CONTRIBUTING.md](CONTRIBUTING.md) file for more information.
|
|
205
|
-
|
|
206
|
-
## Credits
|
|
207
|
-
|
|
208
|
-
This plugin integrates with and builds upon several key technologies:
|
|
209
|
-
|
|
210
|
-
- [WhatsApp Cloud API](https://developers.facebook.com/docs/whatsapp/cloud-api): Meta's official WhatsApp Business Platform
|
|
211
|
-
- [Axios](https://axios-http.com/): Promise-based HTTP client for API requests
|
|
212
|
-
- [Meta for Developers](https://developers.facebook.com/): Meta's developer platform and tools
|
|
213
|
-
|
|
214
|
-
Special thanks to:
|
|
215
|
-
|
|
216
|
-
- The Eliza community for their contributions and feedback
|
|
217
|
-
|
|
218
|
-
For more information about WhatsApp Cloud API and its capabilities, visit:
|
|
219
|
-
|
|
220
|
-
- [WhatsApp Business Platform Documentation](https://developers.facebook.com/docs/whatsapp/cloud-api/overview)
|
|
221
|
-
- [Meta for Developers Blog](https://developers.facebook.com/blog/)
|
|
222
|
-
- [WhatsApp Business API GitHub](https://github.com/WhatsApp/WhatsApp-Business-API-Setup-Scripts)
|
|
223
|
-
|
|
224
|
-
## License
|
|
225
|
-
|
|
226
|
-
This plugin is part of the Eliza project. See the main project repository for license information.
|
package/dist/index.d.ts
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { Plugin } from '@elizaos/core';
|
|
2
|
-
|
|
3
|
-
interface WhatsAppConfig {
|
|
4
|
-
accessToken: string;
|
|
5
|
-
phoneNumberId: string;
|
|
6
|
-
webhookVerifyToken?: string;
|
|
7
|
-
businessAccountId?: string;
|
|
8
|
-
}
|
|
9
|
-
interface WhatsAppMessage {
|
|
10
|
-
type: "text" | "template";
|
|
11
|
-
to: string;
|
|
12
|
-
content: string | WhatsAppTemplate;
|
|
13
|
-
}
|
|
14
|
-
interface WhatsAppTemplate {
|
|
15
|
-
name: string;
|
|
16
|
-
language: {
|
|
17
|
-
code: string;
|
|
18
|
-
};
|
|
19
|
-
components?: Array<{
|
|
20
|
-
type: string;
|
|
21
|
-
parameters: Array<{
|
|
22
|
-
type: string;
|
|
23
|
-
text?: string;
|
|
24
|
-
}>;
|
|
25
|
-
}>;
|
|
26
|
-
}
|
|
27
|
-
interface WhatsAppWebhookEvent {
|
|
28
|
-
object: string;
|
|
29
|
-
entry: Array<{
|
|
30
|
-
id: string;
|
|
31
|
-
changes: Array<{
|
|
32
|
-
value: {
|
|
33
|
-
messaging_product: string;
|
|
34
|
-
metadata: {
|
|
35
|
-
display_phone_number: string;
|
|
36
|
-
phone_number_id: string;
|
|
37
|
-
};
|
|
38
|
-
statuses?: Array<{
|
|
39
|
-
id: string;
|
|
40
|
-
status: string;
|
|
41
|
-
timestamp: string;
|
|
42
|
-
recipient_id: string;
|
|
43
|
-
}>;
|
|
44
|
-
messages?: Array<{
|
|
45
|
-
from: string;
|
|
46
|
-
id: string;
|
|
47
|
-
timestamp: string;
|
|
48
|
-
text?: {
|
|
49
|
-
body: string;
|
|
50
|
-
};
|
|
51
|
-
type: string;
|
|
52
|
-
}>;
|
|
53
|
-
};
|
|
54
|
-
field: string;
|
|
55
|
-
}>;
|
|
56
|
-
}>;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
declare class WhatsAppPlugin implements Plugin {
|
|
60
|
-
private client;
|
|
61
|
-
private messageHandler;
|
|
62
|
-
private webhookHandler;
|
|
63
|
-
name: string;
|
|
64
|
-
description: string;
|
|
65
|
-
constructor(config: WhatsAppConfig);
|
|
66
|
-
sendMessage(message: WhatsAppMessage): Promise<any>;
|
|
67
|
-
handleWebhook(event: WhatsAppWebhookEvent): Promise<void>;
|
|
68
|
-
verifyWebhook(token: string): Promise<boolean>;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export { type WhatsAppConfig, type WhatsAppMessage, WhatsAppPlugin, type WhatsAppTemplate, type WhatsAppWebhookEvent };
|