@alfe.ai/openclaw-webhooks 0.0.4 → 0.0.5
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/plugin.js +41 -41
- package/package.json +1 -1
package/dist/plugin.js
CHANGED
|
@@ -51,49 +51,49 @@ const plugin = {
|
|
|
51
51
|
description: "Receive and manage HTTP webhooks from external services",
|
|
52
52
|
version: "0.1.0",
|
|
53
53
|
activate(api) {
|
|
54
|
-
if (globalThis.__alfeWebhooksPluginActivated) {
|
|
55
|
-
api.logger.debug("Alfe Webhooks plugin already activated, skipping re-init");
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
globalThis.__alfeWebhooksPluginActivated = true;
|
|
59
54
|
const log = api.logger;
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
log.info(`Connecting to webhooks service: ${webhooksWsUrl}`);
|
|
77
|
-
webhooksClient = new WebhooksServiceClient({
|
|
78
|
-
wsUrl: webhooksWsUrl,
|
|
79
|
-
apiKey,
|
|
80
|
-
onWebhook: (delivery) => {
|
|
81
|
-
log.info(`Webhook received: ${delivery.name} (${delivery.webhookId}) provider=${delivery.provider}`);
|
|
82
|
-
if (daemonIpcClient) daemonIpcClient.request("event.emit", {
|
|
83
|
-
event: "webhook.received",
|
|
84
|
-
payload: delivery
|
|
85
|
-
}).catch((err) => {
|
|
86
|
-
log.debug(`Failed to emit webhook event to daemon: ${err.message}`);
|
|
87
|
-
});
|
|
88
|
-
},
|
|
89
|
-
onConnectionChange: (connected) => {
|
|
90
|
-
log.info(`Webhooks service connection: ${connected ? "connected" : "disconnected"}`);
|
|
91
|
-
},
|
|
92
|
-
logger: log
|
|
55
|
+
const alreadyActivated = globalThis.__alfeWebhooksPluginActivated === true;
|
|
56
|
+
globalThis.__alfeWebhooksPluginActivated = true;
|
|
57
|
+
if (alreadyActivated) log.debug("Alfe Webhooks plugin re-registering gateway methods");
|
|
58
|
+
else log.info("Alfe Webhooks plugin activating...");
|
|
59
|
+
if (!alreadyActivated) {
|
|
60
|
+
const pluginConfig = (api.config ?? {}).plugins?.entries?.["@alfe.ai/openclaw-webhooks"]?.config ?? {};
|
|
61
|
+
let alfeConfig = null;
|
|
62
|
+
try {
|
|
63
|
+
alfeConfig = resolveConfig();
|
|
64
|
+
} catch {
|
|
65
|
+
log.info("Could not resolve Alfe config — daemon IPC and webhooks WS auth unavailable");
|
|
66
|
+
}
|
|
67
|
+
connectToDaemon(pluginConfig.daemonSocket ?? alfeConfig?.socketPath ?? DEFAULT_SOCKET_PATH, log).then((client) => {
|
|
68
|
+
daemonIpcClient = client;
|
|
69
|
+
}).catch((err) => {
|
|
70
|
+
log.debug(`Daemon connect failed: ${err.message}`);
|
|
93
71
|
});
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
72
|
+
const webhooksWsUrl = pluginConfig.webhooksWsUrl;
|
|
73
|
+
const apiKey = alfeConfig?.apiKey;
|
|
74
|
+
if (webhooksWsUrl && apiKey) {
|
|
75
|
+
log.info(`Connecting to webhooks service: ${webhooksWsUrl}`);
|
|
76
|
+
webhooksClient = new WebhooksServiceClient({
|
|
77
|
+
wsUrl: webhooksWsUrl,
|
|
78
|
+
apiKey,
|
|
79
|
+
onWebhook: (delivery) => {
|
|
80
|
+
log.info(`Webhook received: ${delivery.name} (${delivery.webhookId}) provider=${delivery.provider}`);
|
|
81
|
+
if (daemonIpcClient) daemonIpcClient.request("event.emit", {
|
|
82
|
+
event: "webhook.received",
|
|
83
|
+
payload: delivery
|
|
84
|
+
}).catch((err) => {
|
|
85
|
+
log.debug(`Failed to emit webhook event to daemon: ${err.message}`);
|
|
86
|
+
});
|
|
87
|
+
},
|
|
88
|
+
onConnectionChange: (connected) => {
|
|
89
|
+
log.info(`Webhooks service connection: ${connected ? "connected" : "disconnected"}`);
|
|
90
|
+
},
|
|
91
|
+
logger: log
|
|
92
|
+
});
|
|
93
|
+
webhooksClient.start();
|
|
94
|
+
log.info("Webhooks service client started");
|
|
95
|
+
} else log.info("Webhooks service URL not configured — running without webhooks relay");
|
|
96
|
+
}
|
|
97
97
|
if (typeof api.registerGatewayMethod === "function") {
|
|
98
98
|
api.registerGatewayMethod("webhooks.create", async (...args) => {
|
|
99
99
|
const params = args[0];
|