@alfe.ai/openclaw-whatsapp 0.0.6 → 0.0.7
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.cjs +2 -0
- package/dist/index.d.cts +2 -0
- package/dist/plugin.cjs +112 -0
- package/dist/plugin.d.cts +42 -0
- package/dist/plugin.d.cts.map +1 -0
- package/package.json +8 -6
package/dist/index.cjs
ADDED
package/dist/index.d.cts
ADDED
package/dist/plugin.cjs
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
let _sinclair_typebox = require("@sinclair/typebox");
|
|
2
|
+
let _alfe_ai_config = require("@alfe.ai/config");
|
|
3
|
+
//#region src/plugin.ts
|
|
4
|
+
/**
|
|
5
|
+
* @alfe/openclaw-whatsapp — OpenClaw native plugin
|
|
6
|
+
*
|
|
7
|
+
* Registers WhatsApp tools with OpenClaw. Tools call the Twilio service
|
|
8
|
+
* API using the agent's API key for authentication.
|
|
9
|
+
*
|
|
10
|
+
* This plugin provides:
|
|
11
|
+
* - whatsapp_send_message — send a WhatsApp message from the agent's phone number
|
|
12
|
+
*/
|
|
13
|
+
function ok(data) {
|
|
14
|
+
return {
|
|
15
|
+
content: [{
|
|
16
|
+
type: "text",
|
|
17
|
+
text: JSON.stringify(data)
|
|
18
|
+
}],
|
|
19
|
+
details: data
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
function errResult(message) {
|
|
23
|
+
return {
|
|
24
|
+
content: [{
|
|
25
|
+
type: "text",
|
|
26
|
+
text: JSON.stringify({ error: message })
|
|
27
|
+
}],
|
|
28
|
+
details: { error: message }
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
function defineTool(def) {
|
|
32
|
+
return {
|
|
33
|
+
name: def.name,
|
|
34
|
+
description: def.description,
|
|
35
|
+
label: def.name,
|
|
36
|
+
parameters: def.parameters,
|
|
37
|
+
execute: async (_toolCallId, params) => {
|
|
38
|
+
try {
|
|
39
|
+
return ok(await def.handler(params));
|
|
40
|
+
} catch (e) {
|
|
41
|
+
return errResult(e.message);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
let apiUrl = "";
|
|
47
|
+
let apiKey = "";
|
|
48
|
+
async function whatsappApi(method, path, body) {
|
|
49
|
+
const url = `${apiUrl}${path}`;
|
|
50
|
+
const headers = {
|
|
51
|
+
"Content-Type": "application/json",
|
|
52
|
+
Authorization: `Bearer ${apiKey}`
|
|
53
|
+
};
|
|
54
|
+
const res = await fetch(url, {
|
|
55
|
+
method,
|
|
56
|
+
headers,
|
|
57
|
+
body: body ? JSON.stringify(body) : void 0
|
|
58
|
+
});
|
|
59
|
+
const json = await res.json();
|
|
60
|
+
if (!res.ok) {
|
|
61
|
+
const errorMsg = typeof json.error === "string" ? json.error : typeof json.message === "string" ? json.message : `WhatsApp service returned ${String(res.status)}`;
|
|
62
|
+
throw new Error(errorMsg);
|
|
63
|
+
}
|
|
64
|
+
if (json.data && typeof json.data === "object") return json.data;
|
|
65
|
+
return json;
|
|
66
|
+
}
|
|
67
|
+
const whatsappTools = [defineTool({
|
|
68
|
+
name: "whatsapp_send_message",
|
|
69
|
+
description: "Send a WhatsApp message from your phone number to the specified number. The recipient number must be in E.164 format (e.g., +12025551234). Note: the recipient must have messaged you within the last 24 hours, or the message will fail (WhatsApp session window policy).",
|
|
70
|
+
parameters: _sinclair_typebox.Type.Object({
|
|
71
|
+
to: _sinclair_typebox.Type.String({ description: "Recipient phone number in E.164 format (e.g., +12025551234)" }),
|
|
72
|
+
body: _sinclair_typebox.Type.String({ description: "The message content to send" })
|
|
73
|
+
}),
|
|
74
|
+
handler: async (params) => {
|
|
75
|
+
const { to, body } = params;
|
|
76
|
+
return whatsappApi("POST", "/mobile/whatsapp/send", {
|
|
77
|
+
to,
|
|
78
|
+
body
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
})];
|
|
82
|
+
const plugin = {
|
|
83
|
+
id: "@alfe.ai/openclaw-whatsapp",
|
|
84
|
+
name: "Alfe WhatsApp Plugin",
|
|
85
|
+
description: "WhatsApp integration — outbound messaging via Twilio",
|
|
86
|
+
version: "0.0.1",
|
|
87
|
+
activate(api) {
|
|
88
|
+
const log = api.logger;
|
|
89
|
+
for (const tool of whatsappTools) api.registerTool(tool);
|
|
90
|
+
log.info(`Registered ${String(whatsappTools.length)} WhatsApp tools: ${whatsappTools.map((t) => t.name).join(", ")}`);
|
|
91
|
+
if (!globalThis.__whatsappPluginActivated) {
|
|
92
|
+
globalThis.__whatsappPluginActivated = true;
|
|
93
|
+
log.info("Alfe WhatsApp plugin activating...");
|
|
94
|
+
try {
|
|
95
|
+
const config = (0, _alfe_ai_config.resolveConfig)();
|
|
96
|
+
apiUrl = config.apiUrl;
|
|
97
|
+
apiKey = config.apiKey;
|
|
98
|
+
} catch (err) {
|
|
99
|
+
log.error(`Failed to resolve config: ${err instanceof Error ? err.message : String(err)}`);
|
|
100
|
+
log.warn("WhatsApp tools will fail — no API config available");
|
|
101
|
+
}
|
|
102
|
+
log.info(`WhatsApp API: ${apiUrl}`);
|
|
103
|
+
}
|
|
104
|
+
log.info("Alfe WhatsApp plugin activated");
|
|
105
|
+
},
|
|
106
|
+
deactivate(api) {
|
|
107
|
+
globalThis.__whatsappPluginActivated = false;
|
|
108
|
+
api.logger.info("Alfe WhatsApp plugin deactivated");
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
//#endregion
|
|
112
|
+
module.exports = plugin;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { TSchema } from "@sinclair/typebox";
|
|
2
|
+
|
|
3
|
+
//#region src/plugin.d.ts
|
|
4
|
+
|
|
5
|
+
interface Logger {
|
|
6
|
+
info(msg: string, ...args: unknown[]): void;
|
|
7
|
+
warn(msg: string, ...args: unknown[]): void;
|
|
8
|
+
error(msg: string, ...args: unknown[]): void;
|
|
9
|
+
debug(msg: string, ...args: unknown[]): void;
|
|
10
|
+
}
|
|
11
|
+
interface OpenClawPluginApi {
|
|
12
|
+
logger: Logger;
|
|
13
|
+
registerTool(tool: ToolDef): void;
|
|
14
|
+
registerGatewayMethod(name: string, handler: (...args: unknown[]) => Promise<unknown>): void;
|
|
15
|
+
on(event: string, handler: (...args: unknown[]) => void | Promise<void>, options?: {
|
|
16
|
+
priority?: number;
|
|
17
|
+
}): void;
|
|
18
|
+
}
|
|
19
|
+
interface ToolDef {
|
|
20
|
+
name: string;
|
|
21
|
+
description: string;
|
|
22
|
+
label: string;
|
|
23
|
+
parameters: TSchema;
|
|
24
|
+
execute: (toolCallId: string, params: Record<string, unknown>) => Promise<{
|
|
25
|
+
content: {
|
|
26
|
+
type: "text";
|
|
27
|
+
text: string;
|
|
28
|
+
}[];
|
|
29
|
+
details: unknown;
|
|
30
|
+
}>;
|
|
31
|
+
}
|
|
32
|
+
declare const plugin: {
|
|
33
|
+
id: string;
|
|
34
|
+
name: string;
|
|
35
|
+
description: string;
|
|
36
|
+
version: string;
|
|
37
|
+
activate(api: OpenClawPluginApi): void;
|
|
38
|
+
deactivate(api: OpenClawPluginApi): void;
|
|
39
|
+
};
|
|
40
|
+
//#endregion
|
|
41
|
+
export { plugin as default };
|
|
42
|
+
//# sourceMappingURL=plugin.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.d.cts","names":[],"sources":["../src/plugin.ts"],"mappings":";;;;UAaU,MAAA,CAWyD;EAKzD,IAAA,CAAA,GAAA,EAAO,MAAA,EAAA,GAAA,IAAA,EAAA,OAAA,EAAA,CAAA,EAAA,IAAA;EAAA,IAAA,CAAA,GAAA,EAAA,MAAA,EAAA,GAAA,IAAA,EAAA,OAAA,EAAA,CAAA,EAAA,IAAA;OAIH,CAAA,GAAA,EAAA,MAAA,EAAA,GAAA,IAAA,EAAA,OAAA,EAAA,CAAA,EAAA,IAAA;OAC0B,CAAA,GAAA,EAAA,MAAA,EAAA,GAAA,IAAA,EAAA,OAAA,EAAA,CAAA,EAAA,IAAA;;UAd9B,iBAAA,CAciE;EAkGrE,MAAA,EA/GI,MAsJT;EAAA,YAAA,CAAA,IAAA,EArJoB,OAqJpB,CAAA,EAAA,IAAA;uBAjCe,CAAA,IAAA,EAAA,MAAA,EAAA,OAAA,EAAA,CAAA,GAAA,IAAA,EAAA,OAAA,EAAA,EAAA,GAnHuD,OAmHvD,CAAA,OAAA,CAAA,CAAA,EAAA,IAAA;KA6BE,KAAA,EAAA,MAAA,EAAA,OAAA,EAAA,CAAA,GAAA,IAAA,EAAA,OAAA,EAAA,EAAA,GAAA,IAAA,GA/I0C,OA+I1C,CAAA,IAAA,CAAA,EAAA,QAAA,EAAA;IAAiB,QAAA,CAAA,EAAA,MAAA;;;UA1IzB,OAAA;;;;cAII;wCAC0B,4BAA4B;;;;;;;;cAkG9D;;;;;gBAMU;kBA6BE"}
|
package/package.json
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alfe.ai/openclaw-whatsapp",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"description": "OpenClaw WhatsApp plugin for Alfe — outbound WhatsApp messaging via Twilio",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
8
8
|
"exports": {
|
|
9
9
|
".": {
|
|
10
|
-
"
|
|
11
|
-
"
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"require": "./dist/index.cjs",
|
|
12
|
+
"import": "./dist/index.js"
|
|
12
13
|
},
|
|
13
14
|
"./plugin": {
|
|
14
|
-
"
|
|
15
|
-
"
|
|
15
|
+
"types": "./dist/plugin.d.ts",
|
|
16
|
+
"require": "./dist/plugin.cjs",
|
|
17
|
+
"import": "./dist/plugin.js"
|
|
16
18
|
}
|
|
17
19
|
},
|
|
18
20
|
"openclaw": {
|
|
@@ -26,7 +28,7 @@
|
|
|
26
28
|
],
|
|
27
29
|
"dependencies": {
|
|
28
30
|
"@sinclair/typebox": "^0.34.48",
|
|
29
|
-
"@alfe.ai/config": "0.0.
|
|
31
|
+
"@alfe.ai/config": "0.0.7"
|
|
30
32
|
},
|
|
31
33
|
"scripts": {
|
|
32
34
|
"build": "tsdown",
|