03IntegrationsType: Reference architecture
SMS and chat inside the CRM, with one record per message and no blind resends
A reference design for a Zoho CRM extension built for many orgs: one record per provider message, and a person for any unclear send.
Shows
- Software Architecture
- Enterprise Integrations
- API Design
Where this comes from: Drawn from systems I've designed on Zoho. The business, names and data here are generalized. The patterns and failure modes come from real work, and the design includes what that work taught me.
On This Page
In 30 Seconds
A Zoho CRM extension lets staff text and chat with customers from the record, a shared inbox or a bulk send, through a messaging provider. Each company that installs it keeps its own settings, data center and provider account. Every message, in or out, becomes one CRM record keyed by the provider's message id. A send with an unclear outcome waits for a person.
What It Guarantees
- A repeated event is refused, and a twin that slips past is found by a scheduled check.
- A send with an unknown outcome is never repeated on its own.
- Every bulk recipient ends in a named bucket: sent, skipped with a reason, failed, or not confirmed.
- A message that can't be recorded yet is retried, then swept up; a permanent failure is named, never dropped quietly.
The Problem
Picture a services company whose teams work in Zoho CRM, while customer texts go out from a provider portal and personal phones. The record shows none of it.
Moving messaging into the CRM sounds like one API call. It isn't. Provider events arrive late, twice or out of order. A message sent in bulk may not be readable by its id for a while. A send can time out, leaving nobody sure the customer got it. Phone numbers sit in local formats the provider can't deliver to. Some business chat channels accept only pre-approved templates once a 24-hour reply window closes. As a marketplace extension, the same code has to run in many orgs and data centers, each with its own provider account.
The Approach, in One Sentence
Sending and recording are separate steps, joined by the provider's message id; one import, safe to rerun, writes one CRM record per id.
Architecture
Connections in this diagram
- Record and inbox → Send guard (send)
- Bulk send → Send guard (batches)
- Provider events → Import by message id (message id)
- Send guard → Messaging provider (valid)
- Messaging provider → Import by message id (message ids)
- Messaging provider → Not confirmed (no answer)
- Import by message id → Pending import (not found yet)
- Import by message id → One message record (new id)
- Pending import → One message record (retry)
Key Decisions
Record by the provider's message id, apart from sending
The alternatives were writing the record from the browser, which can close mid-batch, or from the thin webhook payload, which can repeat. One import that reads each message fresh by id, and lets the CRM refuse a known id, can run any number of times. "Sent, not yet recorded" becomes a visible state.
An unknown outcome is "Not confirmed", never "Failed"
The alternatives were automatic retries, or Failed with a Retry button. Without a key the provider can use to drop repeats, both can text a customer twice. The thread reloads to look for the message, and the agent chooses Send again or Discard. "Not sent" appears only when that is certain.
Each install stands alone, and the shared backend knows as little as possible
The alternative was a central service holding every org's credentials. Screens act as the signed-in user through Zoho's embedded SDK. Provider credentials are used only server-side. When I last designed for it, screens could read the extension's settings, so the key is kept where screens can't reach it; that may have changed. Per org, the backend keeps the org id, its Zoho API domain (data center) and an encrypted key that can call one retry function.
Check the whole audience before the first message goes out
The alternative was letting the provider reject bad numbers one by one. A preflight converts every number to E.164 (plus sign, country code, number), drops duplicates, flags missing template fields and names each skip's reason. A size cap stops an accidental "all records".
When Things Go Wrong
An event arrives twice
The message id sits in a unique field, and imports for one org run one at a time, so a repeat finds the first record saved and is refused. Not a search: when I last designed for it, Zoho's search could trail a fresh write by seconds or longer and miss a twin. Nor a unique field alone: in my tests, it let truly parallel writes through. Both may have changed. A scheduled check finds any twin that gets past, so the later record can be removed.
The provider hasn't caught up
Right after a bulk send, a message read by id can come back "not found". Its id becomes a pending import, retried after growing delays; a scheduled CRM sweep picks up the rest.
A batch fails halfway
Batches settle one by one, and each recipient lands in one bucket: sent, skipped, failed or not confirmed. Pressing Send again skips recipients already sent and leaves Not confirmed ones to a person.
A number is stored in a local format
The provider can't deliver to it, and a reply opens a second conversation. One normalization rule runs before sending, in the conversation key and when matching inbound senders; what it can't normalize is refused with a reason.
What the Business Gets
- Every message sits on its contact or lead, one thread per number and channel.
- Staff message from the record, a shared inbox or a list view, with no second tool.
- A bulk send ends with a summary naming every skipped or failed recipient, and why.
For Engineers
Data model. Message: provider message id (unique), conversation key, channel, direction, status, latest flag, owner, contact or lead. Conversation key: sender account + channel + E.164 number. Bulk send: audience snapshot and each recipient's bucket. Pending import: org, ids, attempt, due time, state, last error.
Inbound and imports. Events, bulk imports and retries share one import, which runs one job per org at a time and claims the message id before it looks up the person. A single send records its message in the same call, under the same id; if that fails, the id joins the pending imports.
Outcomes and retries. Imported, already imported, pending, provider unavailable, provider failed, CRM create failed. Pending ids, outages, throttling and timeouts retry after growing delays, then wait for the sweep; the unique id makes a retry safe. A reported failure, or a create rejected on its data, is named in the job's result and bulk summary, never retried blindly. An all-zero or unreadable response fails the job loudly. A scheduled check lists ids on two records, and messages with no person.
import(org, ids): # one job per org at a time
for id in unique(ids):
msg = provider.get(id) # fresh read, not the payload
if msg.not_found or msg.unavailable: note(id, pending); continue
num = e164(msg.number) or skip(id, "number")
key = (msg.sender_account, msg.channel, num)
try: rec = crm.create_message(id, key) # unique on id: a repeat stops here
except Duplicate: note(id, already_imported); continue
who = person_on(key) or match_contact(num) or match_lead(num) or create_lead(num)
crm.link(rec, who) # by query, not the search index
retry_later(org, noted(pending)) # backoff, then the sweep
A limit to know. An event the provider never delivers is invisible to all of this. A periodic pull of recent messages per sender account, through the same import, closes that gap.
How I Build Systems Like This
Before changing an extension, I write down how it behaves today and list findings, each with a severity and the file and line behind it. AI agents (Claude Code) now do much of my hands-on research, code and tests. Analysis is read-only, a second read-only review checks the work before it ships, and done means the full test suite and a live test on a real org both pass.