← All projects
Case study · AI automation · Sales · Telegram

An AI closer that answers my Telegram DMs like I would, and knows when to stay quiet.

Spirex clients ask their questions in Telegram private messages, in Gulf Arabic, at any hour, often as voice notes or screenshots. I built a Python assistant that logs into the Spirex account, waits until the client stops typing, reads the whole chat, and lets Gemini on Vertex AI decide one thing: reply, skip or hand the chat to me. It has been answering real clients since 28 October 2026.
RoleSolo: design, Python, prompts and knowledge, operations
TimelineBuilt and launched in October 2026
Runs onMy MacBook, started by launchd, restarted on crash
Core stackPython, Telethon, Gemini on Vertex AI
The closer's control room in Telegram Saved Messages: a draft reply waiting for approval, a handoff to the owner and the switch to auto mode
The control room is my own Saved Messages chat. Rebuilt from the closer's real message formats and log; client names removed.
242
decisions in its first 6 days
139 · 54 · 49
replies · skips · handoffs
233
follow-ups to quiet leads
147
client chats with memory

Overview.

Why a sales inbox needed judgement, not a chatbot.
The inbox

Traders who ask before they pay

Spirex sells AI trading analysis to Arabic-speaking traders. Before paying they ask about plans, payment by card or USDT, free reads and whether it is a scam, usually in a few short messages, a voice note or a screenshot of a receipt.

The problem

One founder, every time zone

Leads that wait hours go cold. A classic bot answers “ok” and stickers, invents prices, sends the wrong wallet, and promises win rates the brand refuses to promise.

The product

An assistant with judgement

It answers like the founder, in Saudi dialect or the client's language, stays silent when silence is right, hands money and anger to a human, and nudges leads who went quiet, within hard limits written in code.

How it decides.

From a burst of messages to one answer, or none.
  • 1
    It waits until the client stops typingMessages are buffered per chat. Typing and voice-recording events count as activity, so a burst of five messages gets one answer, not five. The wait is configurable and capped, so nobody waits long.
  • 2
    It reads the whole conversationThe last 40 messages with the new ones flagged, a short memory note it keeps about this client, and any photo (a receipt, a chart) or voice note in the new messages, sent to the model as audio and images.
  • 3
    One Gemini call decidesGemini on Vertex AI returns strict JSON against a schema: reply, skip or handoff, the sales stage, the client's language, at most two chat bubbles, a private reason for me and an updated memory note.
  • 4
    Code checks the answer before it leavesAny USDT address that is not the real wallet, or any number-based win-rate claim, turns the reply into a handoff. Bubbles are stripped of the symbols a person never types on a phone.
  • 5
    It types like a person, then sendsThe chat is marked read, the typing indicator runs for a time proportional to the text, and at most two bubbles go out. In draft mode the reply comes to me first.

The control room.

Everything is run from my own Saved Messages chat.

No dashboard to open: the closer reports where I already am. Drafts, handoffs and errors arrive as messages; commands go back the same way.

/ok 3 · /no 3 · /edit 3

Send, drop or rewrite a draft before it reaches the client.

/mode draft · /mode auto

Approve every reply, or let it answer directly.

/pause · /resume · /status

Stop it, restart it, or see replies in the last hour and waiting drafts.

/mute @user · /resume id

Keep it out of a chat, or bring it back after a handoff.

Real decisions.

Its private reasons from the log, client details removed.
skip · curious

Client sent only a sticker with no text or question. The playbook says to skip lone stickers.

reply · ready_to_buy

Client sent a voice note asking how “watch and alert me” works. Explain it simply, in Saudi dialect.

reply · curious

Client lost money with the old version and asks if the new one is guaranteed not to lose. Be honest: no tool removes losses; the agent sets the stop before entry and says wait when the setup is unclear. Invite a free test.

reply · not_interested

Client wanted binary options. Spirex is built for spot and CFD trades with entry, stop and targets, so say so honestly, don't force the sale and leave the door open.

handoff · customer_support

Existing customer: the app asks him to finish Partner activation instead of showing an active plan. The founder has to check the subscription.

handoff · other

An affiliate asks for a free month to promote Spirex on live streams. Partnership and free-plan decisions belong to the owner.

Each decision writes a one-line reason in English for me, even when the reply to the client is in Arabic. Between 28 October and 2 November 2026 it made 242 decisions on new messages: 139 replies, 54 skips and 49 handoffs, plus 233 follow-ups.

Guardrails.

What the model is not allowed to do, enforced outside the model.

Wallet lock

Every Tron address in a draft is compared with the one real wallet. A different address blocks the reply and alerts me.

No win-rate promises

A regular expression catches numeric win-rate, accuracy and “risk-free” claims in Arabic and English. Honest denials such as “there is no guaranteed profit” still pass.

Never first

It only answers people who wrote in. Follow-ups go only to chats where the client already wrote and our last message went unanswered.

Who it ignores

Bots, verified and official accounts, saved phone contacts (friends and family), muted users, and any chat I am handling by hand.

Rate limits

Replies are capped per chat and per hour. When a cap is hit, the chat is not marked as handled, so the next catch-up answers it.

Handoff silence

After a handoff it stays out of that chat for a set time, or until I send /resume with the chat id.

Architecture.

