waha_get_groups
Retrieve WhatsApp group lists with customizable filtering, sorting, and pagination options for efficient chat management.
Instructions
List all groups with filtering and pagination options.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sortBy | No | Sort field (default: id) | |
| sortOrder | No | Sort order (default: asc) | |
| limit | No | Limit results (default: 100, max: 100) | |
| offset | No | Offset for pagination | |
| exclude | No | Exclude fields like 'participants' |
Implementation Reference
- src/index.ts:1872-1889 (handler)The handler function that implements the core logic of the 'waha_get_groups' tool. It parses arguments, calls the WAHAClient.getGroups method, and returns a formatted text response with the list of groups as JSON.private async handleGetGroups(args: any) { const groups = await this.wahaClient.getGroups({ sortBy: args.sortBy, sortOrder: args.sortOrder, limit: args.limit, offset: args.offset, exclude: args.exclude, }); return { content: [ { type: "text", text: `Found ${groups.length} group(s):\n${JSON.stringify(groups, null, 2)}`, }, ], }; }
- src/index.ts:516-546 (registration)Tool registration in the ListToolsRequestSchema handler, including name, description, and input schema definition for validation.name: "waha_get_groups", description: "List all groups with filtering and pagination options.", inputSchema: { type: "object", properties: { sortBy: { type: "string", enum: ["id", "name"], description: "Sort field (default: id)", }, sortOrder: { type: "string", enum: ["asc", "desc"], description: "Sort order (default: asc)", }, limit: { type: "number", description: "Limit results (default: 100, max: 100)", }, offset: { type: "number", description: "Offset for pagination", }, exclude: { type: "array", items: { type: "string" }, description: "Exclude fields like 'participants'", }, }, }, },
- src/client/waha-client.ts:748-769 (helper)Supporting method in WAHAClient that performs the actual HTTP GET request to the WAHA API endpoint /api/{session}/groups with query parameters for sorting, pagination, and filtering.async getGroups(params?: { sortBy?: "id" | "name"; sortOrder?: "asc" | "desc"; limit?: number; offset?: number; exclude?: string[]; }): Promise<any[]> { const queryParams: Record<string, any> = {}; if (params?.sortBy) queryParams.sortBy = params.sortBy; if (params?.sortOrder) queryParams.sortOrder = params.sortOrder; if (params?.limit) queryParams.limit = Math.min(params.limit, 100); if (params?.offset) queryParams.offset = params.offset; if (params?.exclude) queryParams.exclude = params.exclude; const queryString = this.buildQueryString(queryParams); const endpoint = `/api/${this.session}/groups${queryString}`; return this.request<any[]>(endpoint, { method: "GET", }); }