anthergic home

library · #01 · operations

One human, four companies: the inbound radar that never sleeps.

We run four companies with one human and a team of AI agents. Leads arrive on SMS, WhatsApp, email, Facebook and Instagram DMs, comments, live chat, calls, forms and bookings, spread across four CRM accounts. Nobody can watch that many inboxes. So a script does, every 10 minutes, and an AI agent answers most of it.

This is the full build, exactly as it runs for us. Read all of it free. If you want our files (the radar script, the reply playbook, the alert templates), they're at the bottom.

In this build

  1. 01What it does
  2. 02Architecture
  3. 03The 10-minute scan
  4. 04Dedupe and state
  5. 05Filters: spam, opt-outs, robots
  6. 06One line per person
  7. 07SLA re-alerts
  8. 08Quiet hours
  9. 09Alert channels
  10. 10The AI reply playbook
  11. 11Running it on a schedule
  12. 12What it costs
  13. 13What broke, and the fixes
  14. 14Get the files

01

What it does

Every 10 minutes the radar asks each CRM account one question: what came in since I last looked? It reads new inbound messages on every channel, new form and survey submissions, new bookings for the next 30 days and new deals. Then it:

  • throws out what a human shouldn't see: our own outbound messages, one-time codes, auto-replies and bounces, obvious spam, and our own test contacts;
  • logs opt-outs (STOP, unsubscribe, remove me) instead of paging anyone;
  • merges everything about one person into one line;
  • sends one digest: Telegram with links, a short SMS, and a card on our task board;
  • starts a timer on every conversation where the lead spoke last, and re-alerts if nobody has answered in 15 minutes.

An AI agent works the cards. It reads the whole conversation, answers on the same channel by a written playbook, and escalates what it shouldn't handle. When a lead agrees a call time, the human's phone rings.

The point: the human never checks an inbox. The inboxes check in with the human, and only when something real happened.

02

Architecture

One Python file, standard library only, run by the operating system's scheduler. No server, no queue, no database. State is a JSON file next to the script.

Inbound radar architecture Four CRM accounts feed the radar every 10 minutes. The radar reads and writes a state file, filters and merges items, then sends to Telegram, SMS and a task board. An AI reply agent works the board, replies in the CRM, and phones the operator when a call time is confirmed. CRM ACCOUNTS Company A Company B Company C Company D RADAR (EVERY 10 MIN) 1. scan since cursor 2. dedupe by id 3. filter spam / opt-outs 4. merge per person 5. SLA timers 6. one digest state.json Telegram (links) SMS (no links) Task board card AI reply agentreads reply-playbook.md Phone call to human agent replies in the CRM, same channel Only the scan and the SMS send talk to the CRM. Everything else is plain Python and JSON.
The radar only reads. Replies come from the agent (or a human) inside the CRM, which the radar then sees on its next run and uses to stop timers and close cards.

Our CRM is GoHighLevel, one sub-account per company, each with its own API token. Nothing in the design depends on that: only four scan functions and the SMS send talk to the CRM.

03

The 10-minute scan

Per account, every run:

WhatHow
MessagesList conversations sorted by last message date, newest first, 100 per page, and stop at the first one older than the cursor (at most 10 pages). For each changed conversation, read its last 30 messages and keep the new inbound ones.
ChannelsSMS, WhatsApp, email, Facebook and Instagram DMs, Facebook and Instagram comments, live chat, Google chat, TikTok DMs, and calls (shown as "inbound call (status)").
FormsThe latest 50 form submissions and 50 survey submissions, with the form's name in the alert.
BookingsEvery calendar's events from 1 hour ago to 30 days ahead. Cancelled and invalid ones are skipped. The alert shows the time in the operator's time zone.
DealsThe 50 newest opportunities.

Timeline rows that aren't messages (activity, status changes, campaign events, internal notes) are dropped by message type before anything else happens.

04

Dedupe and state

