A funnel bot in Telegram
Someone taps Start and the card is already there: your picture, your three lines, a button that opens your app inside Telegram. Behind it a second agent takes its time — it files the code the link carried, nudges the people who did not finish, and says well done when your backend reports a sign-up. This is how the two halves are built, and why they are two.
- A bot of your own. @BotFather makes one in a minute and gives you a token. It has to be a bot, not a personal Telegram account: only a bot can be the target of an ad link, carry inline buttons, and open your app as a Mini App.
- The first message, finished. A picture, three or four lines, and the words for two or three buttons. The card never changes at run time — that is exactly why it is instant.
- An API key from Settings, if you want the card and the follow-up. The app's trigger editor decides when an agent runs; what a rule sends — the card, its buttons, the handoff — is written through the API or an MCP client today. Every step below says which of the two it is.
- Step 1
Connect the bot
The gear above the channel filters opens Connections. Go to Add New, pick the Telegram Bot tile, paste the token @BotFather gave you and save. Not the Telegram tile above it — that one logs in an ordinary account and can do none of what follows.
From then on the bot's chats arrive in your inbox like any other channel, and the agent you build next can answer in them.

Connections → Add New → Telegram Bot. The three steps are BotFather's; the field takes the token it gives you. - Step 2
Two agents: one to answer, one to think
AI Agents, New Agent, twice. The first one has Text engine set to Rule-Based: it runs no model at all, which is the whole reason the card is instant. Give it no instructions — a rule does not read any.
The second one is Agentic, and this one gets the instructions: what to do with a referral code, when to nudge, what to say when somebody signs up. Give it the tools it will need — messages.send, messages.read_history, contacts.update, reminder.set, reminder.list, reminder.cancel, agent.silence.
Note both agent ids from the address bar. The rule needs to know which agent to hand the conversation to.

