Skip to content
Eng. Apdow
Open to work
CVLet's Talk
·8 min read

Designing a unified inbox across four messaging providers

WhatsApp, Instagram, Messenger and Telegram all model conversations differently. Here is the normalisation layer that made MideSync possible.

ArchitectureRealtimeAI

Every provider thinks it invented messaging. WhatsApp gives you phone-number identities and 24-hour session windows; Instagram hides the username behind a scoped ID; Telegram happily lets bots edit messages; Messenger fires webhooks for things you never asked for.

The conversation model

I normalised everything into three tables: contacts (one human, many channel identities), conversations (a thread bound to a channel identity) and messages (append-only, provider-agnostic).

messages
  id            uuid
  conversation  uuid
  direction     'in' | 'out'
  provider      enum
  provider_ref  text   -- external id, unique per provider
  body          jsonb  -- normalised blocks
  sent_at       timestamptz
  state         'queued' | 'sent' | 'delivered' | 'read' | 'failed'

Idempotency is the whole game

Webhooks retry. Users double-send. A unique index on (provider, provider_ref) plus an upsert means replays are free, and the realtime layer never has to reason about duplicates.

Where AI belongs

Not in the write path. AI triage subscribes to new inbound messages, writes a suggestion row, and a human (or an automation rule) decides. That keeps a bad model response from ever reaching a customer unflagged.

The moment a product claims “one inbox”, the hard part is not the UI. It is agreeing on what a message is.
Share

Keep reading