@wsapichat/mcp-server 1.0.5 → 3.0.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.
Files changed (91) hide show
  1. package/README.md +58 -339
  2. package/dist/client/index.d.ts +4 -1
  3. package/dist/client/index.d.ts.map +1 -1
  4. package/dist/client/index.js +47 -28
  5. package/dist/client/index.js.map +1 -1
  6. package/dist/config/index.d.ts +19 -54
  7. package/dist/config/index.d.ts.map +1 -1
  8. package/dist/config/index.js +57 -29
  9. package/dist/config/index.js.map +1 -1
  10. package/dist/index.d.ts +1 -1
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +42 -36
  13. package/dist/index.js.map +1 -1
  14. package/dist/server.d.ts.map +1 -1
  15. package/dist/server.js +127 -59
  16. package/dist/server.js.map +1 -1
  17. package/dist/tools/calls.d.ts +6 -0
  18. package/dist/tools/calls.d.ts.map +1 -0
  19. package/dist/tools/calls.js +26 -0
  20. package/dist/tools/calls.js.map +1 -0
  21. package/dist/tools/chats.d.ts +19 -1
  22. package/dist/tools/chats.d.ts.map +1 -1
  23. package/dist/tools/chats.js +242 -39
  24. package/dist/tools/chats.js.map +1 -1
  25. package/dist/tools/communities.d.ts +36 -0
  26. package/dist/tools/communities.d.ts.map +1 -0
  27. package/dist/tools/communities.js +318 -0
  28. package/dist/tools/communities.js.map +1 -0
  29. package/dist/tools/contacts.d.ts +9 -9
  30. package/dist/tools/contacts.d.ts.map +1 -1
  31. package/dist/tools/contacts.js +68 -158
  32. package/dist/tools/contacts.js.map +1 -1
  33. package/dist/tools/groups.d.ts +33 -1
  34. package/dist/tools/groups.d.ts.map +1 -1
  35. package/dist/tools/groups.js +367 -33
  36. package/dist/tools/groups.js.map +1 -1
  37. package/dist/tools/media.d.ts +6 -0
  38. package/dist/tools/media.d.ts.map +1 -0
  39. package/dist/tools/media.js +39 -0
  40. package/dist/tools/media.js.map +1 -0
  41. package/dist/tools/messaging-advanced.d.ts +1 -1
  42. package/dist/tools/messaging-advanced.d.ts.map +1 -1
  43. package/dist/tools/messaging-advanced.js +135 -281
  44. package/dist/tools/messaging-advanced.js.map +1 -1
  45. package/dist/tools/messaging.d.ts +5 -1
  46. package/dist/tools/messaging.d.ts.map +1 -1
  47. package/dist/tools/messaging.js +241 -319
  48. package/dist/tools/messaging.js.map +1 -1
  49. package/dist/tools/newsletters.d.ts +16 -0
  50. package/dist/tools/newsletters.d.ts.map +1 -0
  51. package/dist/tools/newsletters.js +131 -0
  52. package/dist/tools/newsletters.js.map +1 -0
  53. package/dist/tools/session.d.ts +3 -1
  54. package/dist/tools/session.d.ts.map +1 -1
  55. package/dist/tools/session.js +72 -37
  56. package/dist/tools/session.js.map +1 -1
  57. package/dist/tools/status.d.ts +14 -0
  58. package/dist/tools/status.d.ts.map +1 -0
  59. package/dist/tools/status.js +106 -0
  60. package/dist/tools/status.js.map +1 -0
  61. package/dist/tools/users.d.ts +20 -0
  62. package/dist/tools/users.d.ts.map +1 -0
  63. package/dist/tools/users.js +175 -0
  64. package/dist/tools/users.js.map +1 -0
  65. package/dist/types/api.d.ts +4508 -1726
  66. package/dist/types/api.d.ts.map +1 -1
  67. package/dist/utils/errors.d.ts +1 -1
  68. package/dist/utils/errors.d.ts.map +1 -1
  69. package/dist/utils/errors.js +43 -42
  70. package/dist/utils/errors.js.map +1 -1
  71. package/dist/utils/logger.d.ts +1 -1
  72. package/dist/utils/logger.d.ts.map +1 -1
  73. package/dist/utils/logger.js +22 -22
  74. package/dist/utils/logger.js.map +1 -1
  75. package/dist/validation/schemas.d.ts +310 -651
  76. package/dist/validation/schemas.d.ts.map +1 -1
  77. package/dist/validation/schemas.js +245 -153
  78. package/dist/validation/schemas.js.map +1 -1
  79. package/package.json +25 -25
  80. package/dist/tools/account.d.ts +0 -14
  81. package/dist/tools/account.d.ts.map +0 -1
  82. package/dist/tools/account.js +0 -78
  83. package/dist/tools/account.js.map +0 -1
  84. package/dist/tools/instance.d.ts +0 -12
  85. package/dist/tools/instance.d.ts.map +0 -1
  86. package/dist/tools/instance.js +0 -54
  87. package/dist/tools/instance.js.map +0 -1
  88. package/dist/types/webhooks.d.ts +0 -1001
  89. package/dist/types/webhooks.d.ts.map +0 -1
  90. package/dist/types/webhooks.js +0 -6
  91. package/dist/types/webhooks.js.map +0 -1
