webhookagent 1.3.0 → 1.3.2
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/README.md +3 -1
- package/lib/heartbeat.js +18 -3
- package/package.json +5 -2
package/README.md
CHANGED
|
@@ -16,8 +16,10 @@ npm install -g @avniyayin/webhookagent
|
|
|
16
16
|
# Save your key (one-time — loads automatically after this)
|
|
17
17
|
webhookagent config --key=wha_your_key
|
|
18
18
|
|
|
19
|
-
# Start heartbeat
|
|
19
|
+
# Start the heartbeat loop
|
|
20
20
|
webhookagent --fetch --ack
|
|
21
|
+
# Polls → events arrive → fetches from queue → acks → outputs → exits
|
|
22
|
+
# Agent processes → runs RESTART command → back to polling
|
|
21
23
|
|
|
22
24
|
# Single check (one poll, then exit)
|
|
23
25
|
webhookagent --once
|
package/lib/heartbeat.js
CHANGED
|
@@ -290,8 +290,14 @@ async function processActions(actions, heartbeatData) {
|
|
|
290
290
|
const ids = [];
|
|
291
291
|
for (const item of queue.items) {
|
|
292
292
|
ids.push(item.id);
|
|
293
|
+
|
|
294
|
+
// Detect chat messages
|
|
295
|
+
let bodyData = item.body_json || item.body;
|
|
296
|
+
if (typeof bodyData === 'string') { try { bodyData = JSON.parse(bodyData); } catch(e) {} }
|
|
297
|
+
const isChat = bodyData && bodyData.type === 'chat_message';
|
|
298
|
+
|
|
293
299
|
const output = {
|
|
294
|
-
type: 'webhook_event',
|
|
300
|
+
type: isChat ? 'chat_message' : 'webhook_event',
|
|
295
301
|
webhook_id: whId,
|
|
296
302
|
webhook_name: whName,
|
|
297
303
|
item_id: item.id,
|
|
@@ -303,6 +309,15 @@ async function processActions(actions, heartbeatData) {
|
|
|
303
309
|
source_ip: item.source_ip,
|
|
304
310
|
received_at: item.received_at,
|
|
305
311
|
};
|
|
312
|
+
|
|
313
|
+
// Chat messages: include reply command so agents know how to respond
|
|
314
|
+
if (isChat) {
|
|
315
|
+
output.sender_name = bodyData.sender_name || 'Visitor';
|
|
316
|
+
output.message = bodyData.message || '';
|
|
317
|
+
output.chat_reply_hint = `This is a chat message from "${output.sender_name}". You MUST respond by running the reply command below. Replace YOUR_REPLY with your response text.`;
|
|
318
|
+
output.chat_reply_command = `curl -s -X POST "${BASE_URL}/webhooks/${whId}/chat/reply" -H "Authorization: Bearer ${API_KEY}" -H "Content-Type: application/json" -d '{"message":"YOUR_REPLY"}'`;
|
|
319
|
+
}
|
|
320
|
+
|
|
306
321
|
// When --ack is not used, include acknowledge instructions with each item
|
|
307
322
|
if (!AUTO_ACK) {
|
|
308
323
|
output.needs_ack = true;
|
|
@@ -362,8 +377,8 @@ async function main() {
|
|
|
362
377
|
// Otherwise match by name (case-insensitive)
|
|
363
378
|
const match = webhooks.webhooks.find(w => w.name.toLowerCase() === f.toLowerCase());
|
|
364
379
|
if (match) {
|
|
365
|
-
log(`Resolved "${f}" → ${match.
|
|
366
|
-
return match.
|
|
380
|
+
log(`Resolved "${f}" → ${match.id}`);
|
|
381
|
+
return match.id;
|
|
367
382
|
}
|
|
368
383
|
log(`WARN: webhook name "${f}" not found, skipping`);
|
|
369
384
|
return null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "webhookagent",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.2",
|
|
4
4
|
"description": "WebhookAgent heartbeat runtime — poll, break, process webhook events at your agent's pace",
|
|
5
5
|
"main": "lib/heartbeat.js",
|
|
6
6
|
"bin": {
|
|
@@ -34,5 +34,8 @@
|
|
|
34
34
|
"lib/",
|
|
35
35
|
"README.md",
|
|
36
36
|
"LICENSE"
|
|
37
|
-
]
|
|
37
|
+
],
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"sharp": "^0.34.5"
|
|
40
|
+
}
|
|
38
41
|
}
|