Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

docs(openapi): publish the contacts response schemas

Yudhi Armyndharis18ab337e72c7
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c9507375a..2643b6a72 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
+- **The ten contacts endpoints now publish the shape of what they return** — they documented a status and a sentence but no schema, so the committed OpenAPI snapshot had nothing to diff for any of them and a change to a response body could reach clients without the contract gate noticing; `GET /contacts/{contactId}/phone` returning `null` for an unresolvable id, and the batch picture lookup answering `null` per id rather than failing, are now stated rather than discovered by calling.
- **Fourteen more boolean environment variables are now validated at boot** — they are read with a bare `=== 'true'` / `!== 'false'` comparison, so a spelling like `DATABASE_SSL=require` silently configured the opposite of what was asked for; `DATABASE_SSL` in particular read as OFF and sent credentials in plaintext to a server the operator believed was TLS-protected. Only `true`/`false` (or blank) are accepted now, so a deployment using another spelling will fail startup until it is corrected. `MCP_READONLY` and `PUPPETEER_HEADLESS` stay tolerant deliberately — both fail toward the safe state.
- **The API description now documents the two statuses middleware returns before routing** — `415` for a compressed request body and `503` with `Retry-After` when too much body data is already in flight, neither of which appeared anywhere in the OpenAPI document despite applying to every operation.
- **The Helm chart now states the reason `replicaCount` must stay 1 that actually applies today** — the warning described two pods corrupting shared session auth, which a session lease and per-pod volumes already prevent, so an operator acting on it would mitigate the wrong thing.
diff --git a/openapi.json b/openapi.json
index 5ca4ec9a9..9c23b7e3f 100644
--- a/openapi.json
+++ b/openapi.json
@@ -3537,7 +3537,17 @@
],
"responses": {
"200": {
- "description": "List of contacts"
+ "description": "List of contacts, windowed by limit/offset. A bare array — there is no envelope.",
+ "content": {
+ "application/json": {
+ "schema": {
+ "type": "array",
+ "items": {
+ "$ref": "#/components/schemas/ContactDto"
+ }
+ }
+ }
+ }
},
"400": {
"description": "Session not ready"
@@ -3578,7 +3588,14 @@
],
"responses": {
"200": {
- "description": ""
+ "description": "Picture URL per requested id",
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/ProfilePicturesResponseDto"
+ }
+ }
+ }
}
},
"summary": "Batch-resolve profile picture URLs for up to 50 contacts",
@@ -3612,7 +3629,14 @@
],
"responses": {
"200": {
- "description": "Contact details"
+ "description": "Contact details",
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/ContactDto"
+ }
+ }
+ }
},
"404": {
"description": "Contact not found"
@@ -3657,7 +3681,14 @@
},
"responses": {
"200": {
- "description": "Contact saved"
+ "description": "Contact saved",
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/ContactAckResponseDto"
+ }
+ }
+ }
},
"400": {
"description": "Session not active or invalid request"
@@ -3692,7 +3723,14 @@
],
"responses": {
"200": {
- "description": "Contact deleted"
+ "description": "Contact deleted",
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/ContactAckResponseDto"
+ }
+ }
+ }
},
"400": {
"description": "Session not active"
@@ -3730,7 +3768,14 @@
],
"responses": {
"200": {
- "description": "Number existence check result"
+ "description": "Number existence check result",
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/NumberCheckResponseDto"
+ }
+ }
+ }
}
},
"summary": "Check if a phone number exists on WhatsApp",
@@ -3764,7 +3809,14 @@
],
"responses": {
"200": {
- "description": "Profile picture URL"
+ "description": "Profile picture URL",
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/ProfilePictureResponseDto"
+ }
+ }
+ }
}
},
"summary": "Get profile picture URL for a contact",
@@ -3798,7 +3850,14 @@
],
"responses": {
"200": {
- "description": "Resolved phone number (MSISDN digits), or null when the engine cannot map it"
+ "description": "Resolved phone number (MSISDN digits), or null when the engine cannot map it",
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/ResolvedPhoneResponseDto"
+ }
+ }
+ }
}
},
"summary": "Resolve a contact id (e.g. an @lid) to a phone number — best-effort",
@@ -3832,7 +3891,14 @@
],
"responses": {
"200": {
- "description": "Contact blocked"
+ "description": "Contact blocked",
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/ContactAckResponseDto"
+ }
+ }
+ }
}
},
"summary": "Block a contact",
@@ -3864,7 +3930,14 @@
],
"responses": {
"200": {
- "description": "Contact unblocked"
+ "description": "Contact unblocked",
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/ContactAckResponseDto"
+ }
+ }
+ }
}
},
"summary": "Unblock a contact",
@@ -9261,6 +9334,131 @@
}
}
},
+ "ContactDto": {
+ "type": "object",
+ "properties": {
+ "id": {
+ "type": "string",
+ "description": "Contact id in the active engine's native format. On Baileys this is frequently an `@lid` rather than a phone-number JID; use GET /contacts/{contactId}/phone to resolve one.",
+ "example": "[email protected]"
+ },
+ "name": {
+ "type": "string",
+ "description": "The name from the account's own addressbook. Absent for a contact that was never saved.",
+ "example": "Ada Lovelace"
+ },
+ "pushName": {
+ "type": "string",
+ "description": "The display name the contact set for themselves. Present even when the contact is not saved.",
+ "example": "Ada"
+ },
+ "number": {
+ "type": "string",
+ "description": "MSISDN digits, without a leading + or any separators.",
+ "example": "628123456789"
+ },
+ "isMyContact": {
+ "type": "boolean",
+ "description": "Whether the entry exists in the account's addressbook.",
+ "example": true
+ },
+ "isBlocked": {
+ "type": "boolean",
+ "description": "Whether this account has blocked the contact.",
+ "example": false
+ },
+ "profilePicUrl": {
+ "type": "string",
+ "description": "Profile picture URL. Absent when the contact has none or their privacy settings hide it.",
+ "example": "https://pps.whatsapp.net/v/t61.24694-24/12345_678_910_n.jpg"
+ }
+ },
+ "required": [
+ "id",
+ "number",
+ "isMyContact",
+ "isBlocked"
+ ]
+ },
+ "ProfilePicturesResponseDto": {
+ "type": "object",
+ "properties": {
+ "pictures": {
+ "type": "object",
+ "description": "Map of the requested contact ids to their picture URL. An id resolves to null when the contact has no picture, hides it, or its individual lookup failed — a per-id failure does not fail the batch. Ids beyond the first 50 are not looked up and are absent from the map.",
+ "example": {
+ "[email protected]": "https://pps.whatsapp.net/v/t61.24694-24/12345_678_910_n.jpg"
+ },
+ "additionalProperties": {
+ "type": "string",
+ "nullable": true
+ }
+ }
+ },
+ "required": [
+ "pictures"
+ ]
+ },
+ "NumberCheckResponseDto": {
+ "type": "object",
+ "properties": {
+ "number": {
+ "type": "string",
+ "description": "The number exactly as supplied in the path.",
+ "example": "628123456789"
+ },
+ "exists": {
+ "type": "boolean",
+ "description": "Whether the number is a registered WhatsApp account.",
+ "example": true
+ },
+ "whatsappId": {
+ "type": "string",
+ "nullable": true,
+ "description": "The canonical chat id in the engine's native format, or null when the number is not registered.",
+ "example": "[email protected]"
+ }
+ },
+ "required": [
+ "number",
+ "exists",
+ "whatsappId"
+ ]
+ },
+ "ProfilePictureResponseDto": {
+ "type": "object",
+ "properties": {
+ "url": {
+ "type": "string",
+ "nullable": true,
+ "description": "Profile picture URL, or null when the contact has none or their privacy settings hide it.",
+ "example": "https://pps.whatsapp.net/v/t61.24694-24/12345_678_910_n.jpg"
+ }
+ },
+ "required": [
+ "url"
+ ]
+ },
+ "ResolvedPhoneResponseDto": {
+ "type": "object",
+ "properties": {
+ "contactId": {
+ "type": "string",
+ "description": "The contact id exactly as supplied in the path.",
+ "example": "12345678901234@lid"
+ },
+ "phone": {
+ "type": "string",
+ "nullable": true,
+ "description": "MSISDN digits for the contact, or null when the engine has not learned the mapping. Best-effort: a null here is not a statement that the contact has no number.",
+ "example": "628123456789"
+ }
+ },
+ "required": [
+ "contactId",
+ "phone"
+ ]
+ },
"UpsertContactDto": {
"type": "object",
"properties": {
@@ -9279,6 +9477,25 @@
"firstName"
]
},
+ "ContactAckResponseDto": {
+ "type": "object",
+ "properties": {
+ "success": {
+ "type": "boolean",
+ "description": "Always true — a failure is reported as a non-2xx status, not as false.",
+ "example": true
+ },
+ "message": {
+ "type": "string",
+ "description": "Human-readable confirmation of what was done.",
+ "example": "Contact saved"
+ }
+ },
+ "required": [
+ "success",
+ "message"
+ ]
+ },
"JoinGroupDto": {
"type": "object",
"properties": {
diff --git a/src/modules/contact/contact.controller.ts b/src/modules/contact/contact.controller.ts
index 00ac1f90a..09d408215 100644
--- a/src/modules/contact/contact.controller.ts
+++ b/src/modules/contact/contact.controller.ts
@@ -4,6 +4,14 @@ import { ContactService } from './contact.service';
import { RequireRole } from '../auth/decorators/auth.decorators';
import { ApiKeyRole } from '../auth/entities/api-key.entity';
import { UpsertContactDto } from './dto/upsert-contact.dto';
+import {
+ ContactAckResponseDto,
+ ContactDto,
+ NumberCheckResponseDto,
+ ProfilePictureResponseDto,
+ ProfilePicturesResponseDto,
+ ResolvedPhoneResponseDto,
+} from './dto/contact-response.dto';
@ApiTags('contacts')
@Controller('sessions/:sessionId/contacts')
@@ -15,7 +23,8 @@ export class ContactController {
@ApiParam({ name: 'sessionId', description: 'Session ID' })
@ApiResponse({
status: 200,
- description: 'List of contacts',
+ description: 'List of contacts, windowed by limit/offset. A bare array — there is no envelope.',
+ type: [ContactDto],
})
@ApiResponse({ status: 400, description: 'Session not ready' })
@ApiResponse({ status: 404, description: 'Session not found' })
@@ -41,6 +50,7 @@ export class ContactController {
})
@ApiParam({ name: 'sessionId', description: 'Session ID' })
@ApiQuery({ name: 'ids', required: true, description: 'Comma-separated contact ids (max 50 used)' })
+ @ApiResponse({ status: 200, description: 'Picture URL per requested id', type: ProfilePicturesResponseDto })
// NOTE: declared BEFORE @Get(':contactId') so the literal segment wins over the param route.
async getProfilePictures(@Param('sessionId') sessionId: string, @Query('ids') ids?: string) {
const list = (ids ?? '')
@@ -58,6 +68,7 @@ export class ContactController {
@ApiResponse({
status: 200,
description: 'Contact details',
+ type: ContactDto,
})
@ApiResponse({ status: 404, description: 'Contact not found' })
async findOne(@Param('sessionId') sessionId: string, @Param('contactId') contactId: string) {
@@ -78,6 +89,7 @@ export class ContactController {
@ApiResponse({
status: 200,
description: 'Number existence check result',
+ type: NumberCheckResponseDto,
})
async checkNumber(@Param('sessionId') sessionId: string, @Param('number') number: string) {
// The engine returns the canonical chat id in its native format; we don't build the JID here
@@ -99,6 +111,7 @@ export class ContactController {
@ApiResponse({
status: 200,
description: 'Profile picture URL',
+ type: ProfilePictureResponseDto,
})
async getProfilePicture(@Param('sessionId') sessionId: string, @Param('contactId') contactId: string) {
const url = await this.contactService.getProfilePicture(sessionId, contactId);
@@ -112,6 +125,7 @@ export class ContactController {
@ApiResponse({
status: 200,
description: 'Resolved phone number (MSISDN digits), or null when the engine cannot map it',
+ type: ResolvedPhoneResponseDto,
})
async resolvePhone(@Param('sessionId') sessionId: string, @Param('contactId') contactId: string) {
const phone = await this.contactService.resolveContactPhone(sessionId, contactId);
@@ -124,7 +138,7 @@ export class ContactController {
@ApiOperation({ summary: "Save a contact to the account's addressbook, or edit an existing entry" })
@ApiParam({ name: 'sessionId', description: 'Session ID' })
@ApiParam({ name: 'contactId', description: 'Contact ID (e.g., [email protected])' })
- @ApiResponse({ status: 200, description: 'Contact saved' })
+ @ApiResponse({ status: 200, description: 'Contact saved', type: ContactAckResponseDto })
@ApiResponse({ status: 400, description: 'Session not active or invalid request' })
async upsertContact(
@Param('sessionId') sessionId: string,
@@ -142,7 +156,7 @@ export class ContactController {
@ApiOperation({ summary: "Remove a contact from the account's addressbook" })
@ApiParam({ name: 'sessionId', description: 'Session ID' })
@ApiParam({ name: 'contactId', description: 'Contact ID (e.g., [email protected])' })
- @ApiResponse({ status: 200, description: 'Contact deleted' })
+ @ApiResponse({ status: 200, description: 'Contact deleted', type: ContactAckResponseDto })
@ApiResponse({ status: 400, description: 'Session not active' })
async deleteContact(@Param('sessionId') sessionId: string, @Param('contactId') contactId: string) {
await this.contactService.deleteContact(sessionId, contactId);
@@ -158,6 +172,7 @@ export class ContactController {
@ApiResponse({
status: 200,
description: 'Contact blocked',
+ type: ContactAckResponseDto,
})
async blockContact(@Param('sessionId') sessionId: string, @Param('contactId') contactId: string) {
await this.contactService.blockContact(sessionId, contactId);
@@ -172,6 +187,7 @@ export class ContactController {
@ApiResponse({
status: 200,
description: 'Contact unblocked',
+ type: ContactAckResponseDto,
})
async unblockContact(@Param('sessionId') sessionId: string, @Param('contactId') contactId: string) {
await this.contactService.unblockContact(sessionId, contactId);
diff --git a/src/modules/contact/dto/contact-response.dto.ts b/src/modules/contact/dto/contact-response.dto.ts
new file mode 100644
index 000000000..1240c2409
--- /dev/null
+++ b/src/modules/contact/dto/contact-response.dto.ts
@@ -0,0 +1,104 @@
+import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
+
+/**
+ * Response shapes for the contacts routes. These describe what the handlers already return —
+ * the payload is the raw handler value, not an envelope — so that a change to the shape shows up
+ * as a diff in the committed OpenAPI snapshot instead of reaching clients unannounced.
+ */
+export class ContactDto {
+ @ApiProperty({
+ description:
+ "Contact id in the active engine's native format. On Baileys this is frequently an `@lid` " +
+ 'rather than a phone-number JID; use GET /contacts/{contactId}/phone to resolve one.',
+ example: '[email protected]',
+ })
+ id!: string;
+
+ @ApiPropertyOptional({
+ description: "The name from the account's own addressbook. Absent for a contact that was never saved.",
+ example: 'Ada Lovelace',
+ })
+ name?: string;
+
+ @ApiPropertyOptional({
+ description: 'The display name the contact set for themselves. Present even when the contact is not saved.',
+ example: 'Ada',
+ })
+ pushName?: string;
+
+ @ApiProperty({ description: 'MSISDN digits, without a leading + or any separators.', example: '628123456789' })
+ number!: string;
+
+ @ApiProperty({ description: "Whether the entry exists in the account's addressbook.", example: true })
+ isMyContact!: boolean;
+
+ @ApiProperty({ description: 'Whether this account has blocked the contact.', example: false })
+ isBlocked!: boolean;
+
+ @ApiPropertyOptional({
+ description: 'Profile picture URL. Absent when the contact has none or their privacy settings hide it.',
+ example: 'https://pps.whatsapp.net/v/t61.24694-24/12345_678_910_n.jpg',
+ })
+ profilePicUrl?: string;
+}
+
+export class ProfilePictureResponseDto {
+ @ApiProperty({
+ type: String,
+ nullable: true,
+ description: 'Profile picture URL, or null when the contact has none or their privacy settings hide it.',
+ example: 'https://pps.whatsapp.net/v/t61.24694-24/12345_678_910_n.jpg',
+ })
+ url!: string | null;
+}
+
+export class ProfilePicturesResponseDto {
+ @ApiProperty({
+ description:
+ 'Map of the requested contact ids to their picture URL. An id resolves to null when the ' +
+ 'contact has no picture, hides it, or its individual lookup failed — a per-id failure does ' +
+ 'not fail the batch. Ids beyond the first 50 are not looked up and are absent from the map.',
+ example: { '[email protected]': 'https://pps.whatsapp.net/v/t61.24694-24/12345_678_910_n.jpg' },
+ additionalProperties: { type: 'string', nullable: true },
+ })
+ pictures!: Record<string, string | null>;
+}
+
+export class NumberCheckResponseDto {
+ @ApiProperty({ description: 'The number exactly as supplied in the path.', example: '628123456789' })
+ number!: string;
+
+ @ApiProperty({ description: 'Whether the number is a registered WhatsApp account.', example: true })
+ exists!: boolean;
+
+ @ApiProperty({
+ type: String,
+ nullable: true,
+ description: "The canonical chat id in the engine's native format, or null when the number is not registered.",
+ example: '[email protected]',
+ })
+ whatsappId!: string | null;
+}
+
+export class ResolvedPhoneResponseDto {
+ @ApiProperty({ description: 'The contact id exactly as supplied in the path.', example: '12345678901234@lid' })
+ contactId!: string;
+
+ @ApiProperty({
+ type: String,
+ nullable: true,
+ description:
+ 'MSISDN digits for the contact, or null when the engine has not learned the mapping. ' +
+ 'Best-effort: a null here is not a statement that the contact has no number.',
+ example: '628123456789',
+ })
+ phone!: string | null;
+}
+
+export class ContactAckResponseDto {
+ @ApiProperty({ description: 'Always true — a failure is reported as a non-2xx status, not as false.', example: true })
+ success!: boolean;
+
+ @ApiProperty({ description: 'Human-readable confirmation of what was done.', example: 'Contact saved' })
+ message!: string;
+}