Skip to main content
Glama
wsapi-chat
by wsapi-chat

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
NameRequiredDescriptionDefault
toYesRecipient phone number (with @s.whatsapp.net) or group ID (with @g.us)
textYesMessage text content (max 4096 characters)
mentionsNoList of phone numbers to mention in the message
replyToNoID of the message being replied to
isForwardedNoWhether the message should be marked as forwarded

Implementation Reference

  • 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', }; }, };
  • 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`); }
  • 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, };
  • 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; }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/wsapi-chat/wsapi-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server