Case study 03 · Driven Properties · Growth & Innovation Technology
DivaOSAI WhatsApp Virtual Assistant
A WhatsApp assistant for real estate agents that connects an LLM to the company's CRM, listings and calendar.
- Role
- Software Engineer on the team: workflow, integrations and an in-progress re-architecture
- Status
- In production on n8n · TypeScript re-architecture in progress
- Core stack
- n8n
- OpenAI
- Redis
- REST APIs
- Node.js
DivaOS is internal Driven Properties software. There is no public repository or demo; code excerpts are short and generic.
01
Overview
DivaOS lets Driven Properties agents work from WhatsApp: search property listings, manage leads, clients and opportunities in the CRM, book meetings, and pull brochures, floor plans and payment plans, in English or Arabic, by text or voice note.
The production system is an n8n workflow that orchestrates the OpenAI API, Redis and internal REST APIs. A typed TypeScript and Fastify replacement is in progress, migrating one intent at a time behind the live workflow.
02
Business problem
- Agents spend their day on WhatsApp with clients, but updating the CRM, looking up listings and scheduling viewings means switching to other tools.
- Requests are free-form, bilingual and often voice notes. "2 bed in marina under 2M for rent" has to become structured filters that a listings API understands.
- Every action touches real business records, so misrouted intents or duplicate replies have a real cost.
03
Solution
- LLM-based intent routing across eight intents: property search, leads, clients, opportunities, appointments, brochures, market analysis and general chat.
- Structured extraction of search filters such as property type, bedrooms, price, area, location and rent or sale.
- Tool integrations with listings search, CRM records, calendar workflows, document retrieval and market analysis.
- Redis-backed sessions holding language, active context and filters, with per-user locks so a burst of messages from one user is processed in order.
- A voice pipeline (media retrieval, transcription and quality checks) and language detection for English and Arabic replies.
04
My contribution
- Worked on the n8n workflow: LLM intent routing, structured filter extraction, multilingual replies and voice message processing.
- Built the Redis-based session handling with concurrency control.
- Integrated CRM, listings, scheduling and document workflows into the conversation.
- Audited the production workflow, and am building its TypeScript re-architecture: strangler migration, an evaluation harness and infrastructure as code.
DivaOS is a team product. The points above are the parts I personally worked on.
05
Technical architecture
Production workflow (n8n)
7 stages
01
WhatsApp message
Text, voice note or interactive reply via the WhatsApp Cloud API
02
Session & lock
Redis session and a per-user lock
03
Voice & language
Transcription, quality checks, language detection
04
Intent routing
LLM classifies the request into one of eight intents
05
Structured extraction
Filters and entities as structured fields
06
Tool execution
Listings, CRM, calendar, documents, market analysis
07
Reply
Bilingual WhatsApp text, cards, lists and documents
Re-architecture target (in progress)
6 stages
01
Webhook API
Fastify: verify HMAC over raw bytes, persist, enqueue, return fast
02
SQS FIFO
One message group per user for ordering; deduplicates retries
03
Worker
Atomic lease-based claim, then route
04
Router
Deterministic layer, then intent classifier
05
Intent handlers
Per-intent schema, reducer and renderer
06
Legacy forward
Un-migrated intents replayed to n8n
Orchestration
- n8n workflow with code, OpenAI and HTTP nodes
- Intent router and per-intent branches
- Error workflow for failures
Conversation state
- Redis sessions: language, active context, filters, pagination
- Per-user locks for concurrent messages
- Sticky filters so follow-ups like "cheaper" refine the last search
Business integrations
- CRM REST APIs: leads, clients, opportunities
- Listings search and listing details
- Calendar and meeting workflows
- Brochures, floor plans and payment plans
Re-architecture (in progress)
- Fastify API and worker, Zod at every boundary
- PostgreSQL with pgvector for location resolution
- SQS FIFO with a dead-letter queue
- OpenTelemetry, Terraform on AWS (ECS Fargate, Aurora, ElastiCache)
06
Technology stack
- Production
- n8n
- OpenAI API
- Redis
- WhatsApp Cloud API
- REST APIs
- Re-architecture
- Node.js
- TypeScript
- Fastify
- PostgreSQL
- pgvector
- Drizzle
- Zod
- Vitest
- Infrastructure
- AWS SQS FIFO
- ECS Fargate
- Aurora Serverless
- ElastiCache
- Terraform
- OpenTelemetry
07
Key engineering challenges
One prompt doing everything
The workflow had grown a single prompt of roughly 29k tokens covering all eight intents, plus a 68 KB parser repairing its output. The re-architecture splits this into a deterministic layer for greetings, help and reset, an intent classifier, and small per-intent extractors. The audit estimated routing cost could drop from about $700 to about $35 a month at 100 users sending 20 messages a day.
Concurrency and duplicate replies
WhatsApp retries webhooks, batches messages and users send several in a row. In production, the lock was acquired on one sender field and released on another; when the two differed, users were locked out and their messages dropped. The new design gets per-user ordering from SQS FIFO message groups and idempotency from a unique index plus an atomic lease-based claim.
Ambiguous locations
Agents type "marina", "jlt" or "dubai mrina". The new location resolver tries exact match, then trigram similarity, then embeddings, merges them with reciprocal rank fusion, and learns aliases when an agent picks a candidate.
Migrating a live system safely
Agents rely on the assistant daily, so a big-bang rewrite was not an option. The strangler service records and replays every message to n8n, and an intent moves over only once its evaluation scores match the existing baseline.
08
Technical decisions and trade-offs
Why route the intent before extracting details?
A small prompt specific to one intent is more reliable and cheaper than one prompt that classifies, extracts, paginates and converts units all at once. A deterministic first layer answers greetings, help and reset with no model call at all.
Trade-off: More moving parts: each intent needs its own schema, prompt, tests and evaluation cases.
Why SQS FIFO instead of a Redis lock in the new design?
Using the user as the message group gives strict per-user ordering without a distributed lock, built-in deduplication of retries, and a dead-letter queue. The webhook only verifies, persists and enqueues, so slow CRM calls can never delay message intake.
Trade-off: A dependency on AWS and a five-minute deduplication window, which is why a database-level idempotency check sits behind it.
Why build evaluations before changing prompts?
84 golden cases across all eight intents, taken from the existing prompt's own examples plus known gaps, score intent, action and filter extraction. CI fails on any regression against the baseline, so quality is measured before anything that produces answers changes.
Atomic, lease-based message claim
typescriptexport async function claimMessage(
messageId: string,
waId: string,
leaseSeconds: number = env().SQS_VISIBILITY_TIMEOUT_S * 2,
): Promise<boolean> {
const lease = sql`now() + make_interval(secs => ${leaseSeconds})`;
const claimed = await getDb()
.insert(processedMessages)
.values({ messageId, waId, claimExpiresAt: lease })
.onConflictDoUpdate({
target: processedMessages.messageId,
set: {
claimedAt: sql`now()`,
claimExpiresAt: lease,
attempts: sql`${processedMessages.attempts} + 1`,
},
setWhere: sql`${processedMessages.completedAt} IS NULL
AND ${processedMessages.claimExpiresAt} < now()`,
})
.returning({ messageId: processedMessages.messageId });
return claimed.length > 0;
}09
Implemented functionality
- Implemented
LLM-based intent routing
- Implemented
Structured extraction of property search filters
- Implemented
CRM integration for leads, clients and opportunities
- Implemented
Property listing search
- Implemented
Meeting and calendar workflows
- Implemented
Multilingual (English and Arabic) conversations
- Implemented
Voice message processing
- Implemented
Redis-backed session management with per-user locking
- Implemented
Brochure, floor plan and payment plan retrieval
- Implemented
Market analysis workflows
- In progress
Re-architecture: webhook service, SQS FIFO ordering and idempotency (built, not yet deployed)
- In progress
Re-architecture: evaluation harness with 84 golden cases and a CI gate
- In progress
Re-architecture: property search, market analysis and location resolver ported
- Planned
Per-intent extractors with OpenAI Structured Outputs
- Planned
CRM intents ported and n8n decommissioned after a soak period
10
Outcomes and future improvements
Outcomes
- DivaOS is used in production by Driven Properties agents on WhatsApp, connecting an LLM to the CRM, listings, calendar and document workflows.
- The workflow audit turned "the bot is flaky" into specific defects. Each one is now covered by a test in the new service.
Next steps
- Per-intent LLM extractors using OpenAI Structured Outputs, cut over only when they match the evaluation baseline.
- Port the CRM intents, then decommission the n8n workflow after a soak period.
- Sustained load testing at 300 concurrent users.