add_label_to_chat
Add a label to a specific WhatsApp chat using session ID, label ID, and chat ID to organize conversations.
Instructions
Apply a label to a specific WhatsApp chat
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sessionId | Yes | Session ID | |
| labelId | Yes | Label ID to apply | |
| chatId | Yes | Chat ID to label |
Implementation Reference
- src/tools/labels.ts:58-76 (handler)The 'add_label_to_chat' tool handler: registers with MCP server, accepts sessionId/labelId/chatId, and calls POST /sessions/{sessionId}/labels/{labelId}/chats with the chatId in the body.
server.registerTool( "add_label_to_chat", { description: "Apply a label to a specific WhatsApp chat", inputSchema: { sessionId: z.string().describe("Session ID"), labelId: z.string().describe("Label ID to apply"), chatId: z.string().describe("Chat ID to label"), }, }, async ({ sessionId, labelId, chatId }) => { const data = await openwaClient({ method: "POST", path: `/sessions/${sessionId}/labels/${labelId}/chats`, body: { chatId }, }); return { content: [{ type: "text" as const, text: JSON.stringify(data, null, 2) }] }; } ); - src/tools/labels.ts:62-67 (schema)Input schema for add_label_to_chat: sessionId (string), labelId (string), chatId (string) — all required.
inputSchema: { sessionId: z.string().describe("Session ID"), labelId: z.string().describe("Label ID to apply"), chatId: z.string().describe("Chat ID to label"), }, }, - src/index.ts:10-10 (registration)Registration import: registerLabelTools is imported from ./tools/labels.js and called on line 21.
import { registerLabelTools } from "./tools/labels.js"; - src/index.ts:21-21 (registration)Registration call: registerLabelTools(server) which registers all label tools including add_label_to_chat.
registerLabelTools(server); - src/client.ts:1-35 (helper)The openwaClient helper function used by the handler to make HTTP requests to the OpenWA API.
const BASE_URL = process.env.OPENWA_BASE_URL || "http://localhost:2785/api"; const API_KEY = process.env.OPENWA_API_KEY || ""; interface RequestOptions { method: string; path: string; body?: Record<string, unknown>; } export async function openwaClient<T = unknown>(opts: RequestOptions): Promise<T> { const url = `${BASE_URL}${opts.path}`; const headers: Record<string, string> = { "Content-Type": "application/json", "X-API-Key": API_KEY, }; const res = await fetch(url, { method: opts.method, headers, body: opts.body ? JSON.stringify(opts.body) : undefined, }); const text = await res.text(); if (!res.ok) { throw new Error(`OpenWA API ${res.status}: ${text}`); } try { return JSON.parse(text) as T; } catch { return text as T; } }