A radar that double-alerts gets muted within a day. So state matters more than anything else in the file.

  • Cursor per account. The newest "last message" time seen. The next run reads from the cursor minus 3 minutes, so a message that lands mid-run is never missed.
  • Seen ids. The overlap would cause repeats, so every message, form, booking and deal id is remembered (the last 3,000 messages and 1,000 of each other kind). An id alerts once, ever.
  • Seed run. The first run on a new account reads the last 7 days, marks all of it seen, and alerts nothing. Without it, connecting an account floods you with a week of history.
  • Failure is safe. Before scanning an account the script copies its state. If the CRM API errors, the copy is restored and that account is retried next run. Nothing is skipped and nothing half-saved. Other accounts carry on.
  • Atomic writes. State is written to a temp file and swapped in, so a crash never leaves broken JSON.

05

Filters: spam, opt-outs and robots

Each new inbound message goes through four checks, in this order:

  1. Internal contact? Ignore. Your own alert contact, test contacts and team are listed by id or tag in the config.
  2. Opt-out? A message that is only "stop", "unsubscribe", "remove me", "opt out", "take me off…" and the like is written to optouts.log and never pages anyone. Whole-message match only, so "can you stop by Tuesday?" still alerts.
  3. System message? Verification and one-time codes, out-of-office and auto-replies, bounce notices, "this inbox is not monitored", "we received your message", "reply STOP to…". Logged to ignored.log.
  4. Spam? SEO and web-design pitches, guest posts and backlinks, crypto and forex, follower sellers, prize and gift-card bait, link shorteners. Logged to ignored.log.

Everything ignored is logged, not deleted. Once a week, skim ignored.log for anything real that got caught and loosen the pattern.

Message text is cleaned too: HTML stripped, quoted email history ("On … wrote:") cut off, then shortened to 160 characters for the alert.

06

One line per person

A lead who fills a form, books and sends a text would be three alerts. The radar merges them into one line per person per account, ranked booking > form > message > deal, with any message text appended:

[Company A] Jane Doe (Acme) via Booking: booked Fri Nov 21 03:00 PM - Intro call | SMS: running 5 min late

Several new messages in one conversation show the latest one plus "(+2 more)". A deal on its own is dropped if the same person was alerted in the last hour, because a new deal almost always follows a message you've just seen.

07

SLA re-alerts

The alert that matters most is the second one: this person is still waiting.

  • When the latest message in a conversation is from the lead, on a channel someone can answer (SMS, WhatsApp, email, DMs, chat), a timer starts.
  • After 15 minutes with no reply: REMINDER 1/2 … no reply for 17 min. Another 15 minutes later: 2/2. Then it stops. Two reminders is the cap, because a third gets ignored anyway.
  • Any outbound message stops the timer, whether it came from a person, the AI agent or an automation. When a person replies, the board card moves to done by itself.
  • Timers older than 2 days are dropped. Seeding clears all timers, so the radar never chases old conversations.

08

Quiet hours (two kinds)

