@0xmaxma/claude-gateway 1.8.9 → 1.8.11

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.
Files changed (121) hide show
  1. package/README.md +46 -6
  2. package/config.template.json +2 -1
  3. package/dist/agent/runner.d.ts +86 -1
  4. package/dist/agent/runner.d.ts.map +1 -1
  5. package/dist/agent/runner.js +396 -9
  6. package/dist/agent/runner.js.map +1 -1
  7. package/dist/api/router.d.ts.map +1 -1
  8. package/dist/api/router.js +1028 -6
  9. package/dist/api/router.js.map +1 -1
  10. package/dist/api/share-router.d.ts.map +1 -1
  11. package/dist/api/share-router.js +24 -0
  12. package/dist/api/share-router.js.map +1 -1
  13. package/dist/api/webhooks-router.d.ts +2 -0
  14. package/dist/api/webhooks-router.d.ts.map +1 -1
  15. package/dist/api/webhooks-router.js +2 -0
  16. package/dist/api/webhooks-router.js.map +1 -1
  17. package/dist/api/whatsapp-access.d.ts +123 -0
  18. package/dist/api/whatsapp-access.d.ts.map +1 -0
  19. package/dist/api/whatsapp-access.js +135 -0
  20. package/dist/api/whatsapp-access.js.map +1 -0
  21. package/dist/api/whatsapp-cloud-access.d.ts +48 -0
  22. package/dist/api/whatsapp-cloud-access.d.ts.map +1 -0
  23. package/dist/api/whatsapp-cloud-access.js +58 -0
  24. package/dist/api/whatsapp-cloud-access.js.map +1 -0
  25. package/dist/api/whatsapp-cloud-client.d.ts +143 -0
  26. package/dist/api/whatsapp-cloud-client.d.ts.map +1 -0
  27. package/dist/api/whatsapp-cloud-client.js +298 -0
  28. package/dist/api/whatsapp-cloud-client.js.map +1 -0
  29. package/dist/api/whatsapp-cloud-webhook-router.d.ts +132 -0
  30. package/dist/api/whatsapp-cloud-webhook-router.d.ts.map +1 -0
  31. package/dist/api/whatsapp-cloud-webhook-router.js +494 -0
  32. package/dist/api/whatsapp-cloud-webhook-router.js.map +1 -0
  33. package/dist/cli/args.d.ts +34 -0
  34. package/dist/cli/args.d.ts.map +1 -1
  35. package/dist/cli/args.js +55 -0
  36. package/dist/cli/args.js.map +1 -1
  37. package/dist/cli/commands/app.d.ts +28 -0
  38. package/dist/cli/commands/app.d.ts.map +1 -0
  39. package/dist/cli/commands/app.js +411 -0
  40. package/dist/cli/commands/app.js.map +1 -0
  41. package/dist/cli/commands/doctor.d.ts.map +1 -1
  42. package/dist/cli/commands/doctor.js +77 -16
  43. package/dist/cli/commands/doctor.js.map +1 -1
  44. package/dist/cli/commands/service.d.ts.map +1 -1
  45. package/dist/cli/commands/service.js +373 -56
  46. package/dist/cli/commands/service.js.map +1 -1
  47. package/dist/cli/commands/update.d.ts.map +1 -1
  48. package/dist/cli/commands/update.js +1 -17
  49. package/dist/cli/commands/update.js.map +1 -1
  50. package/dist/cli/http-client.d.ts +8 -0
  51. package/dist/cli/http-client.d.ts.map +1 -1
  52. package/dist/cli/http-client.js +5 -2
  53. package/dist/cli/http-client.js.map +1 -1
  54. package/dist/cli/index.d.ts.map +1 -1
  55. package/dist/cli/index.js +16 -4
  56. package/dist/cli/index.js.map +1 -1
  57. package/dist/cli/prompt.d.ts +17 -2
  58. package/dist/cli/prompt.d.ts.map +1 -1
  59. package/dist/cli/prompt.js +33 -2
  60. package/dist/cli/prompt.js.map +1 -1
  61. package/dist/config/loader.d.ts +8 -0
  62. package/dist/config/loader.d.ts.map +1 -1
  63. package/dist/config/loader.js +22 -4
  64. package/dist/config/loader.js.map +1 -1
  65. package/dist/config/watcher.d.ts.map +1 -1
  66. package/dist/config/watcher.js +12 -0
  67. package/dist/config/watcher.js.map +1 -1
  68. package/dist/config/whatsapp-accounts.d.ts +77 -0
  69. package/dist/config/whatsapp-accounts.d.ts.map +1 -0
  70. package/dist/config/whatsapp-accounts.js +218 -0
  71. package/dist/config/whatsapp-accounts.js.map +1 -0
  72. package/dist/history/db.d.ts.map +1 -1
  73. package/dist/history/db.js +43 -11
  74. package/dist/history/db.js.map +1 -1
  75. package/dist/history/types.d.ts +18 -1
  76. package/dist/history/types.d.ts.map +1 -1
  77. package/dist/history/types.js +1 -1
  78. package/dist/history/types.js.map +1 -1
  79. package/dist/index.js +26 -0
  80. package/dist/index.js.map +1 -1
  81. package/dist/session/process.d.ts.map +1 -1
  82. package/dist/session/process.js +37 -0
  83. package/dist/session/process.js.map +1 -1
  84. package/dist/session/store.d.ts +3 -2
  85. package/dist/session/store.d.ts.map +1 -1
  86. package/dist/session/store.js +1 -1
  87. package/dist/session/store.js.map +1 -1
  88. package/dist/share/session-video-catalog.d.ts +19 -0
  89. package/dist/share/session-video-catalog.d.ts.map +1 -0
  90. package/dist/share/session-video-catalog.js +119 -0
  91. package/dist/share/session-video-catalog.js.map +1 -0
  92. package/dist/shared/image-optimize.d.ts +32 -0
  93. package/dist/shared/image-optimize.d.ts.map +1 -0
  94. package/dist/shared/image-optimize.js +197 -0
  95. package/dist/shared/image-optimize.js.map +1 -0
  96. package/dist/shared/image-sniff.d.ts +9 -0
  97. package/dist/shared/image-sniff.d.ts.map +1 -1
  98. package/dist/shared/image-sniff.js +13 -0
  99. package/dist/shared/image-sniff.js.map +1 -1
  100. package/dist/shared/text-chunk.d.ts +37 -0
  101. package/dist/shared/text-chunk.d.ts.map +1 -0
  102. package/dist/shared/text-chunk.js +105 -0
  103. package/dist/shared/text-chunk.js.map +1 -0
  104. package/dist/shared/whatsapp-ack.d.ts +13 -0
  105. package/dist/shared/whatsapp-ack.d.ts.map +1 -0
  106. package/dist/shared/whatsapp-ack.js +16 -0
  107. package/dist/shared/whatsapp-ack.js.map +1 -0
  108. package/dist/types.d.ts +183 -0
  109. package/dist/types.d.ts.map +1 -1
  110. package/dist/whatsapp/manager.d.ts +173 -0
  111. package/dist/whatsapp/manager.d.ts.map +1 -0
  112. package/dist/whatsapp/manager.js +838 -0
  113. package/dist/whatsapp/manager.js.map +1 -0
  114. package/mcp/server.ts +4 -0
  115. package/mcp/tools/image/module.ts +6 -1
  116. package/mcp/tools/telegram/receiver-server.ts +15 -8
  117. package/mcp/tools/telegram/reply-attachment.ts +81 -0
  118. package/mcp/tools/video/module.ts +6 -1
  119. package/mcp/tools/whatsapp/module.ts +162 -0
  120. package/mcp/tools/whatsapp-cloud/module.ts +536 -0
  121. package/package.json +7 -2