Rule-Based, and Send mode on Auto — the card carries buttons, and a draft cannot. - Step 3
The card: photo, copy, buttons
Upload the picture first and keep its numeric id — files.upload over MCP returns it. Then give the rule agent an incoming_message trigger whose conditions carry the keyword and the card.
curl -X POST https://api.dialogbrain.com/api/v1/agents/34836/triggers \ -H "X-API-Key: db_live_..." \ -H "Content-Type: application/json" \ -d '{ "trigger_type": "incoming_message", "send_mode": "auto", "conditions": { "keywords": ["/start"], "context_types": ["dm"], "template": { "text": "Acme — borrow, do not sell\n\n💎 Borrow against your assets\n🔒 You keep the upside\n🧾 A loan is rarely a taxable event\n\nOpen the app and start 👇", "attachments": [567356], "buttons": [ { "label": "🚀 Open the app", "web_app": "https://app.example.com/" }, { "label": "🌐 Open the site", "url": "https://example.com/" }, { "label": "🇬🇧 English", "value": "lang_en" } ] } } }'What the shape has to respect: text is required and becomes the caption under the photo, and Telegram's caption limit is 1024 characters. Go over it and the photo arrives on its own, with the text and the buttons following as a second message — so leave a margin, because Telegram counts emoji as two. attachments is a list of file ids. There can be ten buttons, each with a label and exactly one target — two targets on one button is refused when you write the trigger, not when a customer taps it.
Send mode has to be auto. A draft row cannot carry a keyboard, so a card with buttons in draft mode would arrive with the buttons silently missing; the platform refuses the combination instead.
This trigger answers on every Telegram bot the workspace has. If you run more than one, add channel_account_ids with the funnel bot's account id — messages.read_history returns it beside any conversation of that bot.
- Step 4
Hand the conversation to the second agent
The same trigger gets one more key. handoff names the agent that runs after the card, and the brief it runs with.
"handoff": { "agent_id": 34484, "task": "The welcome card has already gone out in this thread — do not send it again. If the incoming /start carries a referral code, read the sender id from messages.read_history and put the code on the contact with contacts.update. Then set a reminder 3 minutes out to check whether they finished." }The order matters and is enforced: the agent starts only after the card has actually been sent. It then runs on that same conversation as an ordinary trigger run — the customer's message is its incoming message, your task is the brief that came with it, its own send mode and safety gates apply. The rule stays instant; the thinking happens behind it.
If the card was drafted rather than sent, or refused, or failed, nothing starts. If you later pause or delete the agent named here, the card still goes out and the reason the follow-up did not start is written into the rule's activity row. The brief may use {channel_type} and {thread_id}; it refuses {message_text}, {from_name} and {raw_data}, because a brief built from what the customer typed is a brief the customer wrote.
- Step 5
The code in the link
Every campaign gets its own link: https://t.me/yourbot?start=SUMMER. Telegram allows up to 64 characters there — letters, digits, underscore, hyphen — and hands the bot /start SUMMER as an ordinary message when the person taps Start.
So nothing about the card changes: the keyword /start still matches, the same card still goes out. The code is the follow-up agent's business. Its brief tells it to read the sender id out of messages.read_history and write the code onto the contact with contacts.update — after which the code lives on the person, where a filter or an export can find it, instead of only in a chat line.
- Step 6
The nudge, and calling it off
Nudging is two lines in the second agent's instructions, not a feature to switch on. Have it call reminder.set for three minutes out with a reason it will recognise later. When the reminder fires, that same agent wakes up on that same conversation.
Tell it what to look at: if the person has said they finished, write nothing at all — agent.silence ends the turn without a message. If they have not, one short line and the same buttons, this time without the photo, so the nudge does not look like the card again.
When they do finish, reminder.list finds the pending one for that conversation and reminder.cancel takes it off. A nudge that arrives after somebody has already signed up is worse than no nudge.
- Step 7
When they sign up, tell the bot
DialogBrain cannot see your product's database, so the sign-up has to be told. Add a webhook trigger to the second agent and copy the URL the trigger card shows you — it carries its own secret, so treat it like a password.
POST https://api.dialogbrain.com/api/agents/webhook/<token> Content-Type: application/json { "event": "account_opened", "telegram_id": 123456789, "ref_code": "SUMMER" }The whole payload reaches the agent, so it can be whatever your backend already knows. The Telegram id is the part that matters: it is how the agent finds the conversation. Its instructions then do the obvious three things — put the sign-up on the contact, cancel the pending reminder, send one line of congratulation.
Where does your frontend get the Telegram id? From Telegram, when your page is opened by the app button as a Mini App: window.Telegram.WebApp.initDataUnsafe.user.id, with the referral code beside it in start_param. A visitor who opened the site button in a normal browser has no Telegram id, and that sign-up cannot be matched to a chat.
One caveat worth knowing: a Telegram id names a conversation on every bot that person has written to. If they have also messaged your support bot, say which bot the funnel runs on in the brief, or hand the agent the numeric conversation id — asked for the id alone, DialogBrain will refuse rather than guess, and name the candidates.
- Step 8
The language button
The third button carried value instead of a link, which means a tap arrives as an ordinary incoming message whose text is exactly that value — lang_en. Anything that matches an incoming message can therefore answer it.
Add a second trigger to the same rule agent: keyword lang_en, and a template that is the same card written in English. No model, no handoff, nothing to wire — the card simply comes back in the other language. The same trick works for a Pricing button, a Contact button, or any branch whose answer is fixed copy.
Why it is two agents
A model composing a message that never changes is pure waiting. On the funnel this guide is drawn from, the first message took between seven and thirty seconds while an LLM wrote it; as a rule with a card it goes out in a fraction of a second, and the same photo is not re-uploaded to Telegram twice.
Everything that genuinely needs judgement still gets it — just after the customer already has something to read and something to tap. That is the whole design: fixed copy on a rule, judgement on an agent, in that order.
Watching it work
The agent's History tab has one row for the rule and one for the follow-up. Open a run to see the tools it called and what came back — that is also where the reason lives when a card does not arrive, or when the card went out and the follow-up did not start: a refused keyboard, a paused target, a channel that does not render buttons.
Test the whole thing on yourself first. Open your bot, tap Start, and watch the card, the code landing on your own contact card, the nudge three minutes later, and the congratulation when you fire the webhook by hand with curl.
Does the card cost tokens?
No. A rule-based agent runs no model — it substitutes the placeholders and sends. Only the follow-up agent behind it is a model run.
Can I use the same card on WhatsApp or Instagram?
The text and the photo, yes. Inline buttons are a Telegram-bot feature, and a Mini App button is Telegram-only; on other channels those buttons are refused rather than dropped.
My buttons never arrive. Why?
Almost always send mode. A draft cannot carry a keyboard, so a card with buttons needs the trigger's send mode set to auto. The other cause is a channel that does not render buttons at all.
Can one button both open a link and send a reply?
No. A button carries exactly one of value, url or web_app. Two targets on one button is refused when the trigger is saved.
Where do the file ids for attachments come from?
From the upload: files.upload over MCP returns the numeric id, and the trigger takes that number, not a filename or a URL.
What if the follow-up agent has nothing to say?
It calls agent.silence and the turn ends with no message. Worth putting in the brief explicitly — an agent that always answers will answer a webhook nobody is reading.
Can the card and the follow-up live on one agent?
Only if you are willing to wait for the model to write the card every time. The split exists so the fixed half is instant; a single agentic agent puts everything behind the same model run.
Is the referral code stored anywhere I can filter on?
It is wherever the follow-up puts it. The usual place is the contact's notes via contacts.update, which makes it visible on the contact card and reachable from search and exports.