Yours. New messages, bookings and form fills alert at any hour. A lead at 2 a.m. is still a lead. Reminders only go out in working hours (we use 08:00 to 23:00 in the operator's time zone), so nobody gets nagged overnight about a conversation that can wait.

Theirs. The AI agent only sends replies between 08:00 and 21:00 in the lead's local time. Outside that window it queues the reply for 08:00 their time and notes it on the card. Replying instantly at 3 a.m. their time looks like a robot, and in some places it breaks texting rules.

09

Alert channels

At most one message per channel per run, however much came in.

ChannelRole
TelegramThe main channel. Free, no length limit, so it gets the full list with a direct link to each conversation. You create the bot with @BotFather.
SMSThe backup that reaches you anywhere. Sent through the CRM to a contact for your own phone (tagged internal, email turned off). Up to 5 lines, then "+N more on the board". No links (see the lessons below).
Phone callRare on purpose: only when a lead has confirmed a call time. A short spoken message read twice, via Twilio. If it rang for everything, you'd stop answering.
Task boardOne card per conversation, titled "Reply - [Company] Name via Channel", high priority, notes newest first. New activity reopens it; a reply closes it. This is the AI agent's work queue.
WhatsAppBuilt, then switched off. Business-started WhatsApp messages need a pre-approved template and are charged per message, and Telegram does the same job free.

The exact message shapes are in alert-templates.txt in the files.

10

The AI reply playbook

The radar finds messages. An AI agent answers them. The agent works from a written playbook that says what a reply is for, how to send it, and where to stop. The template is in the files. These are the parts that matter:

Every reply has one job

Move the person one step toward the outcome you want (for us, a call with the human). Shape: their pain, the essence of the answer, one call to action. One question per text. Written in the sender's voice, short, and about their result.

Before sending

  • Read the whole conversation and the contact's notes. Check nobody already answered. Never send twice.
  • Reply on the same channel, from that company's own number or inbox. Never cross companies.
  • Respect the lead's quiet hours. After sending, add a note to the contact, close the card, and send the human a one-line FYI: "they said … / I replied …".

Calls

  • Any time the agent offers or accepts is at least 2 hours out (1 hour if the lead insists), and inside both parties' calling hours.
  • On a confirmed time: confirm it in the lead's time zone, phone the human, add a card, and set reminders for 1 hour and about 8 minutes before.
  • No calendar bookings unless the human asks. Bookings send their own confirmations and invites.
  • "Call me now": no promises in minutes. "Can I call you in about an hour?" Then ping the human.

Stop and ask (escalation)

The agent leaves the card waiting and messages the human when it sees anger or a complaint, a legal threat, a refund or billing question, a paying client's account issue, a negotiation or discount request, a second push on price, anything personal, or anything it is unsure of. And it never makes anything up: no invented results, testimonials or features.

Never

Message anyone who opted out or is on the do-not-contact list. Text people who never gave consent. Make a send that charges the lead, or promise refunds.

Some threads keep their own approval step and aren't in the agent's scope: our cold-email reply handler, and any account we don't own.

11

Running it on a schedule

We run it from Windows Task Scheduler every 10 minutes with pythonw.exe, so no console window pops up, and --log sends output to a log file that rotates at 2 MB.

schtasks /Create /TN "Inbound Radar" /SC MINUTE /MO 10 ^
  /TR "\"C:\Path\To\pythonw.exe\" \"C:\radar\radar.py\" --log"

On macOS or Linux, cron:

*/10 * * * * cd ~/radar && /usr/bin/python3 radar.py --log
  • --dry prints the alerts and board changes it would make, and saves nothing. Use it after every change.
  • --test "text" sends through Telegram and SMS; --call "text" rings your phone.
  • Pause without touching the scheduler: create an empty file called PAUSE_RADAR next to the script. Delete it to resume.

Why 10 minutes? A lead who hears back in 10 minutes still feels answered. Running it more often mostly means more API calls for the same alerts.

12

What it costs

PartCost
HostingNothing extra. It runs on a computer that's already on. Standard-library Python, no packages.
CRM APIRead calls that come with your CRM plan. Check your CRM's rate limits if you have many accounts.
TelegramFree.
SMS alertsYour provider's normal per-message rate, and at most one per run. It's off by default in the template.
Phone callsTwilio's per-minute rate. A call is a few seconds and only happens on confirmed call times.
WhatsAppCharged per business-started message. That's why we turned it off.
AI agentWhatever your AI subscription costs. The radar itself uses no AI.

13

What broke, and the fixes

  • SMS with links didn't arrive. Alerts carrying long CRM links showed "delivered" in the CRM but never reached the phone. A link-free test arrived. Carriers filter link-heavy texts, so the SMS is now link-free and Telegram carries the links.
  • The API refused requests with no User-Agent. The CRM's edge proxy rejected bare Python requests. Every request now sends a User-Agent header.
  • First run floods. Hence the seed run: connect an account, and the first pass only records history.
  • Alert spam from one person. Form, booking and text from the same lead in one run used to be three alerts. Now it's one merged line, and deals that follow a message are suppressed.
  • A flaky API means a lost message. Hence the state copy and restore per account. An error delays an alert by 10 minutes; it never loses one.

14 · the files

Get the files

Our radar script (with every token, ID and company name taken out), the reply playbook template, the alert templates, a config example and a README with setup and scheduling.

You'll join the Anthergic list: one short email when a new build goes up. Unsubscribe anytime.

Want this built for you?

We build systems like this inside companies: in your stack, on your data, and we stay until it runs. Tell us which inbound is slipping through.

Email us [email protected]

← Back to the library