webhookagent 1.3.1 → 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/lib/heartbeat.js +16 -1
- package/package.json +1 -1
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;
|