Skip to main content
Glama
by wsapi-chat

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

NameRequiredDescriptionDefault
phoneYesPhone number (10-15 digits)

Input Schema (JSON Schema)

{ "properties": { "phone": { "description": "Phone number (10-15 digits)", "type": "string" } }, "required": [ "phone" ], "type": "object" }

Implementation Reference

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

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