@@ -1,481 +1,401 @@
1
- import { wsapiClient } from '../client/index.js';
2
- import { createLogger } from '../utils/logger.js';
3
- import { validateInput, sendTextMessageSchema, sendImageMessageSchema, sendVideoMessageSchema, sendLinkMessageSchema, sendReactionMessageSchema, editMessageSchema, deleteMessageSchema, markMessageAsReadSchema, starMessageSchema, } from '../validation/schemas.js';
4
- const logger = createLogger('messaging-tools');
5
- // Send text message tool
1
+ import { wsapiClient } from "../client/index.js";
2
+ import { createLogger } from "../utils/logger.js";
3
+ import { validateInput, sendTextMessageSchema, sendMediaMessageSchema, sendLinkMessageSchema, sendReactionMessageSchema, editMessageSchema, deleteMessageSchema, deleteMessageForMeSchema, markMessageAsReadSchema, starMessageSchema, pinMessageSchema, } from "../validation/schemas.js";
4
+ const logger = createLogger("messaging-tools");
6
5
  export const sendTextMessage = {
7
- name: 'whatsapp_send_text',
8
- description: 'Send a text message to a WhatsApp contact or group. Supports mentions and replies.',
6
+ name: "whatsapp_send_text",
7
+ description: "Send a text message to a WhatsApp contact or group. Supports mentions, replies, and ephemeral expiration.",
9
8
  inputSchema: {
10
- type: 'object',
9
+ type: "object",
11
10
  properties: {
12
- to: {
13
- type: 'string',
14
- description: 'Recipient phone number (with @s.whatsapp.net) or group ID (with @g.us)',
15
- },
11
+ to: { type: "string", description: "Recipient JID (user or group)" },
16
12
  text: {
17
- type: 'string',
18
- description: 'Message text content (max 4096 characters)',
13
+ type: "string",
14
+ description: "Message text content (max 4096 characters)",
19
15
  },
20
16
  mentions: {
21
- type: 'array',
22
- items: { type: 'string' },
23
- description: 'List of phone numbers to mention in the message',
24
- optional: true,
17
+ type: "array",
18
+ items: { type: "string" },
19
+ description: "JIDs of mentioned users",
25
20
  },
26
21
  replyTo: {
27
- type: 'string',
28
- description: 'ID of the message being replied to',
29
- optional: true,
22
+ type: "string",
23
+ description: "ID of the message being replied to",
24
+ },
25
+ replyToSenderId: {
26
+ type: "string",
27
+ description: "Sender JID of the message being replied to",
30
28
  },
31
- isForwarded: {
32
- type: 'boolean',
33
- description: 'Whether the message should be marked as forwarded',
34
- optional: true,
29
+ isForwarded: { type: "boolean", description: "Mark as forwarded" },
30
+ ephemeralExpiration: {
31
+ type: "string",
32
+ enum: ["off", "24h", "7d", "90d"],
33
+ description: "Disappearing message timer",
35
34
  },
36
35
  },
37
- required: ['to', 'text'],
36
+ required: ["to", "text"],
38
37
  },
39
38
  handler: async (args) => {
40
39
  const input = validateInput(sendTextMessageSchema, args);
41
- logger.info('Sending text message', { to: input.to, textLength: input.text.length });
42
- const result = await wsapiClient.post('/messages/text', input);
43
- logger.info('Text message sent successfully', { messageId: result.id });
40
+ logger.info("Sending text message", {
41
+ to: input.to,
42
+ textLength: input.text.length,
43
+ });
44
+ const result = await wsapiClient.post("/messages/text", input);
45
+ logger.info("Text message sent successfully", { messageId: result.id });
44
46
  return {
45
47
  success: true,
46
48
  messageId: result.id,
47
- message: 'Text message sent successfully',
49
+ message: "Text message sent successfully",
48
50
  };
49
51
  },
50
52
  };
51
- // Send image message tool
52
53
  export const sendImageMessage = {
53
- name: 'whatsapp_send_image',
54
- description: 'Send an image message to a WhatsApp contact or group. Can send from URL or base64.',
54
+ name: "whatsapp_send_image",
55
+ description: "Send an image message. Provide either data (base64) or url.",
55
56
  inputSchema: {
56
- type: 'object',
57
+ type: "object",
57
58
  properties: {
58
- to: {
59
- type: 'string',
60
- description: 'Recipient phone number (with @s.whatsapp.net) or group ID (with @g.us)',
61
- },
62
- imageBase64: {
63
- type: 'string',
64
- description: 'Base64 encoded image data (alternative to imageURL)',
65
- optional: true,
66
- },
67
- imageURL: {
68
- type: 'string',
69
- description: 'URL of the image to send (alternative to imageBase64)',
70
- optional: true,
71
- },
59
+ to: { type: "string", description: "Recipient JID" },
60
+ data: { type: "string", description: "Base64 encoded image data" },
61
+ url: { type: "string", description: "URL of the image" },
72
62
  mimeType: {
73
- type: 'string',
74
- enum: ['image/jpeg', 'image/png', 'image/webp', 'image/gif'],
75
- description: 'MIME type of the image',
76
- },
77
- caption: {
78
- type: 'string',
79
- description: 'Caption for the image (max 1024 characters)',
80
- optional: true,
63
+ type: "string",
64
+ description: "MIME type (auto-detected if omitted)",
81
65
  },
66
+ caption: { type: "string", description: "Caption for the image" },
82
67
  mentions: {
83
- type: 'array',
84
- items: { type: 'string' },
85
- description: 'List of phone numbers to mention in the caption',
86
- optional: true,
68
+ type: "array",
69
+ items: { type: "string" },
70
+ description: "JIDs of mentioned users",
87
71
  },
88
- replyTo: {
89
- type: 'string',
90
- description: 'ID of the message being replied to',
91
- optional: true,
92
- },
93
- isForwarded: {
94
- type: 'boolean',
95
- description: 'Whether the message should be marked as forwarded',
96
- optional: true,
72
+ replyTo: { type: "string", description: "Message ID to reply to" },
73
+ replyToSenderId: {
74
+ type: "string",
75
+ description: "Sender JID of the replied message",
97
76
  },
98
- viewOnce: {
99
- type: 'boolean',
100
- description: 'Whether the image should be sent as view-once',
101
- optional: true,
77
+ isForwarded: { type: "boolean", description: "Mark as forwarded" },
78
+ viewOnce: { type: "boolean", description: "Send as view-once" },
79
+ ephemeralExpiration: {
80
+ type: "string",
81
+ enum: ["off", "24h", "7d", "90d"],
102
82
  },
103
83
  },
104
- required: ['to', 'mimeType'],
84
+ required: ["to"],
105
85
  },
106
86
  handler: async (args) => {
107
- const input = validateInput(sendImageMessageSchema, args);
108
- logger.info('Sending image message', {
87
+ const input = validateInput(sendMediaMessageSchema, args);
88
+ logger.info("Sending image message", {
109
89
  to: input.to,
110
- mimeType: input.mimeType,
111
90
  hasCaption: !!input.caption,
112
- viewOnce: input.viewOnce,
113
91
  });
114
- const result = await wsapiClient.post('/messages/image', input);
115
- logger.info('Image message sent successfully', { messageId: result.id });
92
+ const result = await wsapiClient.post("/messages/image", input);
93
+ logger.info("Image message sent successfully", { messageId: result.id });
116
94
  return {
117
95
  success: true,
118
96
  messageId: result.id,
119
- message: 'Image message sent successfully',
97
+ message: "Image message sent successfully",
120
98
  };
121
99
  },
122
100
  };
123
- // Send video message tool
124
101
  export const sendVideoMessage = {
125
- name: 'whatsapp_send_video',
126
- description: 'Send a video message to a WhatsApp contact or group. Can send from URL or base64.',
102
+ name: "whatsapp_send_video",
103
+ description: "Send a video message. Provide either data (base64) or url.",
127
104
  inputSchema: {
128
- type: 'object',
105
+ type: "object",
129
106
  properties: {
130
- to: {
131
- type: 'string',
132
- description: 'Recipient phone number (with @s.whatsapp.net) or group ID (with @g.us)',
133
- },
134
- videoBase64: {
135
- type: 'string',
136
- description: 'Base64 encoded video data (alternative to videoURL)',
137
- optional: true,
138
- },
139
- videoURL: {
140
- type: 'string',
141
- description: 'URL of the video to send (alternative to videoBase64)',
142
- optional: true,
143
- },
107
+ to: { type: "string", description: "Recipient JID" },
108
+ data: { type: "string", description: "Base64 encoded video data" },
109
+ url: { type: "string", description: "URL of the video" },
144
110
  mimeType: {
145
- type: 'string',
146
- enum: ['video/mp4', 'video/3gp', 'video/mov', 'video/avi'],
147
- description: 'MIME type of the video',
148
- },
149
- caption: {
150
- type: 'string',
151
- description: 'Caption for the video (max 1024 characters)',
152
- optional: true,
153
- },
154
- viewOnce: {
155
- type: 'boolean',
156
- description: 'Whether the video should be sent as view-once',
157
- optional: true,
158
- },
159
- mentions: {
160
- type: 'array',
161
- items: { type: 'string' },
162
- description: 'List of phone numbers to mention in the caption',
163
- optional: true,
164
- },
165
- replyTo: {
166
- type: 'string',
167
- description: 'ID of the message being replied to',
168
- optional: true,
169
- },
170
- isForwarded: {
171
- type: 'boolean',
172
- description: 'Whether the message should be marked as forwarded',
173
- optional: true,
111
+ type: "string",
112
+ description: "MIME type (auto-detected if omitted)",
113
+ },
114
+ caption: { type: "string", description: "Caption for the video" },
115
+ mentions: { type: "array", items: { type: "string" } },
116
+ replyTo: { type: "string", description: "Message ID to reply to" },
117
+ replyToSenderId: {
118
+ type: "string",
119
+ description: "Sender JID of the replied message",
120
+ },
121
+ isForwarded: { type: "boolean" },
122
+ viewOnce: { type: "boolean", description: "Send as view-once" },
123
+ ephemeralExpiration: {
124
+ type: "string",
125
+ enum: ["off", "24h", "7d", "90d"],
174
126
  },
175
127
  },
176
- required: ['to', 'mimeType'],
128
+ required: ["to"],
177
129
  },
178
130
  handler: async (args) => {
179
- const input = validateInput(sendVideoMessageSchema, args);
180
- logger.info('Sending video message', {
181
- to: input.to,
182
- mimeType: input.mimeType,
183
- hasCaption: !!input.caption,
184
- viewOnce: input.viewOnce,
185
- });
186
- const result = await wsapiClient.post('/messages/video', input);
187
- logger.info('Video message sent successfully', { messageId: result.id });
131
+ const input = validateInput(sendMediaMessageSchema, args);
132
+ logger.info("Sending video message", { to: input.to });
133
+ const result = await wsapiClient.post("/messages/video", input);
134
+ logger.info("Video message sent successfully", { messageId: result.id });
188
135
  return {
189
136
  success: true,
190
137
  messageId: result.id,
191
- message: 'Video message sent successfully',
138
+ message: "Video message sent successfully",
192
139
  };
193
140
  },
194
141
  };
195
- // Send link message tool
196
142
  export const sendLinkMessage = {
197
- name: 'whatsapp_send_link',
198
- description: 'Send a link message with optional preview to a WhatsApp contact or group.',
143
+ name: "whatsapp_send_link",
144
+ description: "Send a link message with optional preview.",
199
145
  inputSchema: {
200
- type: 'object',
146
+ type: "object",
201
147
  properties: {
202
- to: {
203
- type: 'string',
204
- description: 'Recipient phone number (with @s.whatsapp.net) or group ID (with @g.us)',
205
- },
148
+ to: { type: "string", description: "Recipient JID" },
206
149
  text: {
207
- type: 'string',
208
- description: 'Message text content (max 4096 characters)',
209
- },
210
- url: {
211
- type: 'string',
212
- description: 'URL to include in the message',
213
- },
214
- title: {
215
- type: 'string',
216
- description: 'Title for the link preview (max 500 characters)',
217
- optional: true,
218
- },
219
- description: {
220
- type: 'string',
221
- description: 'Description for the link preview (max 1000 characters)',
222
- optional: true,
223
- },
224
- jpegThumbnail: {
225
- type: 'string',
226
- description: 'Base64 encoded JPEG thumbnail for the link preview',
227
- optional: true,
228
- },
229
- mentions: {
230
- type: 'array',
231
- items: { type: 'string' },
232
- description: 'List of phone numbers to mention in the message',
233
- optional: true,
234
- },
235
- replyTo: {
236
- type: 'string',
237
- description: 'ID of the message being replied to',
238
- optional: true,
239
- },
240
- isForwarded: {
241
- type: 'boolean',
242
- description: 'Whether the message should be marked as forwarded',
243
- optional: true,
150
+ type: "string",
151
+ description: "Message text (max 4096 characters)",
152
+ },
153
+ url: { type: "string", description: "URL to include" },
154
+ title: { type: "string", description: "Link preview title" },
155
+ description: { type: "string", description: "Link preview description" },
156
+ jpegThumbnail: { type: "string", description: "Base64 JPEG thumbnail" },
157
+ mentions: { type: "array", items: { type: "string" } },
158
+ replyTo: { type: "string" },
159
+ replyToSenderId: { type: "string" },
160
+ isForwarded: { type: "boolean" },
161
+ ephemeralExpiration: {
162
+ type: "string",
163
+ enum: ["off", "24h", "7d", "90d"],
244
164
  },
245
165
  },
246
- required: ['to', 'text', 'url'],
166
+ required: ["to", "text", "url"],
247
167
  },
248
168
  handler: async (args) => {
249
169
  const input = validateInput(sendLinkMessageSchema, args);
250
- logger.info('Sending link message', {
251
- to: input.to,
252
- url: input.url,
253
- hasTitle: !!input.title,
254
- hasDescription: !!input.description,
255
- });
256
- const result = await wsapiClient.post('/messages/link', input);
257
- logger.info('Link message sent successfully', { messageId: result.id });
170
+ logger.info("Sending link message", { to: input.to, url: input.url });
171
+ const result = await wsapiClient.post("/messages/link", input);
172
+ logger.info("Link message sent successfully", { messageId: result.id });
258
173
  return {
259
174
  success: true,
260
175
  messageId: result.id,
261
- message: 'Link message sent successfully',
176
+ message: "Link message sent successfully",
262
177
  };
263
178
  },
264
179
  };
265
- // Send reaction message tool
266
180
  export const sendReactionMessage = {
267
- name: 'whatsapp_send_reaction',
268
- description: 'Send a reaction (emoji) to a specific message.',
181
+ name: "whatsapp_send_reaction",
182
+ description: "Send a reaction (emoji) to a message. Send empty string to remove reaction.",
269
183
  inputSchema: {
270
- type: 'object',
184
+ type: "object",
271
185
  properties: {
272
186
  messageId: {
273
- type: 'string',
274
- description: 'ID of the message to react to',
275
- },
276
- to: {
277
- type: 'string',
278
- description: 'Chat ID where the message is located',
187
+ type: "string",
188
+ description: "ID of the message to react to",
279
189
  },
190
+ to: { type: "string", description: "Chat JID" },
280
191
  senderId: {
281
- type: 'string',
282
- description: 'ID of the original message sender',
192
+ type: "string",
193
+ description: "Sender of the original message (for groups)",
283
194
  },
284
195
  reaction: {
285
- type: 'string',
286
- description: 'Emoji reaction to send (max 10 characters)',
196
+ type: "string",
197
+ description: "Emoji reaction (empty string to remove)",
287
198
  },
288
199
  },
289
- required: ['messageId', 'to', 'senderId', 'reaction'],
200
+ required: ["messageId", "to", "reaction"],
290
201
  },
291
202
  handler: async (args) => {
292
203
  const input = validateInput(sendReactionMessageSchema, args);
293
- logger.info('Sending reaction', {
204
+ logger.info("Sending reaction", {
294
205
  messageId: input.messageId,
295
206
  to: input.to,
296
- reaction: input.reaction,
297
207
  });
298
208
  const result = await wsapiClient.post(`/messages/${input.messageId}/reaction`, {
299
209
  to: input.to,
300
210
  senderId: input.senderId,
301
211
  reaction: input.reaction,
302
212
  });
303
- logger.info('Reaction sent successfully', { messageId: result.id });
213
+ logger.info("Reaction sent successfully");
304
214
  return {
305
215
  success: true,
306
216
  messageId: result.id,
307
- message: 'Reaction sent successfully',
217
+ message: "Reaction sent successfully",
308
218
  };
309
219
  },
310
220
  };
311
- // Edit message tool
312
221
  export const editMessage = {
313
- name: 'whatsapp_edit_message',
314
- description: 'Edit a previously sent text message.',
222
+ name: "whatsapp_edit_message",
223
+ description: "Edit a previously sent text message.",
315
224
  inputSchema: {
316
- type: 'object',
225
+ type: "object",
317
226
  properties: {
318
- messageId: {
319
- type: 'string',
320
- description: 'ID of the message to edit',
321
- },
322
- to: {
323
- type: 'string',
324
- description: 'Chat ID where the message is located',
325
- },
227
+ messageId: { type: "string", description: "ID of the message to edit" },
228
+ to: { type: "string", description: "Chat JID" },
326
229
  text: {
327
- type: 'string',
328
- description: 'New text content for the message (max 4096 characters)',
230
+ type: "string",
231
+ description: "New text content (max 4096 characters)",
232
+ },
233
+ mentions: { type: "array", items: { type: "string" } },
234
+ ephemeralExpiration: {
235
+ type: "string",
236
+ enum: ["off", "24h", "7d", "90d"],
329
237
  },
330
238
  },
331
- required: ['messageId', 'to', 'text'],
239
+ required: ["messageId", "to", "text"],
332
240
  },
333
241
  handler: async (args) => {
334
242
  const input = validateInput(editMessageSchema, args);
335
- logger.info('Editing message', {
336
- messageId: input.messageId,
337
- to: input.to,
338
- textLength: input.text.length,
339
- });
340
- const result = await wsapiClient.put(`/messages/${input.messageId}/text`, {
243
+ logger.info("Editing message", { messageId: input.messageId });
244
+ const result = await wsapiClient.post(`/messages/${input.messageId}/edit`, {
341
245
  to: input.to,
342
246
  text: input.text,
247
+ mentions: input.mentions,
248
+ ephemeralExpiration: input.ephemeralExpiration,
343
249
  });
344
- logger.info('Message edited successfully', { messageId: result.id });
250
+ logger.info("Message edited successfully");
345
251
  return {
346
252
  success: true,
347
253
  messageId: result.id,
348
- message: 'Message edited successfully',
254
+ message: "Message edited successfully",
349
255
  };
350
256
  },
351
257
  };
352
- // Delete message tool
353
258
  export const deleteMessage = {
354
- name: 'whatsapp_delete_message',
355
- description: 'Delete a message for all participants in the chat.',
259
+ name: "whatsapp_delete_message",
260
+ description: "Delete a message for all participants.",
356
261
  inputSchema: {
357
- type: 'object',
262
+ type: "object",
358
263
  properties: {
359
- messageId: {
360
- type: 'string',
361
- description: 'ID of the message to delete',
362
- },
363
- chatId: {
364
- type: 'string',
365
- description: 'Chat ID where the message is located',
366
- },
367
- senderId: {
368
- type: 'string',
369
- description: 'ID of the message sender',
370
- },
264
+ messageId: { type: "string", description: "ID of the message to delete" },
265
+ chatId: { type: "string", description: "Chat JID" },
266
+ senderId: { type: "string", description: "Message sender JID" },
371
267
  },
372
- required: ['messageId', 'chatId', 'senderId'],
268
+ required: ["messageId", "chatId", "senderId"],
373
269
  },
374
270
  handler: async (args) => {
375
271
  const input = validateInput(deleteMessageSchema, args);
376
- logger.info('Deleting message', {
377
- messageId: input.messageId,
272
+ logger.info("Deleting message", { messageId: input.messageId });
273
+ await wsapiClient.post(`/messages/${input.messageId}/delete`, {
378
274
  chatId: input.chatId,
275
+ senderId: input.senderId,
379
276
  });
380
- await wsapiClient.put(`/messages/${input.messageId}/delete`, {
277
+ logger.info("Message deleted successfully");
278
+ return { success: true, message: "Message deleted successfully" };
279
+ },
280
+ };
281
+ export const deleteMessageForMe = {
282
+ name: "whatsapp_delete_message_for_me",
283
+ description: "Delete a message only for yourself.",
284
+ inputSchema: {
285
+ type: "object",
286
+ properties: {
287
+ messageId: { type: "string", description: "ID of the message to delete" },
288
+ chatId: { type: "string", description: "Chat JID" },
289
+ senderId: { type: "string", description: "Message sender JID" },
290
+ isFromMe: {
291
+ type: "boolean",
292
+ description: "Whether the message was sent by you",
293
+ },
294
+ timestamp: {
295
+ type: "string",
296
+ description: "Message timestamp (ISO 8601)",
297
+ },
298
+ },
299
+ required: ["messageId", "chatId"],
300
+ },
301
+ handler: async (args) => {
302
+ const input = validateInput(deleteMessageForMeSchema, args);
303
+ logger.info("Deleting message for me", { messageId: input.messageId });
304
+ await wsapiClient.post(`/messages/${input.messageId}/delete-for-me`, {
381
305
  chatId: input.chatId,
382
306
  senderId: input.senderId,
307
+ isFromMe: input.isFromMe,
308
+ timestamp: input.timestamp,
383
309
  });
384
- logger.info('Message deleted successfully', { messageId: input.messageId });
385
- return {
386
- success: true,
387
- message: 'Message deleted successfully',
388
- };
310
+ logger.info("Message deleted for me successfully");
311
+ return { success: true, message: "Message deleted for me successfully" };
389
312
  },
390
313
  };
391
- // Mark message as read tool
392
314
  export const markMessageAsRead = {
393
- name: 'whatsapp_mark_message_read',
394
- description: 'Mark a message as read.',
315
+ name: "whatsapp_mark_message_read",
316
+ description: "Mark a message as read.",
395
317
  inputSchema: {
396
- type: 'object',
318
+ type: "object",
397
319
  properties: {
398
- messageId: {
399
- type: 'string',
400
- description: 'ID of the message to mark as read',
401
- },
402
- chatId: {
403
- type: 'string',
404
- description: 'Chat ID where the message is located',
405
- },
406
- senderId: {
407
- type: 'string',
408
- description: 'ID of the message sender',
409
- },
320
+ messageId: { type: "string", description: "Message ID" },
321
+ chatId: { type: "string", description: "Chat JID" },
322
+ senderId: { type: "string", description: "Message sender JID" },
410
323
  receiptType: {
411
- type: 'string',
412
- enum: ['delivered', 'sender', 'read', 'played'],
413
- description: 'Type of receipt to send',
324
+ type: "string",
325
+ enum: ["delivered", "sender", "read", "played"],
326
+ description: "Receipt type",
414
327
  },
415
328
  },
416
- required: ['messageId', 'chatId', 'senderId', 'receiptType'],
329
+ required: ["messageId", "chatId", "senderId", "receiptType"],
417
330
  },
418
331
  handler: async (args) => {
419
332
  const input = validateInput(markMessageAsReadSchema, args);
420
- logger.info('Marking message as read', {
421
- messageId: input.messageId,
422
- chatId: input.chatId,
423
- receiptType: input.receiptType,
424
- });
425
- await wsapiClient.put(`/messages/${input.messageId}/read`, {
333
+ logger.info("Marking message as read", { messageId: input.messageId });
334
+ await wsapiClient.post(`/messages/${input.messageId}/read`, {
426
335
  chatId: input.chatId,
427
336
  senderId: input.senderId,
428
337
  receiptType: input.receiptType,
429
338
  });
430
- logger.info('Message marked as read successfully', { messageId: input.messageId });
431
- return {
432
- success: true,
433
- message: 'Message marked as read successfully',
434
- };
339
+ return { success: true, message: "Message marked as read successfully" };
435
340
  },
436
341
  };
437
- // Star message tool
438
342
  export const starMessage = {
439
- name: 'whatsapp_star_message',
440
- description: 'Star or unstar a message.',
343
+ name: "whatsapp_star_message",
344
+ description: "Star or unstar a message.",
441
345
  inputSchema: {
442
- type: 'object',
346
+ type: "object",
443
347
  properties: {
444
- messageId: {
445
- type: 'string',
446
- description: 'ID of the message to star',
447
- },
448
- chatId: {
449
- type: 'string',
450
- description: 'Chat ID where the message is located',
451
- },
452
- senderId: {
453
- type: 'string',
454
- description: 'ID of the message sender',
348
+ messageId: { type: "string", description: "Message ID" },
349
+ chatId: { type: "string", description: "Chat JID" },
350
+ senderId: { type: "string", description: "Message sender JID" },
351
+ starred: {
352
+ type: "boolean",
353
+ description: "True to star, false to unstar",
455
354
  },
456
355
  },
457
- required: ['messageId', 'chatId', 'senderId'],
356
+ required: ["messageId", "chatId", "senderId"],
458
357
  },
459
358
  handler: async (args) => {
460
359
  const input = validateInput(starMessageSchema, args);
461
- logger.info('Starring message', {
462
- messageId: input.messageId,
360
+ logger.info("Starring message", { messageId: input.messageId });
361
+ await wsapiClient.post(`/messages/${input.messageId}/star`, {
463
362
  chatId: input.chatId,
363
+ senderId: input.senderId,
364
+ starred: input.starred,
464
365
  });
465
- await wsapiClient.put(`/messages/${input.messageId}/star`, {
366
+ return { success: true, message: "Message starred successfully" };
367
+ },
368
+ };
369
+ export const pinMessage = {
370
+ name: "whatsapp_pin_message",
371
+ description: "Pin or unpin a message in a chat.",
372
+ inputSchema: {
373
+ type: "object",
374
+ properties: {
375
+ messageId: { type: "string", description: "Message ID" },
376
+ chatId: { type: "string", description: "Chat JID" },
377
+ senderId: { type: "string", description: "Message sender JID" },
378
+ pinned: { type: "boolean", description: "True to pin, false to unpin" },
379
+ pinExpiration: {
380
+ type: "string",
381
+ description: "Pin expiration (e.g. 24h, 7d, 30d)",
382
+ },
383
+ },
384
+ required: ["messageId", "chatId", "senderId"],
385
+ },
386
+ handler: async (args) => {
387
+ const input = validateInput(pinMessageSchema, args);
388
+ logger.info("Pinning message", { messageId: input.messageId });
389
+ await wsapiClient.post(`/messages/${input.messageId}/pin`, {
466
390
  chatId: input.chatId,
467
391
  senderId: input.senderId,
392
+ pinned: input.pinned,
393
+ pinExpiration: input.pinExpiration,
468
394
  });
469
- logger.info('Message starred successfully', { messageId: input.messageId });
470
- return {
471
- success: true,
472
- message: 'Message starred successfully',
473
- };
395
+ return { success: true, message: "Message pin updated successfully" };
474
396
  },
475
397
  };
476
- // Import advanced messaging tools
477
- import { advancedMessagingTools } from './messaging-advanced.js';
478
- // Export all messaging tools
398
+ import { advancedMessagingTools } from "./messaging-advanced.js";
479
399
  export const messagingTools = {
480
400
  sendTextMessage,
481
401
  sendImageMessage,
@@ -484,8 +404,10 @@ export const messagingTools = {
484
404
  sendReactionMessage,
485
405
  editMessage,
486
406
  deleteMessage,
407
+ deleteMessageForMe,
487
408
  markMessageAsRead,
488
409
  starMessage,
410
+ pinMessage,
489
411
  ...advancedMessagingTools,
490
412
  };
491
413
  //# sourceMappingURL=messaging.js.map