@@ -0,0 +1 @@
1
+ {"version":3,"file":"manager.js","sourceRoot":"","sources":["../../src/whatsapp/manager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,uCAAyB;AACzB,iDAAmC;AACnC,2CAA6B;AAC7B,uCAAyB;AA0BzB,KAAK,UAAU,WAAW;IACxB,sEAAsE;IACtE,OAAO,CAAC,wDAAa,yBAAyB,GAAC,CAA6B,CAAC;AAC/E,CAAC;AAED,+CAAiC;AACjC,gDAAwB;AAExB,mEAIqC;AACrC,sCAAyC;AACzC,wDAAoD;AACpD,uDAA0E;AAC1E,4DAMgC;AAChC,qDAAiD;AACjD,6DAA6D;AAC7D,yDAA4D;AAC5D,4DAKgC;AAEhC,MAAM,qBAAqB,GAAG,IAAK,CAAC;AACpC,MAAM,YAAY,GAAG,CAAC,CAAC;AACvB,MAAM,qBAAqB,GAAG,CAAC,GAAG,KAAM,CAAC;AACzC,MAAM,eAAe,GAAG,wBAAU,CAAC,cAAc,CAAC;AAElD;;;;;;GAMG;AACH,MAAM,cAAc,GAAG,IAAI,CAAC;AAE5B;;;;;;;GAOG;AACH,MAAM,yBAAyB,GAAG,GAAG,CAAC;AAEtC;;;;;GAKG;AACH,SAAS,qBAAqB,CAAC,QAAgB;IAC7C,QAAQ,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC;QAC7C,KAAK,MAAM,CAAC,CAAC,OAAO,WAAW,CAAC;QAChC,KAAK,MAAM,CAAC;QACZ,KAAK,OAAO,CAAC,CAAC,OAAO,YAAY,CAAC;QAClC,KAAK,MAAM,CAAC,CAAC,OAAO,WAAW,CAAC;QAChC,KAAK,OAAO,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AAC,WAAW,GAAG,SAAS,CAAC;QAC7B,IAAI,CAAC,WAAW,GAAG,SAAS,CAAC;QAC7B,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC;QACvB,MAAM,IAAI,CAAC,YAAY,EAAE,CAAC;IAC5B,CAAC;IAED,kGAAkG;IAClG,IAAI;QACF,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QACrB,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;YACtB,YAAY,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;YAChC,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC;QAC3B,CAAC;QACD,IAAI,CAAC,IAAI,EAAE,GAAG,CAAC,SAAS,CAAC,CAAC;QAC1B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF;AA1rBD,0CA0rBC"}
package/mcp/server.ts CHANGED
@@ -16,6 +16,8 @@ import { TelegramModule } from './tools/telegram/module';
16
16
  import { DiscordModule } from './tools/discord/module';
17
17
  import { LineModule } from './tools/line/module';
18
18
  import { SlackModule } from './tools/slack/module';
19
+ import { WhatsAppModule } from './tools/whatsapp/module';
20
+ import { WhatsAppCloudModule } from './tools/whatsapp-cloud/module';
19
21
  import { CronModule } from './tools/cron/module';
20
22
  import { SkillsModule } from './tools/skills/module';
21
23
  import { AgentModule } from './tools/agent/module';
@@ -42,6 +44,8 @@ const modules: AnyModule[] = [
42
44
  new DiscordModule(),
43
45
  new LineModule(),
44
46
  new SlackModule(),
47
+ new WhatsAppModule(),
48
+ new WhatsAppCloudModule(),
45
49
  new CronModule(),
46
50
  new SkillsModule(),
47
51
  new AgentModule(),
@@ -516,7 +516,12 @@ export class ImageModule implements ToolModule {
516
516
  // which the share API only fills when gateway.publicUrl is configured.
517
517
  if (minted.some((m) => !m.url)) {
518
518
  await revokeSharesBestEffort(minted.map((m) => m.share_id));
519
- return fail('generate_image: image reference sharing requires gateway.publicUrl to be configured.');
519
+ return fail(
520
+ 'generate_image: image reference sharing requires gateway.publicUrl to be configured ' +
521
+ '(set it in ~/.claude-gateway/config.json to your externally reachable base URL ending ' +
522
+ 'in /gateway, then restart the gateway). As a workaround, pass a publicly reachable ' +
523
+ 'https:// image URL instead of a local path or artifact ref.',
524
+ );
520
525
  }
521
526
  }
522
527
  // Merge back preserving the caller's order. taskIds/priorPrompts are
@@ -30,6 +30,7 @@ import { homedir } from 'os'
30
30
  import { join, extname, sep } from 'path'
31
31
  import { execFileSync } from 'child_process'
32
32
  import { createWorkingStateManager, drainOrphanForwards, chunkText, htmlToPlain } from './typing'
33
+ import { extractRepliedAttachment, safeName } from './reply-attachment'
33
34
  // Import compiled dist/, not raw src/ — src/ is not published (files: ["mcp/"]),
34
35
  // so a src/ import crashes this bun-run receiver on installed packages (the bug
35
36
  // that silenced every bot on systemd installs). Enforced by
@@ -587,7 +588,7 @@ const mcp = new Server(
587
588
  instructions: [
588
589
  'The sender reads Telegram, not this session. Anything you want them to see must go through the reply tool — your transcript output never reaches their chat.',
589
590
  '',
590
- 'Messages from Telegram arrive as <channel source="telegram" chat_id="..." message_id="..." user="..." ts="...">. If the tag has an image_path attribute, Read that file — it is a photo the sender attached. If the tag has attachment_file_id, call download_attachment with that file_id to fetch the file, then Read the returned path. Reply with the reply tool — pass chat_id back. Use reply_to (set to a message_id) only when replying to an earlier message; the latest message doesn\'t need a quote-reply, omit reply_to for normal responses.',
591
+ 'Messages from Telegram arrive as <channel source="telegram" chat_id="..." message_id="..." user="..." ts="...">. If the tag has an image_path attribute, Read that file — it is a photo the sender attached. If the tag has attachment_file_id, call download_attachment with that file_id to fetch the file, then Read the returned path. A nested <replied> block quotes an earlier message; it may carry replied_image_path (Read it) or replied_attachment_file_id (pass to download_attachment) when the quoted message held a photo or file. Reply with the reply tool — pass chat_id back. Use reply_to (set to a message_id) only when replying to an earlier message; the latest message doesn\'t need a quote-reply, omit reply_to for normal responses.',
591
592
  '',
592
593
  'reply accepts file paths (files: ["/abs/path.png"]) for attachments. Use react to add emoji reactions, and edit_message for interim progress updates. Edits don\'t trigger push notifications — when a long task completes, send a new reply so the user\'s device pings.',
593
594
  '',
@@ -926,13 +927,6 @@ const CALLBACK_URL_BASE = (() => {
926
927
 
927
928
  // ─── Message helpers (shared across all polling modes) ───────────────────────
928
929
 
929
- // Filenames and titles are uploader-controlled. They land inside the <channel>
930
- // notification — delimiter chars would let the uploader break out of the tag
931
- // or forge a second meta entry.
932
- function safeName(s: string | undefined): string | undefined {
933
- return s?.replace(/[<>\[\]\r\n;]/g, '_')
934
- }
935
-
936
930
  type AttachmentMeta = {
937
931
  kind: string
938
932
  file_id: string
@@ -1048,6 +1042,12 @@ async function handleInbound(
1048
1042
  } catch {}
1049
1043
  }
1050
1044
 
1045
+ // A replied-to message may also carry a non-photo attachment (document, video,
1046
+ // audio, …). Photos become an image_path above; everything else is surfaced by
1047
+ // file_id so the agent can fetch it with download_attachment — without this a
1048
+ // quote-reply of e.g. a CSV dropped the file entirely.
1049
+ const repliedAttachment = extractRepliedAttachment(replyMsg)
1050
+
1051
1051
  // image_path goes in meta only — an in-content "[image attached — read: PATH]"
1052
1052
  // annotation is forgeable by any allowlisted sender typing that string.
1053
1053
  const channelParams = {
@@ -1074,6 +1074,13 @@ async function handleInbound(
1074
1074
  replied_user: replyMsg.from?.username ?? String(replyMsg.from?.id ?? ''),
1075
1075
  ...(replyMsg.text ? { replied_text: replyMsg.text } : {}),
1076
1076
  ...(repliedImagePath ? { replied_image_path: repliedImagePath } : {}),
1077
+ ...(repliedAttachment ? {
1078
+ replied_attachment_kind: repliedAttachment.kind,
1079
+ replied_attachment_file_id: repliedAttachment.file_id,
1080
+ ...(repliedAttachment.size != null ? { replied_attachment_size: String(repliedAttachment.size) } : {}),
1081
+ ...(repliedAttachment.mime ? { replied_attachment_mime: repliedAttachment.mime } : {}),
1082
+ ...(repliedAttachment.name ? { replied_attachment_name: repliedAttachment.name } : {}),
1083
+ } : {}),
1077
1084
  } : {}),
1078
1085
  },
1079
1086
  }
@@ -0,0 +1,81 @@
1
+ import type { Message } from 'grammy/types'
2
+
3
+ /** Non-photo attachment metadata lifted off a message, mirroring the shape the
4
+ * live-message handlers build for `attachment_*`. Photos are handled separately
5
+ * (downloaded to an image_path); everything else is surfaced by file_id so the
6
+ * agent can fetch it on demand via download_attachment. */
7
+ export type RepliedAttachment = {
8
+ kind: string
9
+ file_id: string
10
+ size?: number
11
+ mime?: string
12
+ name?: string
13
+ }
14
+
15
+ // Filenames and titles are uploader-controlled. They land inside the <channel>
16
+ // notification — delimiter chars would let the uploader break out of the tag
17
+ // or forge a second meta entry.
18
+ export function safeName(s: string | undefined): string | undefined {
19
+ return s?.replace(/[<>\[\]\r\n;]/g, '_')
20
+ }
21
+
22
+ /**
23
+ * Extract a non-photo attachment from the message being replied to.
24
+ *
25
+ * A quote-reply carries the full replied-to message, including any document /
26
+ * video / audio / voice / video_note / sticker it held — but the receiver only
27
+ * ever downloaded a replied *photo*. So replying to (say) a CSV dropped the file
28
+ * entirely: the agent saw `<replied>` with no way to reach the attachment. This
29
+ * returns that attachment's metadata so the reply path can surface a
30
+ * `replied_attachment_file_id` the agent can pass to download_attachment.
31
+ *
32
+ * Returns undefined when the replied message has no such attachment (plain text,
33
+ * or a photo — which the caller handles as an image_path).
34
+ */
35
+ export function extractRepliedAttachment(msg: Message | undefined): RepliedAttachment | undefined {
36
+ if (!msg) return undefined
37
+ if (msg.document)
38
+ return {
39
+ kind: 'document',
40
+ file_id: msg.document.file_id,
41
+ size: msg.document.file_size,
42
+ mime: msg.document.mime_type,
43
+ name: safeName(msg.document.file_name),
44
+ }
45
+ if (msg.video)
46
+ return {
47
+ kind: 'video',
48
+ file_id: msg.video.file_id,
49
+ size: msg.video.file_size,
50
+ mime: msg.video.mime_type,
51
+ name: safeName(msg.video.file_name),
52
+ }
53
+ if (msg.audio)
54
+ return {
55
+ kind: 'audio',
56
+ file_id: msg.audio.file_id,
57
+ size: msg.audio.file_size,
58
+ mime: msg.audio.mime_type,
59
+ name: safeName(msg.audio.file_name),
60
+ }
61
+ if (msg.voice)
62
+ return {
63
+ kind: 'voice',
64
+ file_id: msg.voice.file_id,
65
+ size: msg.voice.file_size,
66
+ mime: msg.voice.mime_type,
67
+ }
68
+ if (msg.video_note)
69
+ return {
70
+ kind: 'video_note',
71
+ file_id: msg.video_note.file_id,
72
+ size: msg.video_note.file_size,
73
+ }
74
+ if (msg.sticker)
75
+ return {
76
+ kind: 'sticker',
77
+ file_id: msg.sticker.file_id,
78
+ size: msg.sticker.file_size,
79
+ }
80
+ return undefined
81
+ }
@@ -418,7 +418,12 @@ export class VideoModule implements ToolModule {
418
418
  // share API only fills when gateway.publicUrl is configured.
419
419
  if (!item.url) {
420
420
  await revokeSharesBestEffort([item.share_id]);
421
- return fail('generate_video: source-frame sharing requires gateway.publicUrl to be configured.');
421
+ return fail(
422
+ 'generate_video: source-frame sharing requires gateway.publicUrl to be configured ' +
423
+ '(set it in ~/.claude-gateway/config.json to your externally reachable base URL ending ' +
424
+ 'in /gateway, then restart the gateway). As a workaround, pass a publicly reachable ' +
425
+ 'https:// image URL instead of a local path or artifact ref.',
426
+ );
422
427
  }
423
428
  return { url: item.url, mintedShareIds: [item.share_id] };
424
429
  }
@@ -0,0 +1,162 @@
1
+ /**
2
+ * WhatsApp outbound tool module — exposes `whatsapp_reply` to the Claude
3
+ * session. Unlike Slack/SMS/LINE, this does NOT open its own connection to
4
+ * the platform: Baileys multiplexes all send/receive through the ONE live
5
+ * socket the gateway's in-process WhatsAppManager already holds (see
6
+ * src/whatsapp/manager.ts's doc comment for why a fresh per-call connection
7
+ * isn't viable here the way it is for a stateless REST client). Instead this
8
+ * tool POSTs to the gateway's own internal `/v1/agents/:id/whatsapp/send`
9
+ * route, using the same `GATEWAY_API_URL`/`GATEWAY_API_KEY` bridge every MCP
10
+ * subprocess already receives (the same bridge Discord's module uses to
11
+ * reach `/cli` pairing approval — a proven pattern, just not yet used to
12
+ * reach a receiver's live resource specifically).
13
+ *
14
+ * WhatsApp is a ToolModule (reply-only, like LINE/Slack/SMS): inbound
15
+ * arrives via WhatsAppManager directly forwarding to the agent's callback
16
+ * port, not through this MCP subprocess at all.
17
+ */
18
+ import type { ToolModule, McpToolDefinition, McpToolResult, ToolVisibility } from '../../types';
19
+
20
+ export class WhatsAppModule implements ToolModule {
21
+ id = 'whatsapp';
22
+ toolVisibility: ToolVisibility = 'current-channel';
23
+
24
+ isEnabled(): boolean {
25
+ return process.env.GATEWAY_ORIGIN_CHANNEL === 'whatsapp';
26
+ }
27
+
28
+ getTools(): McpToolDefinition[] {
29
+ return [
30
+ {
31
+ name: 'whatsapp_reply',
32
+ description:
33
+ 'Send a reply to the current WhatsApp conversation. ' +
34
+ 'Pass chat_id (the JID shown in the <channel> tag) and text. ' +
35
+ 'If the <channel> tag carries an account_id, pass it too — the agent ' +
36
+ 'may have several linked WhatsApp numbers, and account_id is the one ' +
37
+ 'the incoming message arrived on. ' +
38
+ 'Optionally pass image_path (an absolute path) to attach an image — ' +
39
+ 'text then becomes the caption. WhatsApp has its own lightweight ' +
40
+ 'formatting (*bold*, _italic_, ~strikethrough~), not HTML or standard markdown. ' +
41
+ 'Also pass message_id from the <channel> tag when present — it clears the ' +
42
+ '⏳ "seen" reaction the gateway left on the inbound message.',
43
+ inputSchema: {
44
+ type: 'object',
45
+ properties: {
46
+ chat_id: {
47
+ type: 'string',
48
+ description: 'WhatsApp JID to send to (the chat_id from the channel turn).',
49
+ },
50
+ text: {
51
+ type: 'string',
52
+ description: 'Message text (or caption, if image_path is also passed).',
53
+ },
54
+ image_path: {
55
+ type: 'string',
56
+ description: 'Optional absolute path to an image file to attach.',
57
+ },
58
+ as_document: {
59
+ type: 'boolean',
60
+ description:
61
+ 'Send image_path as a file/document instead of a photo. WhatsApp re-compresses ' +
62
+ 'photos; use this when the exact pixels matter (screenshots, diagrams, charts).',
63
+ },
64
+ reply_to_message_id: {
65
+ type: 'string',
66
+ description:
67
+ 'Optional inbound message id to quote — the reply appears attached to that ' +
68
+ 'message. Use the message_id of the turn being answered, especially in a busy group.',
69
+ },
70
+ message_id: {
71
+ type: 'string',
72
+ description:
73
+ 'Optional inbound message id from the <channel> tag — clears the ⏳ ack ' +
74
+ 'reaction the gateway left on it.',
75
+ },
76
+ account_id: {
77
+ type: 'string',
78
+ description:
79
+ 'Which linked WhatsApp number to send from — copy account_id from ' +
80
+ 'the <channel> tag so the reply comes from the number the message ' +
81
+ 'arrived on. Omit only if the tag has none.',
82
+ },
83
+ },
84
+ required: ['chat_id'],
85
+ },
86
+ },
87
+ ];
88
+ }
89
+
90
+ async handleTool(name: string, args: Record<string, unknown>): Promise<McpToolResult> {
91
+ if (name === 'whatsapp_reply') return this.handleReply(args);
92
+ return { content: [{ type: 'text', text: `Unknown tool: ${name}` }], isError: true };
93
+ }
94
+
95
+ private async handleReply(args: Record<string, unknown>): Promise<McpToolResult> {
96
+ const chatId = typeof args.chat_id === 'string' ? args.chat_id : '';
97
+ const text = typeof args.text === 'string' ? args.text : '';
98
+ const imagePath = typeof args.image_path === 'string' ? args.image_path : undefined;
99
+ const accountId = typeof args.account_id === 'string' && args.account_id ? args.account_id : undefined;
100
+ const replyTo =
101
+ typeof args.reply_to_message_id === 'string' && args.reply_to_message_id
102
+ ? args.reply_to_message_id
103
+ : undefined;
104
+ const messageId = typeof args.message_id === 'string' && args.message_id ? args.message_id : undefined;
105
+ const asDocument = args.as_document === true;
106
+ const agentId = process.env.GATEWAY_AGENT_ID ?? '';
107
+ const apiUrl = process.env.GATEWAY_API_URL ?? '';
108
+ const apiKey = process.env.GATEWAY_API_KEY ?? '';
109
+
110
+ if (!chatId) {
111
+ return { content: [{ type: 'text', text: 'whatsapp_reply: missing chat_id' }], isError: true };
112
+ }
113
+ if (!text && !imagePath) {
114
+ return {
115
+ content: [{ type: 'text', text: 'whatsapp_reply: text or image_path is required' }],
116
+ isError: true,
117
+ };
118
+ }
119
+ if (!agentId || !apiUrl || !apiKey) {
120
+ return {
121
+ content: [{ type: 'text', text: 'whatsapp_reply: missing gateway API bridge env vars' }],
122
+ isError: true,
123
+ };
124
+ }
125
+
126
+ try {
127
+ const res = await fetch(`${apiUrl}/api/v1/agents/${agentId}/whatsapp/send`, {
128
+ method: 'POST',
129
+ headers: {
130
+ 'Content-Type': 'application/json',
131
+ Authorization: `Bearer ${apiKey}`,
132
+ },
133
+ // reply_to_message_id (quote) and message_id (ack-clear) are handled
134
+ // gateway-side: Baileys has no stateless send path, so unlike Slack's
135
+ // module this one can't call the platform API itself — the route
136
+ // forwards both to the live WhatsAppManager.
137
+ body: JSON.stringify({
138
+ jid: chatId,
139
+ text,
140
+ image_path: imagePath,
141
+ account_id: accountId,
142
+ reply_to_message_id: replyTo,
143
+ message_id: messageId,
144
+ as_document: asDocument || undefined,
145
+ }),
146
+ });
147
+ if (!res.ok) {
148
+ const body = (await res.json().catch(() => ({}))) as { error?: string };
149
+ return {
150
+ content: [{ type: 'text', text: `whatsapp_reply failed: ${body.error ?? res.status}` }],
151
+ isError: true,
152
+ };
153
+ }
154
+ return { content: [{ type: 'text', text: 'Sent message via WhatsApp.' }] };
155
+ } catch (err) {
156
+ return {
157
+ content: [{ type: 'text', text: `whatsapp_reply failed: ${(err as Error).message}` }],
158
+ isError: true,
159
+ };
160
+ }
161
+ }
162
+ }