Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

docs: state why a chat id and a delivery id stop at 255

Yudhi Armyndharis37c83b4b4599
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4862547ea..314c33d3c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -51,8 +51,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- Bound each webhook and ingress queue command at 2 s once Redis has connected, so a Redis that stops answering falls back to direct delivery and inline dispatch instead of holding every dispatch and ingress request.
-- Answer `400` for a send route's, a chat action's or a product send's `chatId`, or a bulk `batchId`, over 255 characters, where PostgreSQL answered `500` once the value passed its index entry limit.
-- Use the body hash as the delivery id of an ingress request whose dedup header is longer than 255 characters, where PostgreSQL answered `500`.
+- Answer `400` for a send route's or a product send's `chatId`, or a bulk `batchId`, over 255 characters, where PostgreSQL answered `500` once the value passed its index entry limit.
+- Answer `400` for a chat action's `chatId` over 255 characters, as the send routes do, instead of handing it to the engine.
+- Use the body hash as the delivery id of an ingress request whose dedup header is longer than 255 characters, where PostgreSQL answered `500` once the value passed its index entry limit.
- MCP tools refuse a `chatId`, `fromChatId` or `toChatId` over 255 characters, as the send routes do, where PostgreSQL answered an internal tool error.
- A start that fails while another start of the same session is in flight leaves the claim to that start, so its engine is no longer left on a row no node holds.
- Uninstalling a plugin hands the chats it had taken over back to the bot, so other plugins are no longer silent there.
diff --git a/src/modules/integration/ingress.service.spec.ts b/src/modules/integration/ingress.service.spec.ts
index 0f8b21ed3..5daf0eef7 100644
--- a/src/modules/integration/ingress.service.spec.ts
+++ b/src/modules/integration/ingress.service.spec.ts
@@ -592,12 +592,12 @@ describe('dedupOn: body (a provider that rotates its delivery id on retry)', ()
expect((d.enqueue.mock.calls[0] as [unknown, string])[1]).toBe('d-1');
});
- it('falls back to the body hash when the dedup header is longer than the delivery id column', async () => {
+ it('falls back to the body hash when the dedup header is longer than 255 characters', async () => {
const d = deps();
await new IngressService(d).handle({ ...req, headers: { 'x-delivery': 'x'.repeat(256) }, rawBody: '{"n":1}' });
const id = (d.enqueue.mock.calls[0] as [unknown, string])[1];
expect(id).toMatch(/^[0-9a-f]{64}$/);
- // The bound is the column's: an id of exactly 255 characters is still the provider's.
+ // The bound is inclusive: an id of exactly 255 characters is still the provider's.
const edge = deps();
await new IngressService(edge).handle({ ...req, headers: { 'x-delivery': 'y'.repeat(255) }, rawBody: '{"n":1}' });
expect((edge.enqueue.mock.calls[0] as [unknown, string])[1]).toBe('y'.repeat(255));
diff --git a/src/modules/integration/ingress.service.ts b/src/modules/integration/ingress.service.ts
index 779f8ce15..124235fff 100644
--- a/src/modules/integration/ingress.service.ts
+++ b/src/modules/integration/ingress.service.ts
@@ -209,8 +209,8 @@ export class IngressService {
// dead-lettered, and the deliveries were simply gone. Fall through to the body hash, which is
// exactly the "provider supplied no id" case it already exists for.
const headerId = req.headers[dedupHeader]?.trim();
- // An id longer than the column holding it is no id the provider could have minted: it is stored under the
- // unique index on PostgreSQL, which refuses a long entry with a 500, so such a header gets the body hash too.
+ // An id past 255 characters is no id a provider mints, and the unique index it is stored under refuses an
+ // entry past about 2.7 KB on PostgreSQL with a 500, so such a header gets the body hash too.
const deliveryId =
route.dedupOn === 'body' || !headerId || headerId.length > MAX_DELIVERY_ID_LENGTH
? deriveDeliveryId(req)
@@ -292,7 +292,7 @@ export class IngressService {
}
}
-/** The longest dedup header value taken as a delivery id; the column and its unique index hold 255 characters. */
+/** The longest dedup header value taken as a delivery id, kept far below the index entry limit of PostgreSQL. */
const MAX_DELIVERY_ID_LENGTH = 255;
/**
diff --git a/src/modules/session/dto/chat-id-bound.dto.spec.ts b/src/modules/session/dto/chat-id-bound.dto.spec.ts
index b853ab83b..b2ba01899 100644
--- a/src/modules/session/dto/chat-id-bound.dto.spec.ts
+++ b/src/modules/session/dto/chat-id-bound.dto.spec.ts
@@ -11,9 +11,10 @@ import { PinChatDto } from './pin-chat.dto';
import { SubscribePresenceDto } from './presence.dto';
import { SendChatStateDto } from './send-chat-state.dto';
-// A chat id is stored in an indexed column; PostgreSQL refuses an index entry past about 2.7 KB, which
-// used to surface as a 500 where SQLite stored the value. The send routes bound it at 255, and so does
-// every other request body that names a chat.
+// The send routes store a chat id in an indexed column, and PostgreSQL refuses an index entry past about
+// 2.7 KB, which used to surface as a 500 where SQLite stored the value. They bound it at 255, and so does
+// every other request body that names a chat, so one limit holds across the API: a product send stores
+// the id like the send routes, and a chat action hands it to the engine.
describe('chatId is bounded at 255 characters on the chat action bodies', () => {
const exact = `${'1'.repeat(250)}@c.us`;
const over = `${'1'.repeat(251)}@c.us`;