@wahooks/channel 0.8.1 → 0.9.1
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.js +28 -32
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -315,46 +315,38 @@ mcp.setRequestHandler(CallToolRequestSchema, async (req) => {
|
|
|
315
315
|
switch (req.params.name) {
|
|
316
316
|
case "wahooks_reply":
|
|
317
317
|
case "wahooks_send": {
|
|
318
|
+
const chatId = toChatId(args.to);
|
|
319
|
+
// Human-like: typing → random delay → stop typing → send
|
|
320
|
+
await api("POST", `/connections/${connectionId}/typing`, { chatId }).catch(() => { });
|
|
321
|
+
const delay = 1000 + Math.random() * 2000 + Math.min(args.text.length * 40, 4000);
|
|
322
|
+
await new Promise((r) => setTimeout(r, delay));
|
|
323
|
+
await api("POST", `/connections/${connectionId}/typing/stop`, { chatId }).catch(() => { });
|
|
318
324
|
await api("POST", `/connections/${connectionId}/send`, {
|
|
319
|
-
chatId
|
|
325
|
+
chatId,
|
|
320
326
|
text: args.text,
|
|
327
|
+
skipPresence: true,
|
|
321
328
|
});
|
|
322
329
|
return { content: [{ type: "text", text: `Sent to ${args.to}` }] };
|
|
323
330
|
}
|
|
324
|
-
case "wahooks_send_image":
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
chatId: toChatId(args.to),
|
|
328
|
-
...media,
|
|
329
|
-
caption: args.caption,
|
|
330
|
-
});
|
|
331
|
-
return { content: [{ type: "text", text: `Image sent to ${args.to}` }] };
|
|
332
|
-
}
|
|
333
|
-
case "wahooks_send_document": {
|
|
334
|
-
const media = resolveMedia(args);
|
|
335
|
-
await api("POST", `/connections/${connectionId}/send-document`, {
|
|
336
|
-
chatId: toChatId(args.to),
|
|
337
|
-
...media,
|
|
338
|
-
caption: args.caption,
|
|
339
|
-
});
|
|
340
|
-
return { content: [{ type: "text", text: `Document sent to ${args.to}` }] };
|
|
341
|
-
}
|
|
342
|
-
case "wahooks_send_video": {
|
|
343
|
-
const media = resolveMedia(args);
|
|
344
|
-
await api("POST", `/connections/${connectionId}/send-video`, {
|
|
345
|
-
chatId: toChatId(args.to),
|
|
346
|
-
...media,
|
|
347
|
-
caption: args.caption,
|
|
348
|
-
});
|
|
349
|
-
return { content: [{ type: "text", text: `Video sent to ${args.to}` }] };
|
|
350
|
-
}
|
|
331
|
+
case "wahooks_send_image":
|
|
332
|
+
case "wahooks_send_document":
|
|
333
|
+
case "wahooks_send_video":
|
|
351
334
|
case "wahooks_send_audio": {
|
|
335
|
+
const chatId = toChatId(args.to);
|
|
352
336
|
const media = resolveMedia(args);
|
|
353
|
-
|
|
354
|
-
|
|
337
|
+
const endpoint = req.params.name.replace("wahooks_", "").replace("_", "-");
|
|
338
|
+
// Human-like: typing → delay → stop typing → send
|
|
339
|
+
await api("POST", `/connections/${connectionId}/typing`, { chatId }).catch(() => { });
|
|
340
|
+
await new Promise((r) => setTimeout(r, 1500 + Math.random() * 2000));
|
|
341
|
+
await api("POST", `/connections/${connectionId}/typing/stop`, { chatId }).catch(() => { });
|
|
342
|
+
await api("POST", `/connections/${connectionId}/${endpoint}`, {
|
|
343
|
+
chatId,
|
|
355
344
|
...media,
|
|
345
|
+
caption: args.caption,
|
|
346
|
+
filename: args.filename,
|
|
356
347
|
});
|
|
357
|
-
|
|
348
|
+
const type = endpoint.replace("send-", "");
|
|
349
|
+
return { content: [{ type: "text", text: `${type} sent to ${args.to}` }] };
|
|
358
350
|
}
|
|
359
351
|
case "wahooks_send_location": {
|
|
360
352
|
await api("POST", `/connections/${connectionId}/send-location`, {
|
|
@@ -418,7 +410,11 @@ function connectWebSocket() {
|
|
|
418
410
|
return;
|
|
419
411
|
const chatId = payload.from ?? "";
|
|
420
412
|
const isGroup = chatId.includes("@g.us");
|
|
421
|
-
const sender = payload.participant ?? chatId;
|
|
413
|
+
const sender = payload.participant ?? chatId;
|
|
414
|
+
// Send read receipt immediately
|
|
415
|
+
if (chatId && connectionId) {
|
|
416
|
+
api("POST", `/connections/${connectionId}/mark-read`, { chatId }).catch(() => { });
|
|
417
|
+
}
|
|
422
418
|
const text = payload.body ?? payload.text ?? "";
|
|
423
419
|
const hasMedia = payload.hasMedia === true;
|
|
424
420
|
const media = payload.media;
|