One process on a laptop, one model call per decision.
Telegram
Client DMsText, voice notes, photos, stickers · typing events · read receipts
Saved MessagesDrafts, handoffs and alerts to me · my commands back
→
closer.py (asyncio + Telethon)
Event loopPer-chat buffer and typing-aware wait · catch-up every 2 min · follow-ups every 10 min
Filters and stateContacts, bots, mutes, handoff silence, rate limits · per-chat memory note and stage in state.json
brain.pyTranscript + media → one structured call → guard() → reply, skip or handoff
→
Services
Gemini on Vertex AIFlash model with fallbacks · JSON schema output · audio and image understanding
Knowledge filesProduct and prices · objection map · playbook · auto-trading FAQ
macOSlaunchd KeepAlive · caffeinate · logs
Python 3
Telethon (MTProto)
asyncio
Gemini on Vertex AI
Structured JSON output
Audio and image input
launchd
caffeinate
JSON state
Markdown knowledge base

Engineering deep dives.

Eight decisions that make it safe to leave running.

1. One answer per burst, not per message

Problem
People on Telegram send a question in four pieces. A bot that answers each piece sounds like a bot and repeats itself.
Approach
Each chat has a pending buffer and one waiting task. New messages and typing events push the deadline back; the task fires after a quiet period or a hard cap, then hands every buffered message id to one decision. The model is told to cover everything in a single reply.
Trade-off
A reply arrives a few seconds later than an instant bot would send it, which is also how a person behaves.
Lives in: closer.py: queue, wait_then_handle, on_typing

2. “Skip” is a valid answer

Problem
Most auto-responders answer everything: “ok”, a thumbs up, a spam link, a personal chat.
Approach
Skip and handoff are values of the same enum as reply in the response schema, with a sales stage beside them. The playbook lists when to stay silent; the log shows it does, from lone stickers to off-topic panic about an exchange being hacked.
Trade-off
A wrong skip leaves a client unanswered, so skips can be posted to Saved Messages while I build trust in it.
Lives in: brain.py: SCHEMA, INSTRUCTIONS; knowledge/03_playbook.md

3. Rules in code, not only in the prompt

Problem
A prompt can be ignored. In a payments chat, one invented wallet address or one “90% win rate” is a real loss or a broken promise.
Approach
guard() runs after every model answer: the wallet check, the win-rate pattern, and a humanizer that removes dashes, slashes, quotes and list markers while keeping links intact. A blocked draft never reaches the client; I get the draft and the reason.
Trade-off
The win-rate pattern is deliberately narrow, so honest sentences that mention profit are not blocked.
Lives in: brain.py: guard, humanize, FORBIDDEN, TRON_ADDRESS

4. Trust is earned in draft mode

Problem
Handing your sales inbox to a model on day one is reckless.
Approach
It starts in draft mode: every proposed reply arrives in my Saved Messages with the reason and stage, and I answer /ok 3, /no 3 or /edit 3 with my own text. /mode auto switches it on. If I write in a chat myself, my message is told apart from its own sends and it stands down.
Trade-off
Draft mode is slower; it exists for the first days, not forever.
Lives in: closer.py: on_command, on_outgoing, our_texts

5. Never miss a message

Problem
The closer runs on a MacBook. Lids close, Wi-Fi drops and Telegram does not always push every update.
Approach
Every two minutes a catch-up pass looks for private chats whose last message is the client's, from the last three hours, newer than what was already handled, and queues them. launchd starts it at login and restarts it if it crashes, wrapped in caffeinate so the Mac stays awake while it runs.
Trade-off
If the Mac is fully off, clients wait until it is back on.
Lives in: closer.py: catch_up, catch_up_loop; autostart.sh

6. Follow-ups with manners

Problem
Leads go quiet after the price. A human would nudge once or twice; a spammer would nudge forever.
Approach
Every ten minutes it looks for chats where our message was the last one, 3 hours and then 24 hours ago. The model decides whether a nudge is right and writes one short message that ends with a question. Only in Saudi daytime, at most 20 an hour, never to stages like not_interested, spam or paid.
Trade-off
Two nudges at most; a lead who wants more attention than that gets it from me.
Lives in: closer.py: followup_due, follow_up, followup_loop

7. Knowledge anyone can edit

Problem
Prices and rules change weekly. Changing them should not mean changing code.
Approach
The model reads four Markdown files on every call: the product, prices and payment steps; an objection map (value, trust, effort, time, identity, risk) adapted from the open-source objection-destroyer method; the tone and closing playbook; and the auto-trading FAQ. Facts not in the files do not exist: the model hands off instead of guessing.
Trade-off
About 30 KB of context per call, which a Flash model handles cheaply.
Lives in: knowledge/01_spirex.md … 04_auto_trading.md

8. A model call that fails safely

Problem
APIs rate-limit, models get renamed and credits run out, always at the worst time.
Approach
Calls go to the Vertex AI endpoint with a chain of fallback models. 429 and 5xx errors retry with backoff, 400 to 404 move to the next model, 402 (no credits) stops at once, and a JSON answer cut short is retried. If everything fails, nothing is sent to the client and I get a message.
Trade-off
Python standard library only for HTTP, so there is nothing to break on upgrade.
Lives in: brain.py: decide, _models, _call