whatsapp_send_text
Send text messages to WhatsApp contacts or groups. Supports mentions, replies, and forwarding functionality for comprehensive messaging.
Instructions
Send a text message to a WhatsApp contact or group. Supports mentions and replies.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| to | Yes | Recipient phone number (with @s.whatsapp.net) or group ID (with @g.us) | |
| text | Yes | Message text content (max 4096 characters) | |
| mentions | No | List of phone numbers to mention in the message | |
| replyTo | No | ID of the message being replied to | |
| isForwarded | No | Whether the message should be marked as forwarded |
Implementation Reference
- src/tools/messaging.ts:25-73 (handler)Full ToolHandler object for 'whatsapp_send_text', including name, description, inputSchema, and the core handler function that performs input validation and sends the message via wsapiClient.export const sendTextMessage: ToolHandler = { name: 'whatsapp_send_text', description: 'Send a text message to a WhatsApp contact or group. Supports mentions and replies.', inputSchema: { type: 'object', properties: { to: { type: 'string', description: 'Recipient phone number (with @s.whatsapp.net) or group ID (with @g.us)', }, text: { type: 'string', description: 'Message text content (max 4096 characters)', }, mentions: { type: 'array', items: { type: 'string' }, description: 'List of phone numbers to mention in the message', optional: true, }, replyTo: { type: 'string', description: 'ID of the message being replied to', optional: true, }, isForwarded: { type: 'boolean', description: 'Whether the message should be marked as forwarded', optional: true, }, }, required: ['to', 'text'], }, handler: async (args: any) => { const input = validateInput(sendTextMessageSchema, args) as SendTextMessageInput; logger.info('Sending text message', { to: input.to, textLength: input.text.length }); const result = await wsapiClient.post('/messages/text', input); logger.info('Text message sent successfully', { messageId: result.id }); return { success: true, messageId: result.id, message: 'Text message sent successfully', }; }, };
- src/validation/schemas.ts:12-18 (schema)Zod validation schema (sendTextMessageSchema) used in the handler for input validation.export const sendTextMessageSchema = z.object({ to: chatIdSchema, text: z.string().min(1).max(4096), mentions: z.array(phoneNumberSchema).optional(), replyTo: messageIdSchema.optional(), isForwarded: z.boolean().optional(), });
- src/server.ts:53-79 (registration)Server method setupToolHandlers() that registers all tools, including whatsapp_send_text from messagingTools, into the server's tools Map.private setupToolHandlers(): void { logger.info('Setting up tool handlers'); // Register all tool categories const toolCategories = [ messagingTools, contactTools, groupTools, chatTools, sessionTools, instanceTools, accountTools, ]; toolCategories.forEach(category => { Object.values(category).forEach(tool => { if (this.tools.has(tool.name)) { logger.warn(`Tool ${tool.name} already registered, skipping`); return; } this.tools.set(tool.name, tool); logger.debug(`Registered tool: ${tool.name}`); }); }); logger.info(`Registered ${this.tools.size} tools`); }
- src/tools/messaging.ts:544-555 (registration)Export of messagingTools object containing the sendTextMessage handler, which is imported and registered in the server.export const messagingTools = { sendTextMessage, sendImageMessage, sendVideoMessage, sendLinkMessage, sendReactionMessage, editMessage, deleteMessage, markMessageAsRead, starMessage, ...advancedMessagingTools, };
- src/validation/schemas.ts:305-312 (helper)validateInput helper function called in the handler to validate arguments against the schema.export function validateInput<T>(schema: z.ZodSchema<T>, data: unknown): T { const result = schema.safeParse(data); if (!result.success) { const errors = result.error.errors.map(err => `${err.path.join('.')}: ${err.message}`); throw new Error(`Validation failed: ${errors.join(', ')}`); } return result.data; }