whatsapp_get_contact_picture
Retrieve the profile picture of a WhatsApp contact using their contact ID to display contact images within applications.
Instructions
Get the profile picture of a WhatsApp contact.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| contactId | Yes | Contact ID (phone number with @s.whatsapp.net) |
Input Schema (JSON Schema)
{
"properties": {
"contactId": {
"description": "Contact ID (phone number with @s.whatsapp.net)",
"type": "string"
}
},
"required": [
"contactId"
],
"type": "object"
}
Implementation Reference
- src/tools/contacts.ts:155-183 (handler)The ToolHandler implementation for 'whatsapp_get_contact_picture'. Validates the input contactId, fetches the profile picture using wsapiClient.get(`/contacts/${contactId}/picture`), logs the action, and returns the picture data.export const getContactPicture: ToolHandler = { name: 'whatsapp_get_contact_picture', description: 'Get the profile picture of a WhatsApp contact.', inputSchema: { type: 'object', properties: { contactId: { type: 'string', description: 'Contact ID (phone number with @s.whatsapp.net)', }, }, required: ['contactId'], }, handler: async (args: any) => { const input = validateInput(getContactSchema, args); logger.info('Getting contact picture', { contactId: input.contactId }); const result = await wsapiClient.get(`/contacts/${input.contactId}/picture`); logger.info('Retrieved contact picture successfully', { contactId: input.contactId }); return { success: true, picture: result, message: 'Contact picture retrieved successfully', }; }, };
- src/tools/contacts.ts:158-167 (schema)The input schema definition for the tool, specifying the required 'contactId' parameter.inputSchema: { type: 'object', properties: { contactId: { type: 'string', description: 'Contact ID (phone number with @s.whatsapp.net)', }, }, required: ['contactId'], },
- src/server.ts:58-76 (registration)Registration logic in setupToolHandlers() that includes 'contactTools' (containing whatsapp_get_contact_picture) in toolCategories and registers each tool by name into the server's tools Map.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}`); }); });
- src/validation/schemas.ts:173-175 (schema)Zod schema used internally by the handler for input validation (getContactSchema), defining contactId as a phone number pattern.export const getContactSchema = z.object({ contactId: phoneNumberSchema, });
- src/validation/schemas.ts:305-312 (helper)Utility function validateInput used in the handler to validate arguments against getContactSchema before API call.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; }