Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(db): parse JSON columns on Postgres to prevent dashboard crash (#384)
Yudhi Armyndharis9529dc6082a5
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 5217e9cc2..f3cf4795a 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0## [Unreleased]+### Fixed++- **Dashboard no longer crashes ("Something went wrong") when a webhook exists on PostgreSQL.** JSON+ columns (`webhooks.events`/`headers`, `sessions.config`, `messages.metadata`, `message_batches.*`)+ were declared `jsonb` in their entities but created as `text` by the baseline migration, so on+ Postgres the driver returned them as raw JSON strings and the dashboard's `events.map()` threw an+ uncaught error. `jsonColumnType()` now resolves to `simple-json` on both dialects (parsed in JS on+ read) — no schema migration or data conversion, since the write format was already identical. This+ also corrects the same latent string-instead-of-object behavior for session reconnect config,+ message-reaction persistence, and bulk-send batches on Postgres. The dashboard additionally+ normalizes webhook `events` to an array at the query boundary as defense-in-depth. (#385)+## [0.4.6] - 2026-06-20A reliability, correctness, and dashboard release. **Identity & engine:** Baileys gains a persistent,diff --git a/dashboard/src/hooks/queries.ts b/dashboard/src/hooks/queries.tsindex 5b644aa4a..205fd859d 100644--- a/dashboard/src/hooks/queries.ts+++ b/dashboard/src/hooks/queries.ts@@ -72,6 +72,10 @@ export function useWebhooksQuery() {queryKey: queryKeys.webhooks,queryFn: webhookApi.listAll,staleTime: 30_000,+ // Normalize `events` to an array at the data boundary so every consumer (list render + edit+ // modal) can trust the declared string[] shape. A malformed payload then renders as no tags+ // instead of taking down the whole SPA via events.map() in the ErrorBoundary.+ select: webhooks => webhooks.map(w => ({ ...w, events: Array.isArray(w.events) ? w.events : [] })),});}diff --git a/src/common/utils/column-types.spec.ts b/src/common/utils/column-types.spec.tsindex 366a759ce..6d1ed7e1f 100644--- a/src/common/utils/column-types.spec.ts+++ b/src/common/utils/column-types.spec.ts@@ -12,7 +12,12 @@ describe('cross-DB column type helpers (data connection dialect)', () => {it('resolves Postgres types when DATABASE_TYPE=postgres', () => {process.env.DATABASE_TYPE = 'postgres';- expect(jsonColumnType()).toBe('jsonb');+ // JSON columns are 'simple-json' on BOTH dialects: the baseline migration created these as+ // `text`, and the pg driver returns a `text` column as a raw (unparsed) string. A 'jsonb'-typed+ // entity reading a text column hands back that string, so e.g. webhook.events arrives as+ // '["message.received"]' and the dashboard's events.map() throws. 'simple-json' JSON-parses on+ // read regardless of dialect, matching the actual text columns. Dates still differ by dialect.+ expect(jsonColumnType()).toBe('simple-json');expect(dateColumnType()).toBe('timestamp');});diff --git a/src/common/utils/column-types.ts b/src/common/utils/column-types.tsindex 42b2d62bd..08ebdc691 100644--- a/src/common/utils/column-types.ts+++ b/src/common/utils/column-types.ts@@ -18,9 +18,16 @@const isPostgres = (): boolean => process.env.DATABASE_TYPE === 'postgres';/**- * Returns 'jsonb' for PostgreSQL, 'simple-json' for SQLite.+ * Always 'simple-json' (TypeORM JSON.stringify/parse over a `text` column), on BOTH dialects.+ *+ * The baseline migration created these columns as `text` on Postgres too (never `jsonb`). The pg+ * driver only auto-parses real json/jsonb columns, so a `jsonb`-typed entity reading the actual+ * `text` column hands back a RAW string — e.g. webhook.events comes through as the string+ * '["message.received"]', and the dashboard's events.map() throws (full-page crash). 'simple-json'+ * parses on read regardless of dialect, matching the real columns. No native jsonb queries exist+ * (all JSON filtering is done in JS), so nothing is lost.*/-export const jsonColumnType = (): 'jsonb' | 'simple-json' => (isPostgres() ? 'jsonb' : 'simple-json');+export const jsonColumnType = (): 'simple-json' => 'simple-json';/*** Returns 'timestamp' for PostgreSQL, 'text' for SQLite.