whatsapp_get_pair_code
Generate a WhatsApp pairing code for account authentication by providing a valid phone number to initiate the login process.
Instructions
Get pairing code for WhatsApp login.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| phone | Yes | Phone number (10-15 digits) |
Input Schema (JSON Schema)
{
"properties": {
"phone": {
"description": "Phone number (10-15 digits)",
"type": "string"
}
},
"required": [
"phone"
],
"type": "object"
}
Implementation Reference
- src/tools/session.ts:41-55 (handler)Core implementation of the whatsapp_get_pair_code tool. Validates phone input, fetches pairing code from WSAPI endpoint `/session/login/code/{phone}`, and returns success response with pairCode.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 for validating the 'phone' input parameter (10-15 digits) used 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 'whatsapp_get_pair_code' from sessionTools, into the server's tools Map by iterating over tool collections.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/validation/schemas.ts:305-312 (helper)Helper function used in the handler to validate inputs against Zod schemas, throwing detailed errors on failure.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; }
- src/tools/session.ts:68-68 (registration)Exports the collection of session-related tools, including getPairCode (whatsapp_get_pair_code), for registration in the server.export const sessionTools = { getSessionStatus, getQRCode, getQRCodeImage, getPairCode, logout };