Lesson 3 · Module 5: Omnichannel Integration: WhatsApp, Telegram and MCP
Building a Telegram bot and linking it to the same agent
- Create a Telegram bot and get its token
- Receive messages by webhook and reply
- Plug Telegram into your existing agent
Why this matters
Many customers prefer Telegram, and a second agent for each app would mean two sets of prompts, two calendars and twice the errors to fix. This lesson shows how to open Telegram as a second front door to the agent you already built, so one brain serves every channel while each app keeps its own thin connector.
Key ideas
- Bot token. A secret string BotFather gives you when you create a bot. Whoever holds it can control the bot, so store it only in n8n's credentials.
- Webhook. A web address that Telegram calls each time a customer writes, so your workflow reacts at once instead of checking for messages again and again. Add a secret token so only Telegram can call it.
- Adapter. A small step that turns each app's message into one common shape. Example:
telegram_update = {"message": {"from": {"id": 5551234, "first_name": "Sara"}, "text": "Book Friday?"}}
common = {"channel": "telegram", "user_id": "tg:5551234", "name": "Sara", "text": "Book Friday?"}
The tg: prefix keeps Telegram user ids from clashing with WhatsApp phone numbers.
- Shared agent. The same sub-workflow answers every channel, so a fix to its prompt or tools improves WhatsApp and Telegram together.
- Inline buttons. Tappable choices under a message. A tap sends a callback query, which the workflow must answer so the button stops spinning.
Try it before you watch
Your WhatsApp agent gets a new Telegram customer. Which parts of the system must change, and which can stay the same?
Show answerHide answer
Only the channel edge changes: you add a Telegram trigger and a small adapter that maps the update to the common format and back. The shared agent, its prompt, tools and calendar stay the same, so one fix serves both apps. It shows that the agent is the brain and each channel is just a door.
Words to know
- BotFather: Telegram's official bot that creates new bots and issues their tokens.
- Webhook: a web address that a service calls to deliver news to you as it happens.
- secret_token: a password you set on a webhook; Telegram sends it back with each delivery so you can reject fake calls.
- Update: the package Telegram sends for each event, such as a new message or a button tap.
- Callback query: the signal Telegram sends when a customer taps an inline button.
- Sub-workflow: a workflow that another workflow calls, so several channels can share it.
What to watch for
- How the Set node reshapes the Telegram update into the same common format used for WhatsApp.
- Where the Answer Query step sits in the flow, and why a button tap needs it.
- The secret token check, and what the workflow does when the header does not match.
Learn it with your tutor on the live board
Key points from the video
One shop, two chat apps
- Your WhatsApp agent already answers customers
- Customers ask for Telegram
- Goal: same agent, a second front door
layout: side
direction: LR
components:
cust: {kind: user, label: Customer}
wa: {kind: external, label: WhatsApp}
agent: {kind: llm, label: Agent}
tg: {kind: external, label: Telegram}
links: [cust->wa, wa->agent, tg->agent]
steps:
- at: "Picture Mona"
show: [agent]
note: "Mona's skincare shop"
- at: "her agent learned to answer on WhatsApp"
show: [wa]
- at: "Do you have Telegram"
show: [cust]
flow: ["cust>wa: Do you have Telegram"]
- at: "customers ask Mona for Telegram too"
note: "More customers ask"
- at: "a second agent"
note: "Another agent?"
- at: "The agent is the brain"
highlight: agent
note: "One brain"
- at: "one door into it"
highlight: wa
- at: "Telegram as a second door"
show: [tg]
flow: ["tg>agent: same brain"] What you will learn
- Create a Telegram bot and get its token
- Receive messages by webhook and reply
- Plug Telegram into your existing agent
layout: side
direction: down
tree:
This lesson: ["Bot token", "Webhook", "Same agent"]
steps:
- at: "By the end of this lesson"
grow: "This lesson"
- at: "create a Telegram bot"
highlight: "Bot token"
- at: "receive customer messages"
highlight: "Webhook"
- at: "connect Telegram to the agent"
highlight: "Same agent"
- at: "a few short lines of Python"
highlight: none
note: "n8n plus a little Python" Meet BotFather
- Open Telegram, search for BotFather
- Send /newbot, pick a name and username
- Treat the token like a password
- No business verification needed
layout: side
direction: LR
components:
you: {kind: user, label: You}
bf: {kind: external, label: BotFather}
tok: {kind: auth, label: Bot token}
n8n: {kind: service, label: n8n credentials}
links: [you->bf, bf->tok, tok->n8n]
steps:
- at: "Telegram makes this part refreshingly quick"
show: [you]
- at: "search for an official account"
show: [bf]
flow: ["you>bf: search for BotFather"]
- at: "the command slash newbot"
flow: ["you>bf: /newbot"]
- at: "BotFather replies with a token"
show: [tok]
flow: ["bf>tok: token"]
- at: "Treat that token like a password"
highlight: tok
note: "Keep it secret"
- at: "Put it in n8n's credentials"
show: [n8n]
flow: ["tok>n8n: store"]
- at: "Compare this with WhatsApp"
note: "WhatsApp needed approvals"
- at: "no review at all"
note: "Telegram: no review" How a message reaches you
- A webhook is a URL Telegram calls for you
- Register it once with setWebhook
- Add a secret_token, check it every call
layout: full
parts:
msg: {chat: "Can I book on Friday?"}
tg: {chip: Telegram, sub: "Telegram servers"}
wh: {chip: Webhook, sub: "Your URL"}
ck: {chip: Check secret, sub: "secret_token"}
door: {box: Entrance, holds: [tg, wh, ck]}
ag: {chip: Agent}
sd: {chip: sendMessage}
bot: {box: "Mona's bot", holds: [door, ag, sd]}
steps:
- at: "types to your bot"
send: msg
- at: "Telegram's servers"
highlight: tg
- at: "Telegram then has to tell you"
note: "Telegram tells you"
- at: "The cleanest way is a webhook"
highlight: wh
- at: "giving the post office your home address"
note: "Your URL is your home address"
- at: "register your address once"
note: "setWebhook, once"
- at: "include a secret token"
highlight: ck
note: "secret_token"
- at: "your workflow can check it"
highlight: ck
note: "Check every call"
- at: "Then the agent thinks"
zoom_out: door
highlight: ag
- at: "reply with sendMessage"
highlight: sd What Telegram actually sends
import json
update = {
"update_id": 901,
"message": {
"chat": {"id": 5551234, "type": "private"},
"from": {"id": 5551234, "first_name": "Sara"},
"text": "Can I book a consultation on Friday?",
},
}
def to_common(update):
msg = update["message"]
return {
"channel": "telegram",
"user_id": f"tg:{msg['from']['id']}",
"name": msg["from"]["first_name"],
"text": msg["text"],
}
incoming = to_common(update)
print(incoming)
reply = {"chat_id": 5551234,
"text": f"Hi {incoming['name']}! Pick a time below."}
print(json.dumps(reply)) One agent, two doors
- Each channel gets a thin adapter
- Adapters translate to one common message
- The agent never needed to know which app was used
layout: wide
direction: LR
components:
waUser: {kind: user, label: WhatsApp customer}
tguser: {kind: user, label: Telegram customer}
tg: {kind: external, label: Telegram}
wa: {kind: external, label: WhatsApp}
adapter: {kind: api, label: Channel adapters}
agent: {kind: llm, label: Agent}
cal: {kind: database, label: Calendar}
links: [waUser->wa, tguser->tg, tg->adapter, wa->adapter, adapter->agent, agent->cal]
steps:
- at: "two front doors"
show: [waUser, tguser, tg, wa, adapter]
- at: "the same brain"
show: all
- at: "Sara asks for Friday"
flow: ["tguser>tg: book Friday"]
- at: "Telegram delivers the update"
flow: ["tg>adapter: update"]
- at: "the adapter translates it"
flow: ["adapter>agent: common message"]
- at: "the agent checks the calendar"
flow: ["agent>cal: free slots"]
- at: "finds two free slots"
flow: ["cal>agent: 10 and 14"]
- at: "writes a reply"
flow: ["agent>adapter: reply"]
- at: "the adapter sends it back through Telegram"
flow: ["adapter>tg: sendMessage"]
- at: "The agent never needed to know"
highlight: agent
note: "Any app works" Worked example: booking on Telegram
- Sara asks for a consultation on Friday
- Agent replies with inline time buttons
- Tap sends a callback query: answer it
- Agent books, confirms, sends invoice link
layout: side
direction: LR
components:
sara: {kind: user, label: Sara}
tg: {kind: external, label: Telegram}
agent: {kind: llm, label: Agent}
cal: {kind: database, label: Calendar}
inv: {kind: file, label: Invoice link}
links: [sara->tg, tg->agent, agent->cal, agent->inv]
steps:
- at: "Let's follow one real booking"
show: [sara]
- at: "Sara's first message asks"
show: [tg]
flow: ["sara>tg: Book on Friday?"]
- at: "The agent replies with a short message"
show: [agent]
flow: ["agent>tg: Happy to help, Sara."]
- at: "Under it are buttons"
note: "Time buttons under the reply"
- at: "Telegram calls these inline keyboard buttons"
highlight: tg
note: "Inline keyboard buttons"
- at: "each one carries a hidden code"
note: "Hidden code: slot ten"
- at: "When Sara taps one"
flow: ["sara>tg: tap a button"]
- at: "Telegram sends a callback query"
flow: ["tg>agent: callback query"]
- at: "Your workflow answers it"
note: "Button stops spinning"
- at: "then the agent books the calendar slot"
show: [cal]
flow: ["agent>cal: book slot"]
- at: "confirms in the chat"
flow: ["agent>tg: Booked on Friday"]
- at: "sends the invoice link"
show: [inv]
flow: ["agent>inv: invoice link"]
- at: "One tap instead of typing"
note: "One tap, no typing" The no-code build in n8n
- Telegram Trigger: messages and button taps
- Button tap? Answer Query first
- Set node: map fields to the common format
- Call the same AI Agent sub-workflow
- Telegram node: send text or buttons
layout: full
parts:
trig: {chip: Telegram Trigger, sub: "messages and taps"}
ans: {chip: Answer Query, sub: "stops the spinner"}
setn: {chip: Set common format, sub: "one shape"}
intake: {box: Intake, holds: [trig, ans, setn]}
ag: {chip: Shared agent, sub: "same sub-workflow"}
rep: {chip: Send reply, sub: "buttons or text"}
root: {box: "n8n flow", holds: [intake, ag, rep]}
steps:
- at: "four main nodes"
note: "Four main nodes and one extra"
- at: "Start with the Telegram Trigger"
highlight: trig
- at: "registers the webhook"
highlight: trig
note: "Webhook and secret check"
- at: "When the update is a button tap"
highlight: ans
note: "A button tap"
- at: "Answer Query tells Telegram"
highlight: ans
note: "Button stops spinning"
- at: "a Set node maps the fields"
highlight: setn
note: "Channel, user id, name, text"
- at: "the button's hidden code becomes the text"
highlight: setn
note: "A tap: hidden code"
- at: "call your existing agent"
zoom_out: intake
highlight: ag
note: "The same agent for both"
- at: "saved as its own sub-workflow"
highlight: ag
note: "One sub-workflow"
- at: "its answer includes choices"
note: "Choices?"
- at: "send inline buttons"
highlight: rep
note: "Buttons"
- at: "otherwise send plain text"
highlight: rep
note: "Plain text"
- at: "Change the agent once"
highlight: ag
note: "Both channels improve" How Telegram differs from WhatsApp
- No 24-hour window, no template approval
- Free to send, no per-message fees
- A bot can only message people
- Customers find you by username or link
layout: side
direction: down
tree:
Two doors:
WhatsApp: ["24-hour window", "Approved templates"]
Telegram: ["No window", "No templates", "Free to send"]
steps:
- at: "A few rules change"
grow: "Two doors"
- at: "On WhatsApp you had"
grow: "WhatsApp"
- at: "Telegram has neither"
grow: "Telegram"
highlight: ["No window", "No templates"]
- at: "sending messages costs nothing"
highlight: "Free to send"
- at: "a bot can only message people"
highlight: none
note: "They must press Start first"
- at: "puts a t dot me link"
highlight: none
note: "A t.me link on invoices"
- at: "One tap opens the bot"
highlight: none
note: "Tap, then press Start"
- at: "send reminders and invoice updates"
highlight: none
note: "Reminders and updates" Common mistake: an open webhook
- Webhook URL with no secret check
- Anyone can post fake "customer" messages
- Claim free sessions
- Fix: set secret_token, reject mismatches
layout: side
direction: LR
components:
bad: {kind: user, label: Stranger}
hook: {kind: api, label: Webhook}
n8n: {kind: service, label: n8n flow}
book: {kind: database, label: Bookings}
ai: {kind: llm, label: AI agent}
links: [bad->hook, hook->n8n, n8n->book, n8n->ai]
steps:
- at: "the mistake I see most often"
show: [hook]
note: "No secret check"
- at: "they never add the secret check"
show: [n8n]
- at: "just a public web address"
note: "Anyone can reach it"
- at: "anyone who finds it"
show: [bad]
flow: ["bad>hook: fake update", "hook>n8n: passes"]
- at: "book every slot on Friday"
show: [book]
flow: ["n8n>book: every slot"]
- at: "ask for refunds"
note: "Refunds too"
- at: "spam you until your AI bill jumps"
show: [ai]
flow: ["n8n>ai: spam"]
- at: "claim free sessions"
note: "Free sessions claimed"
- at: "The fix takes two minutes"
note: "Two minutes to fix"
- at: "Set a secret token"
highlight: hook
note: "secret_token"
- at: "compare the header"
highlight: n8n
- at: "the Telegram Trigger does this for you"
highlight: n8n
note: "Trigger checks it"
- at: "an IF node does it"
note: "IF node"
- at: "stop right there"
highlight: bad
note: "Fake update blocked" Recap
- BotFather gives you a bot and a token
- Protect the webhook with a secret token
- Adapters turn each channel into one message
- One shared agent serves every door
layout: side
direction: LR
components:
bf: {kind: external, label: BotFather}
tg: {kind: external, label: Telegram}
wh: {kind: api, label: Webhook}
ad: {kind: api, label: Adapter}
ag: {kind: llm, label: Shared agent}
links: [bf->tg, tg->wh, wh->ad, ad->ag]
steps:
- at: "Let's recap"
show: [bf]
- at: "in a minute"
show: [tg]
- at: "guard like a password"
highlight: bf
note: "Guard the token"
- at: "delivers each message to your webhook"
show: [wh]
flow: ["tg>wh: message"]
- at: "protect that webhook"
highlight: wh
note: "Secret token"
- at: "A thin adapter turns"
show: [ad]
flow: ["wh>ad: update"]
- at: "prefixed user ids"
note: "Prefix keeps ids apart"
- at: "behind every door"
show: [ag]
flow: ["ad>ag: one message"]
- at: "helps WhatsApp and Telegram"
highlight: ag
note: "One fix, both channels"
- at: "one memory across all its doors"
note: "Next lesson: memory" Your exercise
- Create a test bot with BotFather
- Build the n8n flow, button taps included
- Route it to the agent you built
- Book one slot with an inline button
layout: side
direction: LR
components:
you: {kind: user, label: You}
bf: {kind: external, label: BotFather}
tgbot: {kind: external, label: Your test bot}
n8n: {kind: service, label: n8n flow}
ag: {kind: llm, label: Agent}
cal: {kind: database, label: Calendar}
links: [you->bf, bf->tgbot, you->tgbot, tgbot->n8n, n8n->ag, ag->cal]
steps:
- at: "Now it's your turn"
show: [you]
- at: "Create a test bot with BotFather"
show: [bf]
flow: ["you>bf: /newbot"]
- at: "for your own business idea"
show: [tgbot]
note: "Your idea or Mona's shop"
- at: "Build the flow in n8n"
show: [n8n]
flow: ["tgbot>n8n: messages"]
- at: "an Answer Query step"
note: "Button taps"
- at: "the agent you built for WhatsApp"
show: [ag]
flow: ["n8n>ag: call"]
- at: "a Telegram send node"
flow: ["n8n>tgbot: reply"]
- at: "Make sure the secret token check is on"
note: "Secret token check on"
- at: "message your bot from your phone"
flow: ["you>tgbot: Need an appointment?"]
- at: "tapping an inline button"
show: [cal]
flow: ["ag>cal: book slot"]
- at: "answers you on both WhatsApp and Telegram"
highlight: ag
note: "One agent, two doors"
- at: "ready for the next lesson"
note: "Next lesson: memory" Transcript
One shop, two chat apps. Picture Mona, who runs a small online skincare shop and sells video consultations. In the last lesson her agent learned to answer on WhatsApp: questions about products, bookings, invoices. Then a customer writes, "Do you have Telegram? I don't use WhatsApp." A week later customers ask Mona for Telegram too, and she wants that. So does Mona need a second agent, a second set of prompts, a second calendar? No. The agent is the brain, and WhatsApp is just one door into it. Today we add Telegram as a second door, so the same agent answers in both places with the same knowledge and the same booking rules.
What you will learn. By the end of this lesson you'll be able to do three things. First, create a Telegram bot and get its token, the secret key that lets your system speak as that bot. Second, receive customer messages through a webhook and send replies back. Third, and most important, connect Telegram to the agent you already built, so you don't rebuild anything. We'll do it in n8n, the no-code tool we've been using, and I'll show a few short lines of Python so you can see exactly what data moves between the pieces.
Meet BotFather. Telegram makes this part refreshingly quick. Inside the Telegram app you search for an official account called BotFather. You send it the command slash newbot, give your bot a display name like Mona Skincare, and a username that must end in "bot", like mona skincare bot. BotFather replies with a token, a long string of numbers and letters. Treat that token like a password: anyone who has it can control your bot. Put it in n8n's credentials, never in a shared document. Compare this with WhatsApp, where you needed a business account, a verified number and approved templates. Here there's no review at all.
How a message reaches you. When a customer types to your bot, the message first lands on Telegram's servers. Telegram then has to tell you about it. The cleanest way is a webhook. Think of it as giving the post office your home address: instead of you walking to the post office every few minutes to ask "anything for me?", they bring each letter to your door. You register your address once with a call named setWebhook, and you include a secret token. Telegram sends that secret back on every delivery in a header, a small label that travels with each delivery, so your workflow can check it before doing anything. Then the agent thinks, and you reply with sendMessage.
What Telegram actually sends. Let's slow down and look at the real data. Telegram sends a small package called an update. Inside is the message: the chat id, which is the conversation's address, who sent it, and the text. Our little function, to common, reshapes it into the same simple format our WhatsApp side already produces: which channel, a user id, a name, and the text. Notice the user id gets a prefix, t g colon, so a Telegram number can never clash with a WhatsApp phone number. The reply is even simpler: a chat id and the text to send. That's all sendMessage needs.
One agent, two doors. Here's the whole idea in one picture. Mona's shop now has two front doors, WhatsApp and Telegram, and each door has a thin adapter that translates its own format into the common message we just built. Behind the adapters sits the same brain you already made, with the same prompt, the same tools and the same calendar. Watch what happens when Sara asks for Friday. Telegram delivers the update, the adapter translates it, the agent checks the calendar, finds two free slots, writes a reply, and the adapter sends it back through Telegram. The agent never needed to know which app Sara used.
Worked example: booking on Telegram. Let's follow one real booking. Sara's first message asks, "Can I book a consultation on Friday?" The agent replies with a short message: "Happy to help, Sara. These times are free on Friday." Under it are buttons, ten o'clock, two o'clock, or "another day". Telegram calls these inline keyboard buttons, and each one carries a hidden code like slot ten. When Sara taps one, Telegram sends a callback query instead of text. Your workflow answers it so the button stops spinning, then the agent books the calendar slot, confirms in the chat, and sends the invoice link. One tap instead of typing times back and forth.
The no-code build in n8n. In n8n this takes four main nodes and one small extra. Start with the Telegram Trigger, paste your bot's credential, and choose two update types: messages, and callback queries, which are button taps. n8n registers the webhook, and current versions also check the secret token for you. When the update is a button tap, a Telegram node with Answer Query tells Telegram you got it, so the button stops spinning. Next, a Set node maps the fields into the common format: channel, user id, name and text; for a tap, the button's hidden code becomes the text. Then call your existing agent, saved as its own sub-workflow, so both channels share exactly the same one. If its answer includes choices, like time slots, send inline buttons; otherwise send plain text. Change the agent once, and both channels improve.
How Telegram differs from WhatsApp. A few rules change between the two doors. On WhatsApp you had a 24-hour reply window and approved templates for anything outside it. Telegram has neither, and sending messages costs nothing. The catch is that a bot can only message people who have started a chat with it first, so you can't import a list of customers and send a promotion. That's why Mona puts a t dot me link on her invoices and order emails. One tap opens the bot, the customer presses Start, and from then on the agent can send reminders and invoice updates.
Common mistake: an open webhook. Here's the mistake I see most often. People set up the webhook, it works, and they never add the secret check. Your webhook is just a public web address, and anyone who finds it can send it something that looks exactly like a Telegram update. A stranger could fake a customer, book every slot on Friday, ask for refunds, simply spam you until your AI bill jumps, or claim free sessions. The fix takes two minutes. Set a secret token when you register the webhook, and make the first step of your workflow compare the header. In n8n the Telegram Trigger does this for you; with a plain Webhook node, an IF node does it. If it doesn't match, stop right there.
Recap. Let's recap. BotFather creates your Telegram bot in a minute and gives you a token, which you guard like a password. Telegram delivers each message to your webhook, and you protect that webhook with a secret token. A thin adapter turns every channel's format into one common message, with prefixed user ids so customers never get mixed up. And behind every door sits one shared agent, so a fix to its prompt or tools helps WhatsApp and Telegram at once. Next lesson we give that agent one memory across all its doors.
Your exercise. Now it's your turn, and you can do it in one sitting. Create a test bot with BotFather for your own business idea, or for Mona's shop. Build the flow in n8n: the Telegram Trigger listening to messages and callback queries, an Answer Query step for button taps, a Set node for the common format, a call to the agent you built for WhatsApp, and a Telegram send node. Make sure the secret token check is on: the trigger handles it, and if you used a plain Webhook node, add the IF node that compares the header. Then message your bot from your phone, ask for an appointment, and complete one booking by tapping an inline button. If the same agent answers you on both WhatsApp and Telegram, you're ready for the next lesson.
Explore the animations
The animations from the video, exact and live: play them, pause, drag the slider or jump to a step at your own pace.
Loading the animation...
Loading the animation...
Loading the animation...
Loading the animation...
Loading the animation...
Loading the animation...
Loading the animation...
Loading the animation...
Loading the animation...
Loading the animation...
Loading the animation...
Answer every question, then check. 70% passes; you can retry as often as you like.
Lesson summary
- Reading
- Video watched
- Quiz passed (70%)
- BotFather gives you a bot and a token
- Protect the webhook with a secret token
- Adapters turn each channel into one message
- One shared agent serves every door