webhookagent 1.3.1 → 1.4.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/README.md +15 -0
- package/lib/heartbeat.js +18 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -37,6 +37,21 @@ webhookagent --auto-restart --fetch --ack
|
|
|
37
37
|
|
|
38
38
|
No open ports needed. Works behind any firewall. Events are queued so nothing is lost.
|
|
39
39
|
|
|
40
|
+
## Chat Messages
|
|
41
|
+
|
|
42
|
+
Chat endpoints let people message your agent through a shareable link (`webhookagent.com/agentchat/{name}?t={token}`). Chat messages arrive as `ACTION:` lines with `type: "chat_message"`:
|
|
43
|
+
|
|
44
|
+
```
|
|
45
|
+
ACTION:{"type":"chat_message","webhook_name":"support","sender_name":"Alex","message":"hey, is my order ready?","chat_reply_command":"curl -s -X POST ..."}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Key fields:
|
|
49
|
+
- `sender_name` — who sent the message
|
|
50
|
+
- `message` — what they said
|
|
51
|
+
- `chat_reply_command` — run this with your reply text replacing `YOUR_REPLY`
|
|
52
|
+
|
|
53
|
+
After replying, **RESTART the heartbeat immediately** (same as always). Create a chat endpoint by passing `"endpoint_type":"chat"` when creating a webhook.
|
|
54
|
+
|
|
40
55
|
## Options
|
|
41
56
|
|
|
42
57
|
| Flag | Default | Description |
|
package/lib/heartbeat.js
CHANGED
|
@@ -238,7 +238,7 @@ async function api(path, method = 'GET', body = null) {
|
|
|
238
238
|
const headers = {
|
|
239
239
|
'Authorization': `Bearer ${API_KEY}`,
|
|
240
240
|
'Content-Type': 'application/json',
|
|
241
|
-
'User-Agent': 'WebhookAgent-Heartbeat/1.
|
|
241
|
+
'User-Agent': 'WebhookAgent-Heartbeat/1.4 (Node.js)',
|
|
242
242
|
};
|
|
243
243
|
const opts = { method, headers };
|
|
244
244
|
if (body) opts.body = JSON.stringify(body);
|
|
@@ -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;
|
|
@@ -345,7 +360,7 @@ async function processActions(actions, heartbeatData) {
|
|
|
345
360
|
// ============================================================
|
|
346
361
|
|
|
347
362
|
async function main() {
|
|
348
|
-
log('WebhookAgent Heartbeat Runtime v1.
|
|
363
|
+
log('WebhookAgent Heartbeat Runtime v1.4');
|
|
349
364
|
log(`Polling ${BASE_URL} every ${INTERVAL / 1000}s${MAX_CYCLES === Infinity ? '' : `, max ${MAX_CYCLES} cycles`}${AUTO_RESTART ? ' (continuous)' : ''}${SHOW_MODE ? ' (show mode — no break)' : ''}`);
|
|
350
365
|
|
|
351
366
|
// Resolve webhook names to IDs if needed
|