whatsapp_subscribe_contact_presence
Monitor a WhatsApp contact's online status and availability by subscribing to real-time presence updates using their contact ID.
Instructions
Subscribe to presence updates for a specific contact.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| contactId | Yes | Contact ID (phone number with @s.whatsapp.net) |
Implementation Reference
- src/tools/contacts.ts:217-244 (handler)The complete ToolHandler implementation for 'whatsapp_subscribe_contact_presence', defining the input schema, description, and handler logic that subscribes to presence updates via WSAPI.export const subscribeToContactPresence: ToolHandler = { name: 'whatsapp_subscribe_contact_presence', description: 'Subscribe to presence updates for a specific 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('Subscribing to contact presence', { contactId: input.contactId }); await wsapiClient.post(`/contacts/${input.contactId}/presence`, {}); logger.info('Subscribed to contact presence successfully', { contactId: input.contactId }); return { success: true, message: 'Successfully subscribed to contact presence updates', }; }, };
- src/server.ts:57-76 (registration)Registers all tools from contactTools (which includes whatsapp_subscribe_contact_presence) by adding them to the server's tools Map.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}`); }); });
- src/tools/contacts.ts:247-255 (registration)Local registration of the subscribeToContactPresence tool within the contactTools export object, which is then imported into server.ts.export const contactTools = { getContacts, getContact, createContact, updateContact, getContactPicture, getContactBusinessProfile, subscribeToContactPresence, };
- src/tools/contacts.ts:220-229 (schema)Input schema definition requiring a contactId string for the tool.inputSchema: { type: 'object', properties: { contactId: { type: 'string', description: 'Contact ID (phone number with @s.whatsapp.net)', }, }, required: ['contactId'], },