Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
docs(api): register ChatSummary schema and document kind
Yudhi Armyndharisf9e2edaecbcb
diff --git a/docs/06-api-specification.md b/docs/06-api-specification.mdindex 2064074e1..144c54393 100644--- a/docs/06-api-specification.md+++ b/docs/06-api-specification.md@@ -336,6 +336,7 @@ Get active chats for a session, most-recent first (paginated)."id": "[email protected]","name": "Alice","isGroup": false,+ "kind": "individual","unreadCount": 2,"timestamp": 1719306115,"lastMessage": "See you tomorrow"@@ -343,7 +344,7 @@ Get active chats for a session, most-recent first (paginated).]```-Sorted by `timestamp` DESC (most recent first) then paginated. `timestamp` is an epoch number (seconds).+Sorted by `timestamp` DESC (most recent first) then paginated. `timestamp` is an epoch number (seconds). `kind` is the user-facing chat discriminator — one of `individual|group|channel|status|broadcast|unknown`; `isGroup` is retained for back-compat (true only for `kind: "group"`).**Errors:** `400` session not started · `401` · `403` · `404` session not found@@ -765,7 +766,7 @@ Get persisted message history for a session from the local DB (paginated, filter}```-Each `Message`: `{ id (uuid), sessionId, waMessageId (string|null), chatId, from, to, body (string|null), type, direction ('incoming'|'outgoing'), timestamp (number|null), metadata (object|null), status ('pending'|'sent'|'delivered'|'read'|'failed'), createdAt (ISO date) }`. Ordered by `createdAt` DESC. The response is the raw service object (no envelope).+Each `Message`: `{ id (uuid), sessionId, waMessageId (string|null), chatId, from, to, body (string|null), type, direction ('incoming'|'outgoing'), timestamp (number|null), metadata (object|null), status ('pending'|'sent'|'delivered'|'read'|'failed'), createdAt (ISO date) }`. Ordered by `createdAt` DESC. The response is the raw service object (no envelope). Unlike the live `IncomingMessage` shape below, this persisted `Message` does **not** carry `kind` — re-derive the chat kind from `chatId` (see `ChatKind` / `chatKind()`) if needed.**Errors:** `401` missing/invalid API key@@ -806,13 +807,14 @@ Returns a bare array of engine-neutral `IncomingMessage` objects:"timestamp": 1719312000,"fromMe": false,"isGroup": false,+ "kind": "individual","author": "[email protected]","senderPhone": "628123456789"}]```-Each item may also include `isStatusBroadcast`, `mentionedIds`, `isLidSender`, `contact`, `media { mimetype, filename?, data?, omitted?, sizeBytes? }`, `quotedMessage { id, body }`, `call { video, missed }` (for `call` messages), and `location { latitude, longitude, description?, address?, url? }`. `type` is one of `text|image|video|audio|voice|document|sticker|location|contact|call|revoked|masked|unknown`. A `masked` message is one WhatsApp deliberately withholds from linked/companion devices — e.g. a high-security business OTP — so its `body` is empty by design (the content is only available on the primary phone) rather than a parsing failure; this occurs on the Baileys engine.+Each item may also include `isStatusBroadcast`, `mentionedIds`, `isLidSender`, `contact`, `media { mimetype, filename?, data?, omitted?, sizeBytes? }`, `quotedMessage { id, body }`, `call { video, missed }` (for `call` messages), and `location { latitude, longitude, description?, address?, url? }`. `type` is one of `text|image|video|audio|voice|document|sticker|location|contact|call|revoked|masked|unknown`. A `masked` message is one WhatsApp deliberately withholds from linked/companion devices — e.g. a high-security business OTP — so its `body` is empty by design (the content is only available on the primary phone) rather than a parsing failure; this occurs on the Baileys engine. `kind` is the user-facing chat discriminator of `chatId` — one of `individual|group|channel|status|broadcast|unknown`; it supersedes `isStatusBroadcast` (equivalent to `kind === 'status'`), which is retained for back-compat.**Errors:** `400` session not active · `401` missing/invalid API key · `500` engine errordiff --git a/openapi.json b/openapi.jsonindex 8048c758a..966f2a728 100644--- a/openapi.json+++ b/openapi.json@@ -725,7 +725,17 @@],"responses": {"200": {- "description": "List of active chats (most recent first)"+ "description": "List of active chats (most recent first)",+ "content": {+ "application/json": {+ "schema": {+ "type": "array",+ "items": {+ "$ref": "#/components/schemas/ChatSummaryDto"+ }+ }+ }+ }},"400": {"description": "Session not ready"@@ -6198,6 +6208,58 @@"status"]},+ "ChatSummaryDto": {+ "type": "object",+ "properties": {+ "id": {+ "type": "string",+ "example": "[email protected]"+ },+ "name": {+ "type": "string",+ "example": "Alice"+ },+ "isGroup": {+ "type": "boolean",+ "description": "Retained for back-compat; true for @g.us chats.",+ "example": false+ },+ "kind": {+ "type": "string",+ "enum": [+ "individual",+ "group",+ "channel",+ "status",+ "broadcast",+ "unknown"+ ],+ "description": "User-facing chat kind.",+ "example": "individual"+ },+ "unreadCount": {+ "type": "number",+ "example": 1+ },+ "timestamp": {+ "type": "number",+ "description": "Unix seconds of the last activity.",+ "example": 1700000010+ },+ "lastMessage": {+ "type": "string",+ "example": "hi"+ }+ },+ "required": [+ "id",+ "name",+ "isGroup",+ "kind",+ "unreadCount",+ "timestamp"+ ]+ },"MarkChatReadDto": {"type": "object","properties": {diff --git a/src/modules/session/dto/chat-summary.dto.ts b/src/modules/session/dto/chat-summary.dto.tsnew file mode 100644index 000000000..575c2a26e--- /dev/null+++ b/src/modules/session/dto/chat-summary.dto.ts@@ -0,0 +1,28 @@+import { ApiProperty } from '@nestjs/swagger';+import type { ChatKind } from '../../../engine/identity/wa-id';++const CHAT_KINDS: ChatKind[] = ['individual', 'group', 'channel', 'status', 'broadcast', 'unknown'];++/** OpenAPI mirror of the engine `ChatSummary` (documentation only; the runtime returns the interface). */+export class ChatSummaryDto {+ @ApiProperty({ example: '[email protected]' })+ id!: string;++ @ApiProperty({ example: 'Alice' })+ name!: string;++ @ApiProperty({ description: 'Retained for back-compat; true for @g.us chats.', example: false })+ isGroup!: boolean;++ @ApiProperty({ enum: CHAT_KINDS, description: 'User-facing chat kind.', example: 'individual' })+ kind!: ChatKind;++ @ApiProperty({ example: 1 })+ unreadCount!: number;++ @ApiProperty({ description: 'Unix seconds of the last activity.', example: 1700000010 })+ timestamp!: number;++ @ApiProperty({ required: false, example: 'hi' })+ lastMessage?: string;+}diff --git a/src/modules/session/dto/index.ts b/src/modules/session/dto/index.tsindex cd141f617..7a942c78d 100644--- a/src/modules/session/dto/index.ts+++ b/src/modules/session/dto/index.ts@@ -4,3 +4,4 @@ export * from './mark-chat-read.dto';export * from './delete-chat.dto';export * from './send-chat-state.dto';export * from './request-pairing-code.dto';+export * from './chat-summary.dto';diff --git a/src/modules/session/session.controller.ts b/src/modules/session/session.controller.tsindex 3acd7f432..8c5fcda59 100644--- a/src/modules/session/session.controller.ts+++ b/src/modules/session/session.controller.ts@@ -10,6 +10,7 @@ import {SendChatStateDto,RequestPairingCodeDto,PairingCodeResponseDto,+ ChatSummaryDto,} from './dto';import { Session } from './entities/session.entity';import { ChatSummary } from '../../engine/interfaces/whatsapp-engine.interface';@@ -228,7 +229,7 @@ export class SessionController {@Get(':id/chats')@ApiOperation({ summary: 'Get active chats for a session' })@ApiParam({ name: 'id', description: 'Session ID' })- @ApiResponse({ status: 200, description: 'List of active chats (most recent first)' })+ @ApiResponse({ status: 200, description: 'List of active chats (most recent first)', type: [ChatSummaryDto] })@ApiResponse({ status: 400, description: 'Session not ready' })@ApiResponse({ status: 404, description: 'Session not found' })@ApiQuery({ name: 'limit', required: false, description: 'Max chats to return (1–1000, default 1000)' })