@elizaos/plugin-whatsapp 1.0.0 → 2.0.0-alpha.1
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/LICENSE +2 -2
- package/README.md +4 -4
- package/dist/index.d.ts +30 -18
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/package.json +26 -27
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c)
|
|
3
|
+
Copyright (c) 2026 Shaw Walters and elizaOS Contributors
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
|
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
18
18
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
19
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
20
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -15,7 +15,7 @@ This plugin provides functionality to:
|
|
|
15
15
|
## Installation
|
|
16
16
|
|
|
17
17
|
```bash
|
|
18
|
-
|
|
18
|
+
npm install @elizaos/plugin-whatsapp
|
|
19
19
|
```
|
|
20
20
|
|
|
21
21
|
## Configuration
|
|
@@ -174,19 +174,19 @@ interface WhatsAppTemplate {
|
|
|
174
174
|
### Building
|
|
175
175
|
|
|
176
176
|
```bash
|
|
177
|
-
|
|
177
|
+
npm run build
|
|
178
178
|
```
|
|
179
179
|
|
|
180
180
|
### Testing
|
|
181
181
|
|
|
182
182
|
```bash
|
|
183
|
-
|
|
183
|
+
npm run test
|
|
184
184
|
```
|
|
185
185
|
|
|
186
186
|
### Linting
|
|
187
187
|
|
|
188
188
|
```bash
|
|
189
|
-
|
|
189
|
+
npm run lint
|
|
190
190
|
```
|
|
191
191
|
|
|
192
192
|
## Security Best Practices
|
package/dist/index.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ interface WhatsAppConfig {
|
|
|
7
7
|
businessAccountId?: string;
|
|
8
8
|
}
|
|
9
9
|
interface WhatsAppMessage {
|
|
10
|
-
type:
|
|
10
|
+
type: 'text' | 'template';
|
|
11
11
|
to: string;
|
|
12
12
|
content: string | WhatsAppTemplate;
|
|
13
13
|
}
|
|
@@ -24,6 +24,21 @@ interface WhatsAppTemplate {
|
|
|
24
24
|
}>;
|
|
25
25
|
}>;
|
|
26
26
|
}
|
|
27
|
+
interface WhatsAppIncomingMessage {
|
|
28
|
+
from: string;
|
|
29
|
+
id: string;
|
|
30
|
+
timestamp: string;
|
|
31
|
+
text?: {
|
|
32
|
+
body: string;
|
|
33
|
+
};
|
|
34
|
+
type: string;
|
|
35
|
+
}
|
|
36
|
+
interface WhatsAppStatusUpdate {
|
|
37
|
+
id: string;
|
|
38
|
+
status: string;
|
|
39
|
+
timestamp: string;
|
|
40
|
+
recipient_id: string;
|
|
41
|
+
}
|
|
27
42
|
interface WhatsAppWebhookEvent {
|
|
28
43
|
object: string;
|
|
29
44
|
entry: Array<{
|
|
@@ -35,26 +50,23 @@ interface WhatsAppWebhookEvent {
|
|
|
35
50
|
display_phone_number: string;
|
|
36
51
|
phone_number_id: string;
|
|
37
52
|
};
|
|
38
|
-
statuses?:
|
|
39
|
-
|
|
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
|
+
statuses?: WhatsAppStatusUpdate[];
|
|
54
|
+
messages?: WhatsAppIncomingMessage[];
|
|
53
55
|
};
|
|
54
56
|
field: string;
|
|
55
57
|
}>;
|
|
56
58
|
}>;
|
|
57
59
|
}
|
|
60
|
+
interface WhatsAppMessageResponse {
|
|
61
|
+
messaging_product: string;
|
|
62
|
+
contacts: Array<{
|
|
63
|
+
input: string;
|
|
64
|
+
wa_id: string;
|
|
65
|
+
}>;
|
|
66
|
+
messages: Array<{
|
|
67
|
+
id: string;
|
|
68
|
+
}>;
|
|
69
|
+
}
|
|
58
70
|
|
|
59
71
|
declare class WhatsAppPlugin implements Plugin {
|
|
60
72
|
private client;
|
|
@@ -63,9 +75,9 @@ declare class WhatsAppPlugin implements Plugin {
|
|
|
63
75
|
name: string;
|
|
64
76
|
description: string;
|
|
65
77
|
constructor(config: WhatsAppConfig);
|
|
66
|
-
sendMessage(message: WhatsAppMessage): Promise<
|
|
78
|
+
sendMessage(message: WhatsAppMessage): Promise<WhatsAppMessageResponse>;
|
|
67
79
|
handleWebhook(event: WhatsAppWebhookEvent): Promise<void>;
|
|
68
80
|
verifyWebhook(token: string): Promise<boolean>;
|
|
69
81
|
}
|
|
70
82
|
|
|
71
|
-
export { type WhatsAppConfig, type WhatsAppMessage, WhatsAppPlugin, type WhatsAppTemplate, type WhatsAppWebhookEvent };
|
|
83
|
+
export { type WhatsAppConfig, type WhatsAppIncomingMessage, type WhatsAppMessage, type WhatsAppMessageResponse, WhatsAppPlugin, type WhatsAppStatusUpdate, type WhatsAppTemplate, type WhatsAppWebhookEvent };
|
package/dist/index.js
CHANGED
|
@@ -53,14 +53,15 @@ var WebhookHandler = class {
|
|
|
53
53
|
this.client = client;
|
|
54
54
|
}
|
|
55
55
|
async handle(event) {
|
|
56
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
56
57
|
try {
|
|
57
|
-
if (event.entry
|
|
58
|
+
if ((_e = (_d = (_c = (_b = (_a = event.entry) == null ? void 0 : _a[0]) == null ? void 0 : _b.changes) == null ? void 0 : _c[0]) == null ? void 0 : _d.value) == null ? void 0 : _e.messages) {
|
|
58
59
|
const messages = event.entry[0].changes[0].value.messages;
|
|
59
60
|
for (const message of messages) {
|
|
60
61
|
await this.handleMessage(message);
|
|
61
62
|
}
|
|
62
63
|
}
|
|
63
|
-
if (event.entry
|
|
64
|
+
if ((_j = (_i = (_h = (_g = (_f = event.entry) == null ? void 0 : _f[0]) == null ? void 0 : _g.changes) == null ? void 0 : _h[0]) == null ? void 0 : _i.value) == null ? void 0 : _j.statuses) {
|
|
64
65
|
const statuses = event.entry[0].changes[0].value.statuses;
|
|
65
66
|
for (const status of statuses) {
|
|
66
67
|
await this.handleStatus(status);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/client.ts","../src/handlers/message.handler.ts","../src/handlers/webhook.handler.ts","../src/index.ts"],"sourcesContent":["import axios, { type AxiosInstance } from
|
|
1
|
+
{"version":3,"sources":["../src/client.ts","../src/handlers/message.handler.ts","../src/handlers/webhook.handler.ts","../src/index.ts"],"sourcesContent":["import axios, { type AxiosInstance, type AxiosResponse } from 'axios';\nimport type { WhatsAppConfig, WhatsAppMessage, WhatsAppMessageResponse } from './types';\n\nexport class WhatsAppClient {\n private client: AxiosInstance;\n private config: WhatsAppConfig;\n\n constructor(config: WhatsAppConfig) {\n this.config = config;\n this.client = axios.create({\n baseURL: 'https://graph.facebook.com/v17.0',\n headers: {\n Authorization: `Bearer ${config.accessToken}`,\n 'Content-Type': 'application/json',\n },\n });\n }\n\n async sendMessage(message: WhatsAppMessage): Promise<AxiosResponse<WhatsAppMessageResponse>> {\n const endpoint = `/${this.config.phoneNumberId}/messages`;\n\n const payload = {\n messaging_product: 'whatsapp',\n recipient_type: 'individual',\n to: message.to,\n type: message.type,\n ...(message.type === 'text'\n ? { text: { body: message.content } }\n : { template: message.content }),\n };\n\n return this.client.post(endpoint, payload);\n }\n\n async verifyWebhook(token: string): Promise<boolean> {\n return token === this.config.webhookVerifyToken;\n }\n}\n","import type { WhatsAppClient } from '../client';\nimport type { WhatsAppMessage, WhatsAppMessageResponse } from '../types';\n\nexport class MessageHandler {\n constructor(private client: WhatsAppClient) {}\n\n async send(message: WhatsAppMessage): Promise<WhatsAppMessageResponse> {\n try {\n const response = await this.client.sendMessage(message);\n return response.data;\n } catch (error: unknown) {\n if (error instanceof Error) {\n throw new Error(`Failed to send WhatsApp message: ${error.message}`);\n }\n throw new Error('Failed to send WhatsApp message');\n }\n }\n}\n","import type { WhatsAppClient } from '../client';\nimport type { WhatsAppIncomingMessage, WhatsAppStatusUpdate, WhatsAppWebhookEvent } from '../types';\n\nexport class WebhookHandler {\n constructor(private client: WhatsAppClient) {}\n\n async handle(event: WhatsAppWebhookEvent): Promise<void> {\n try {\n // Process messages\n if (event.entry?.[0]?.changes?.[0]?.value?.messages) {\n const messages = event.entry[0].changes[0].value.messages;\n for (const message of messages) {\n await this.handleMessage(message);\n }\n }\n\n // Process status updates\n if (event.entry?.[0]?.changes?.[0]?.value?.statuses) {\n const statuses = event.entry[0].changes[0].value.statuses;\n for (const status of statuses) {\n await this.handleStatus(status);\n }\n }\n } catch (error: unknown) {\n if (error instanceof Error) {\n throw new Error(`Failed to send WhatsApp message: ${error.message}`);\n }\n throw new Error('Failed to send WhatsApp message');\n }\n }\n\n private async handleMessage(message: WhatsAppIncomingMessage): Promise<void> {\n // Implement message handling logic\n // This could emit events or trigger callbacks based on your framework's needs\n console.log('Received message:', message);\n }\n\n private async handleStatus(status: WhatsAppStatusUpdate): Promise<void> {\n // Implement status update handling logic\n // This could emit events or trigger callbacks based on your framework's needs\n console.log('Received status update:', status);\n }\n}\n","import type { Plugin } from '@elizaos/core';\nimport { WhatsAppClient } from './client';\nimport { MessageHandler, WebhookHandler } from './handlers';\nimport type {\n WhatsAppConfig,\n WhatsAppMessage,\n WhatsAppMessageResponse,\n WhatsAppWebhookEvent,\n} from './types';\n\nexport class WhatsAppPlugin implements Plugin {\n private client: WhatsAppClient;\n private messageHandler: MessageHandler;\n private webhookHandler: WebhookHandler;\n\n name: string;\n description: string;\n\n constructor(config: WhatsAppConfig) {\n this.name = 'WhatsApp Cloud API Plugin';\n this.description = 'A plugin for integrating WhatsApp Cloud API with your application.';\n this.client = new WhatsAppClient(config);\n this.messageHandler = new MessageHandler(this.client);\n this.webhookHandler = new WebhookHandler(this.client);\n }\n\n async sendMessage(message: WhatsAppMessage): Promise<WhatsAppMessageResponse> {\n return this.messageHandler.send(message);\n }\n\n async handleWebhook(event: WhatsAppWebhookEvent): Promise<void> {\n return this.webhookHandler.handle(event);\n }\n\n async verifyWebhook(token: string): Promise<boolean> {\n return this.client.verifyWebhook(token);\n }\n}\n\nexport * from './types';\n"],"mappings":";AAAA,OAAO,WAAuD;AAGvD,IAAM,iBAAN,MAAqB;AAAA,EAChB;AAAA,EACA;AAAA,EAER,YAAY,QAAwB;AAChC,SAAK,SAAS;AACd,SAAK,SAAS,MAAM,OAAO;AAAA,MACvB,SAAS;AAAA,MACT,SAAS;AAAA,QACL,eAAe,UAAU,OAAO,WAAW;AAAA,QAC3C,gBAAgB;AAAA,MACpB;AAAA,IACJ,CAAC;AAAA,EACL;AAAA,EAEA,MAAM,YAAY,SAA2E;AACzF,UAAM,WAAW,IAAI,KAAK,OAAO,aAAa;AAE9C,UAAM,UAAU;AAAA,MACZ,mBAAmB;AAAA,MACnB,gBAAgB;AAAA,MAChB,IAAI,QAAQ;AAAA,MACZ,MAAM,QAAQ;AAAA,MACd,GAAI,QAAQ,SAAS,SACf,EAAE,MAAM,EAAE,MAAM,QAAQ,QAAQ,EAAE,IAClC,EAAE,UAAU,QAAQ,QAAQ;AAAA,IACtC;AAEA,WAAO,KAAK,OAAO,KAAK,UAAU,OAAO;AAAA,EAC7C;AAAA,EAEA,MAAM,cAAc,OAAiC;AACjD,WAAO,UAAU,KAAK,OAAO;AAAA,EACjC;AACJ;;;AClCO,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A,EAEA,MAAc,aAAa,QAA6C;AAGpE,YAAQ,IAAI,2BAA2B,MAAM;AAAA,EACjD;AACJ;;;AChCO,IAAM,iBAAN,MAAuC;AAAA,EAClC;AAAA,EACA;AAAA,EACA;AAAA,EAER;AAAA,EACA;AAAA,EAEA,YAAY,QAAwB;AAChC,SAAK,OAAO;AACZ,SAAK,cAAc;AACnB,SAAK,SAAS,IAAI,eAAe,MAAM;AACvC,SAAK,iBAAiB,IAAI,eAAe,KAAK,MAAM;AACpD,SAAK,iBAAiB,IAAI,eAAe,KAAK,MAAM;AAAA,EACxD;AAAA,EAEA,MAAM,YAAY,SAA4D;AAC1E,WAAO,KAAK,eAAe,KAAK,OAAO;AAAA,EAC3C;AAAA,EAEA,MAAM,cAAc,OAA4C;AAC5D,WAAO,KAAK,eAAe,OAAO,KAAK;AAAA,EAC3C;AAAA,EAEA,MAAM,cAAc,OAAiC;AACjD,WAAO,KAAK,OAAO,cAAc,KAAK;AAAA,EAC1C;AACJ;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elizaos/plugin-whatsapp",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-alpha.1",
|
|
4
4
|
"description": "WhatsApp Cloud API plugin",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -20,58 +20,57 @@
|
|
|
20
20
|
"dist"
|
|
21
21
|
],
|
|
22
22
|
"scripts": {
|
|
23
|
-
"build": "tsup",
|
|
24
|
-
"dev": "tsup --watch",
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"test:coverage": "bun test --coverage"
|
|
23
|
+
"build": "tsup --format esm --dts",
|
|
24
|
+
"dev": "tsup --format esm --dts --watch",
|
|
25
|
+
"test": "vitest run",
|
|
26
|
+
"coverage": "vitest run --coverage",
|
|
27
|
+
"lint": "biome check --apply-unsafe src/",
|
|
28
|
+
"lint:fix": "biome check --apply src/",
|
|
29
|
+
"format": "biome format src/",
|
|
30
|
+
"format:fix": "biome format --write src/"
|
|
32
31
|
},
|
|
33
32
|
"dependencies": {
|
|
34
|
-
"@elizaos/core": "latest",
|
|
35
33
|
"axios": "1.7.8"
|
|
36
34
|
},
|
|
37
35
|
"devDependencies": {
|
|
38
|
-
"
|
|
39
|
-
"prettier": "^3.0.0",
|
|
40
|
-
"bun": "^1.2.15",
|
|
41
|
-
"@types/bun": "latest",
|
|
36
|
+
"@biomejs/biome": "1.5.3",
|
|
42
37
|
"@types/node": "20.17.9",
|
|
43
|
-
"typescript": "
|
|
38
|
+
"@typescript-eslint/eslint-plugin": "8.16.0",
|
|
39
|
+
"@typescript-eslint/parser": "8.16.0",
|
|
40
|
+
"typescript": "5.6.3",
|
|
41
|
+
"vitest": "^3.0.0"
|
|
44
42
|
},
|
|
45
43
|
"publishConfig": {
|
|
46
44
|
"access": "public"
|
|
47
45
|
},
|
|
48
46
|
"agentConfig": {
|
|
49
|
-
"pluginType": "elizaos:
|
|
47
|
+
"pluginType": "elizaos:client:1.0.0",
|
|
50
48
|
"pluginParameters": {
|
|
51
49
|
"WHATSAPP_ACCESS_TOKEN": {
|
|
52
50
|
"type": "string",
|
|
51
|
+
"minLength": 1,
|
|
53
52
|
"description": "WhatsApp Cloud API access token",
|
|
54
|
-
"
|
|
55
|
-
"sensitive": true
|
|
53
|
+
"optional": false
|
|
56
54
|
},
|
|
57
55
|
"WHATSAPP_PHONE_NUMBER_ID": {
|
|
58
56
|
"type": "string",
|
|
57
|
+
"minLength": 1,
|
|
59
58
|
"description": "WhatsApp business phone number ID",
|
|
60
|
-
"
|
|
61
|
-
"sensitive": true
|
|
59
|
+
"optional": false
|
|
62
60
|
},
|
|
63
61
|
"WHATSAPP_WEBHOOK_TOKEN": {
|
|
64
62
|
"type": "string",
|
|
63
|
+
"minLength": 1,
|
|
65
64
|
"description": "Webhook verification token",
|
|
66
|
-
"
|
|
67
|
-
"sensitive": true
|
|
65
|
+
"optional": true
|
|
68
66
|
},
|
|
69
67
|
"WHATSAPP_BUSINESS_ID": {
|
|
70
68
|
"type": "string",
|
|
69
|
+
"minLength": 1,
|
|
71
70
|
"description": "Business account ID",
|
|
72
|
-
"
|
|
73
|
-
"sensitive": true
|
|
71
|
+
"optional": true
|
|
74
72
|
}
|
|
75
73
|
}
|
|
76
|
-
}
|
|
77
|
-
|
|
74
|
+
},
|
|
75
|
+
"gitHead": "05d4ca11d769db8c7f54a722ee24b2ce2b951543"
|
|
76
|
+
}
|