whatsapp_get_pair_code
Generate a WhatsApp pairing code for logging into an account using a phone number. This tool enables authentication by creating a code that connects to the WhatsApp service.
Instructions
Get pairing code for WhatsApp login.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| phone | Yes | Phone number (10-15 digits) |
Implementation Reference
- src/tools/session.ts:41-55 (handler)The main handler implementation for the 'whatsapp_get_pair_code' tool. It validates the input phone number using getSessionLoginCodeSchema, logs the request, fetches the pair code from the WSAPI endpoint `/session/login/code/{phone}`, and returns the result.export const getPairCode: ToolHandler = { name: 'whatsapp_get_pair_code', description: 'Get pairing code for WhatsApp login.', inputSchema: { type: 'object', properties: { phone: { type: 'string', description: 'Phone number (10-15 digits)' } }, required: ['phone'], }, handler: async (args: any) => { const input = validateInput(getSessionLoginCodeSchema, args); logger.info('Getting pair code', { phone: input.phone }); const result = await wsapiClient.get(`/session/login/code/${input.phone}`); return { success: true, pairCode: result, message: 'Pair code retrieved successfully' }; }, };
- src/validation/schemas.ts:277-279 (schema)Zod schema used for validating the input 'phone' parameter (10-15 digits) in the whatsapp_get_pair_code handler.export const getSessionLoginCodeSchema = z.object({ phone: z.string().regex(/^\d{10,15}$/), });
- src/server.ts:53-79 (registration)Registers all tools including those from sessionTools (which contains whatsapp_get_pair_code) into the server's tools Map by iterating over tool categories and setting each tool by its name.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/session.ts:68-68 (registration)Groups and exports the session-related tools including getPairCode (whatsapp_get_pair_code) for registration in the server.export const sessionTools = { getSessionStatus, getQRCode, getQRCodeImage, getPairCode, logout };