@elizaos/plugin-whatsapp 0.1.9 → 1.0.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.
- package/LICENSE +2 -2
- package/README.md +4 -4
- package/dist/index.d.ts +0 -1
- package/dist/index.js +7 -12
- package/dist/index.js.map +1 -1
- package/package.json +76 -39
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2025 Shaw Walters
|
|
3
|
+
Copyright (c) 2025 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
|
+
bun add @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
|
+
bun run build
|
|
178
178
|
```
|
|
179
179
|
|
|
180
180
|
### Testing
|
|
181
181
|
|
|
182
182
|
```bash
|
|
183
|
-
|
|
183
|
+
bun test
|
|
184
184
|
```
|
|
185
185
|
|
|
186
186
|
### Linting
|
|
187
187
|
|
|
188
188
|
```bash
|
|
189
|
-
|
|
189
|
+
bun run lint
|
|
190
190
|
```
|
|
191
191
|
|
|
192
192
|
## Security Best Practices
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -40,9 +40,7 @@ var MessageHandler = class {
|
|
|
40
40
|
return response.data;
|
|
41
41
|
} catch (error) {
|
|
42
42
|
if (error instanceof Error) {
|
|
43
|
-
throw new Error(
|
|
44
|
-
`Failed to send WhatsApp message: ${error.message}`
|
|
45
|
-
);
|
|
43
|
+
throw new Error(`Failed to send WhatsApp message: ${error.message}`);
|
|
46
44
|
}
|
|
47
45
|
throw new Error("Failed to send WhatsApp message");
|
|
48
46
|
}
|
|
@@ -70,9 +68,7 @@ var WebhookHandler = class {
|
|
|
70
68
|
}
|
|
71
69
|
} catch (error) {
|
|
72
70
|
if (error instanceof Error) {
|
|
73
|
-
throw new Error(
|
|
74
|
-
`Failed to send WhatsApp message: ${error.message}`
|
|
75
|
-
);
|
|
71
|
+
throw new Error(`Failed to send WhatsApp message: ${error.message}`);
|
|
76
72
|
}
|
|
77
73
|
throw new Error("Failed to send WhatsApp message");
|
|
78
74
|
}
|
|
@@ -87,19 +83,18 @@ var WebhookHandler = class {
|
|
|
87
83
|
|
|
88
84
|
// src/index.ts
|
|
89
85
|
var WhatsAppPlugin = class {
|
|
86
|
+
client;
|
|
87
|
+
messageHandler;
|
|
88
|
+
webhookHandler;
|
|
89
|
+
name;
|
|
90
|
+
description;
|
|
90
91
|
constructor(config) {
|
|
91
|
-
this.config = config;
|
|
92
92
|
this.name = "WhatsApp Cloud API Plugin";
|
|
93
93
|
this.description = "A plugin for integrating WhatsApp Cloud API with your application.";
|
|
94
94
|
this.client = new WhatsAppClient(config);
|
|
95
95
|
this.messageHandler = new MessageHandler(this.client);
|
|
96
96
|
this.webhookHandler = new WebhookHandler(this.client);
|
|
97
97
|
}
|
|
98
|
-
client;
|
|
99
|
-
messageHandler;
|
|
100
|
-
webhookHandler;
|
|
101
|
-
name;
|
|
102
|
-
description;
|
|
103
98
|
async sendMessage(message) {
|
|
104
99
|
return this.messageHandler.send(message);
|
|
105
100
|
}
|
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 \"axios\";\nimport type { WhatsAppConfig, WhatsAppMessage } from \"./types\";\n\nexport class WhatsAppClient {\n
|
|
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 \"axios\";\nimport type { WhatsAppConfig, WhatsAppMessage } 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<any> {\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 } from \"../types\";\n\nexport class MessageHandler {\n constructor(private client: WhatsAppClient) {}\n\n async send(message: WhatsAppMessage): Promise<any> {\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 { 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: any): 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: any): 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 type {\n WhatsAppConfig,\n WhatsAppMessage,\n WhatsAppWebhookEvent,\n} from \"./types\";\nimport { MessageHandler, WebhookHandler } from \"./handlers\";\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 =\n \"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<any> {\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,WAAmC;AAGnC,IAAM,iBAAN,MAAqB;AAAA,EAClB;AAAA,EACA;AAAA,EAER,YAAY,QAAwB;AAClC,SAAK,SAAS;AACd,SAAK,SAAS,MAAM,OAAO;AAAA,MACzB,SAAS;AAAA,MACT,SAAS;AAAA,QACP,eAAe,UAAU,OAAO,WAAW;AAAA,QAC3C,gBAAgB;AAAA,MAClB;AAAA,IACF,CAAC;AAAA,EACH;AAAA,EAEA,MAAM,YAAY,SAAwC;AACxD,UAAM,WAAW,IAAI,KAAK,OAAO,aAAa;AAE9C,UAAM,UAAU;AAAA,MACd,mBAAmB;AAAA,MACnB,gBAAgB;AAAA,MAChB,IAAI,QAAQ;AAAA,MACZ,MAAM,QAAQ;AAAA,MACd,GAAI,QAAQ,SAAS,SACjB,EAAE,MAAM,EAAE,MAAM,QAAQ,QAAQ,EAAE,IAClC,EAAE,UAAU,QAAQ,QAAQ;AAAA,IAClC;AAEA,WAAO,KAAK,OAAO,KAAK,UAAU,OAAO;AAAA,EAC3C;AAAA,EAEA,MAAM,cAAc,OAAiC;AACnD,WAAO,UAAU,KAAK,OAAO;AAAA,EAC/B;AACF;;;AClCO,IAAM,iBAAN,MAAqB;AAAA,EAC1B,YAAoB,QAAwB;AAAxB;AAAA,EAAyB;AAAA,EAE7C,MAAM,KAAK,SAAwC;AACjD,QAAI;AACF,YAAM,WAAW,MAAM,KAAK,OAAO,YAAY,OAAO;AACtD,aAAO,SAAS;AAAA,IAClB,SAAS,OAAgB;AACvB,UAAI,iBAAiB,OAAO;AAC1B,cAAM,IAAI,MAAM,oCAAoC,MAAM,OAAO,EAAE;AAAA,MACrE;AACA,YAAM,IAAI,MAAM,iCAAiC;AAAA,IACnD;AAAA,EACF;AACF;;;ACdO,IAA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;AAAA,EAEA,MAAM,cAAc,OAA4C;AAC9D,WAAO,KAAK,eAAe,OAAO,KAAK;AAAA,EACzC;AAAA,EAEA,MAAM,cAAc,OAAiC;AACnD,WAAO,KAAK,OAAO,cAAc,KAAK;AAAA,EACxC;AACF;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,40 +1,77 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
2
|
+
"name": "@elizaos/plugin-whatsapp",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "WhatsApp Cloud API plugin",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"module": "dist/index.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
"./package.json": "./package.json",
|
|
11
|
+
".": {
|
|
12
|
+
"import": {
|
|
13
|
+
"@elizaos/source": "./src/index.ts",
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"default": "./dist/index.js"
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist"
|
|
21
|
+
],
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build": "tsup",
|
|
24
|
+
"dev": "tsup --watch",
|
|
25
|
+
"lint": "prettier --write ./src",
|
|
26
|
+
"clean": "rm -rf dist .turbo node_modules .turbo-tsconfig.json tsconfig.tsbuildinfo",
|
|
27
|
+
"format": "prettier --write ./src",
|
|
28
|
+
"format:check": "prettier --check ./src",
|
|
29
|
+
"test": "bun test",
|
|
30
|
+
"test:watch": "bun test --watch",
|
|
31
|
+
"test:coverage": "bun test --coverage"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"@elizaos/core": "latest",
|
|
35
|
+
"axios": "1.7.8"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"tsup": "8.3.5",
|
|
39
|
+
"prettier": "^3.0.0",
|
|
40
|
+
"bun": "^1.2.15",
|
|
41
|
+
"@types/bun": "latest",
|
|
42
|
+
"@types/node": "20.17.9",
|
|
43
|
+
"typescript": "5.6.3"
|
|
44
|
+
},
|
|
45
|
+
"publishConfig": {
|
|
46
|
+
"access": "public"
|
|
47
|
+
},
|
|
48
|
+
"agentConfig": {
|
|
49
|
+
"pluginType": "elizaos:plugin:1.0.0",
|
|
50
|
+
"pluginParameters": {
|
|
51
|
+
"WHATSAPP_ACCESS_TOKEN": {
|
|
52
|
+
"type": "string",
|
|
53
|
+
"description": "WhatsApp Cloud API access token",
|
|
54
|
+
"required": true,
|
|
55
|
+
"sensitive": true
|
|
56
|
+
},
|
|
57
|
+
"WHATSAPP_PHONE_NUMBER_ID": {
|
|
58
|
+
"type": "string",
|
|
59
|
+
"description": "WhatsApp business phone number ID",
|
|
60
|
+
"required": true,
|
|
61
|
+
"sensitive": true
|
|
62
|
+
},
|
|
63
|
+
"WHATSAPP_WEBHOOK_TOKEN": {
|
|
64
|
+
"type": "string",
|
|
65
|
+
"description": "Webhook verification token",
|
|
66
|
+
"required": false,
|
|
67
|
+
"sensitive": true
|
|
68
|
+
},
|
|
69
|
+
"WHATSAPP_BUSINESS_ID": {
|
|
70
|
+
"type": "string",
|
|
71
|
+
"description": "Business account ID",
|
|
72
|
+
"required": false,
|
|
73
|
+
"sensitive": true
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|