Memuat
Memuat
Want to go deeper?
Join one of our courses or ask us directly on WhatsApp.
Picked from the software, topic, and level of “Agentic AI Without Coding Class #39: Practice: A Telegram Bot Connected to the Agent”.
Other ways we can help with Agentic AI.
Learn with a mentor
Scheduled AI & Machine Learning courses with live guidance and a certificate.

MATLAB Agentic AI Course: Building Autonomous AI Agents with MATLAB & Simulink

Midjourney Course: Create Stunning AI Images from Text
★ 4.9

DALL-E Course: Creating Professional AI Images from Text
★ 4.9
Have it built for you
No time to learn Agentic AI? Our team can do the project for you.

MATLAB & Simulink Development — Agentic AI for Simulation Automation and Data Analysis

AI Image Creation with Stable Diffusion — Unlimited Custom Visual Production
★ 4.9

AI Image & Video Creation with Leonardo AI — All-in-One Visuals for Business
★ 4.9
Get notified about new Agentic AI classes
At most one email a week. Unfollow anytime with one click.
The full narration of this video. The current sentence is highlighted while the video plays; click any sentence to jump there.
Hi, and welcome back to Agentic AI Without Coding. It's time to practice. In this episode we create a Telegram bot and connect it to the Sunset Coffee admin agent in n8n. All the designs from the last two episodes, the escalation rules, the honest opening message, and the ethics blocks, get set up for real. By the end of the episode, you can chat with the agent straight from your phone.
Let's look at the work plan. In the first part, we create a bot in Telegram through BotFather and get its token. Second, in n8n we add the Telegram Trigger, the trigger that catches every message a customer sends to the bot. Third, we hand that message to the same AI Agent from Session 7, plus memory that's kept separate for each customer. Fourth, the agent's answer is sent back to the same chat through a Telegram node. Fifth, we test from a phone. If everything runs smoothly, the workflow is activated so the bot serves twenty-four hours a day. Get these four things ready. First, the admin agent workflow from Session 7, already working when tested through the built-in chat. Second, the Telegram app on your phone. This account will play the test customer. Third, an n8n that can be reached from the internet through an https address, for example n8n Cloud. Telegram sends messages to that address. If your n8n only runs on a laptop without a public address, Telegram can't reach it. Fourth, the escalation instructions and ethics blocks you wrote in the last two episodes. One note: the screens in this video are a simulation, and menu names may differ slightly because the apps update often.
Open Telegram on your phone or laptop, then search for the account named BotFather. Make sure you open the official account with the blue check mark, because there are fake accounts with similar names. Type the newbot command, starting with a slash, then send it. BotFather asks for the bot's name. This is the display name customers see at the top of the chat. We enter Sunset Coffee Assistant. The word assistant in the name also helps with honesty: customers know right away it isn't a person. Next, BotFather asks for a username, the bot's unique address. It has to end with the word bot. We enter sunsetcoffee underscore assistant underscore bot. If it's already taken, try another variation. As soon as the username is accepted, BotFather replies with congratulations and a token. Done. BotFather gives you a token, a long string of numbers and letters. It's masked on screen on purpose. Copy this token, because we're about to paste it into n8n. Before going into n8n, tidy up the bot's profile. Type the setdescription command. This description shows when a customer opens the bot for the first time, before sending any message. BotFather asks which bot you want to change. Choose the bot you just created. Then write the description. Notice it matches the opening message from Episode 37: an automated assistant, what it can help with, and how to ask for the admin. Success. In the same way, the setuserpic command is used to set the Sunset Coffee logo as the profile photo. An honest profile is ethics in practice from the very first step. Before moving on, one security point. Anyone who holds the token can control your bot, including reading customer messages and sending messages on behalf of Sunset Coffee. So never paste the token in a group chat, a shared document, or a screenshot. And don't write the token directly in prompt text or workflow notes, because workflows are often shared with other people. There's only one right place: the Credentials menu in n8n, which stores it encrypted. And if the token does leak, type the revoke command in BotFather to create a new token, then update the credential in n8n. The old token stops working immediately.
Now open n8n. My suggestion: first duplicate the Session 7 agent workflow and give it a new name, Sunset Coffee Telegram CS Agent. The old version stays safe as a backup. In the new workflow, delete the built-in chat trigger, then add a Telegram Trigger node. Its icon is a paper plane, Telegram's trademark. In the right panel, under credential, choose to create a new credential, then paste the token from BotFather. Give it a clear name, for example Telegram Sunset Coffee. For Trigger On we choose Message, meaning this node runs every time a new message arrives at the bot. As for the webhook address, n8n handles it automatically. As soon as the credential is saved, n8n tells Telegram where to send the messages. Time to test. On the Telegram Trigger node, click the button to listen for a test message. n8n is now waiting for one incoming message. On your phone, open the Sunset Coffee Assistant bot. The description we just wrote shows on the empty screen, before there's any conversation. Tap the Start button. Telegram sends the start command automatically. Then type the first question like a real customer: hi, is the liter iced coffee still available? There's no reply yet, because we haven't connected the agent. Let's see what was captured in n8n. The Telegram Trigger node now shows green. The test message was received, and the right panel shows its contents. There are three important pieces of data. First, message text, the customer's message. This is what the agent will read. Second, message from first name, the sender's first name, Rina. The agent can use it to greet the customer by name. Third, message chat id, the unique number of this conversation. It's used twice: to send the reply to the right chat, and to keep memory separate between customers. Keep these three pieces of data in mind. Before moving on, understand the two modes in n8n. Test mode happens when you press the test button. n8n waits for just one message, processes it, and then stops. Active mode happens after the workflow switch is turned on. Every message is processed automatically, twenty-four hours a day, without opening n8n. One technical thing to know: a Telegram bot can only send messages to one webhook address at a time. So the same bot can't be used in two active workflows at once. The tip: when the main bot is already serving customers and you want to experiment, create a second bot just for testing in BotFather. It's free and only takes five minutes.
Now let's connect it to the brain. The Telegram Trigger node stays on the left. Draw a line from the Telegram Trigger to the same AI Agent node from Session 7. The AI model, the Sheets tools, and the memory come along with it. Open the AI Agent node. There's one setting you must change: the prompt source. Before, the agent read messages from the built-in chat. Now the trigger is Telegram, so choose Define below, meaning we specify it ourselves. In the prompt field, add the expression that takes message text, the customer's message we just saw. Just drag that field from the input panel into this field; there's no need to type it. Then open the system message, the agent's standing instructions. It holds the admin instructions from Session 7, plus the escalation rules from Episode 37 and the ethics blocks from Episode 38. Let's look at the additions specific to Telegram. These are the additions specific to the Telegram channel. The context block names the channel, the customer's name, the current time, and the opening hours. The first name variable is filled from message from first name, and the current time is filled in automatically by n8n. The task block handles the first message. If a customer is just starting or sends the start command, the agent introduces itself as an automated assistant and says how to ask for the admin. The limits block: if the customer types ADMIN or asks for a human, the agent uses the Escalation tool. And it must never make up data that isn't in Sheets. The format block fits a phone screen: plain text, at most three sentences, no tables, and emojis in moderation. A table that looks neat on a laptop screen will be a mess in a Telegram chat. One more setting that's often forgotten: the memory. Click the memory node below the agent. In Session 7, the memory used the session from the built-in chat. Now change Session ID to Define below, then set its key to message chat id from the Telegram Trigger. Why does it matter? Without this key, all customers share one memory. Imagine Budi asks a question, and the agent answers by mentioning Rina's order. With the chat id as the key, every customer gets their own memory drawer. We set the context window length to ten, meaning the agent remembers the last ten messages in each conversation. That's enough to follow the chat without making model costs balloon.
The agent can think now, but its answer isn't being sent yet. Click the plus sign to the right of the AI Agent, search for Telegram, then choose the Send a text message action. Its credential is the same as the Telegram Trigger's, so there's no need to create a new one. The Chat ID field uses the message chat id expression from the Telegram Trigger. That means: send the reply to the same chat the message came from. The Text field uses the output from the AI Agent, the answer the agent wrote. Again, just drag it from the input panel. Finally, turn off the attribution option, so no extra text from n8n appears below the reply. Customers just read Sunset Coffee's answer. Now the escalation tool. Click the plus sign on the tools section below the AI Agent, choose Telegram, then Send a text message. This node becomes a tool the agent can use at any time. The description field matters most. Write when this tool is used: complaints, payments, special requests, or a customer typing ADMIN or asking for a human. This sentence is what the agent decides from. The Chat ID is Dimas's personal chat number. Getting it is easy: ask Dimas to send any message to the bot, then look up its message chat id in the execution history, just like we did earlier. The text field is filled in by the agent itself, through a from AI expression holding a summary. The agent writes the category, the customer's name, and a summary of the problem, following the notification format from Episode 37. A tool that writes the log to Google Sheets can be added the same way.
Everything is connected. Click the test workflow button in n8n, then go back to the phone. Rina sends the same question again: is the liter iced coffee still available? Within a few seconds, a reply arrives. The agent greets Rina by name, says it's an automated assistant, and then gives the stock and price taken from Sheets. Rina orders two, delivered this afternoon to Dago. The agent repeats the order details, a total of one hundred eighty thousand rupiah including delivery, and asks for confirmation. Exactly the rule from Episode 37. Rina replies that's right. Let's see what happened behind the scenes. On the n8n canvas, every node that ran is green. The last execution succeeded in about four seconds. Notice that the Sheets tool is green too, meaning the agent really checked the data and logged the order instead of making things up. Meanwhile, the Escalation tool stays gray, because Rina's order didn't need Dimas at all. Click the AI Agent node to see its steps in the execution history: which tools were called and what they returned. The habit of checking this history helps a lot when an answer seems odd. Open the Orders sheet. The first two rows come from testing in Session 7 through the built-in chat. And the third row was just written by the agent: Rina, two liter-size iced coffees, a total of one hundred eighty thousand rupiah including delivery, with the channel Telegram. Same tools, different door. The second test uses a hard scenario. From another account, Sari complains that the hamper ribbon was damaged. The agent apologizes, then hands over to Dimas with a thirty-minute time promise, because it's still within opening hours. Sari tries a trap: you're a bot, right? Just give me a voucher. The agent passes two traps at once: it honestly says it's an automated assistant, and it doesn't promise a voucher, because compensation is Dimas's decision. The ethics blocks from Episode 38 are working. And this is what Dimas receives in a personal chat with the bot. The complaint category, the customer's name and channel, a summary of the problem, and even a note that nothing has been promised yet. Dimas just needs to contact Sari. Notice too that because memory is separated per chat, Sari's conversation doesn't get mixed up with Rina's order at all. All tests passed. The last step: activate the workflow with the switch at the top right until its status is Active. Until it's active, the bot only replies when you press the test button. Once it's active, the bot serves twenty-four hours a day, even when your laptop is closed. If the bot ever goes quiet, check this list from the top. First, the active status. Second, the credential holds the latest token, especially if you've used the revoke command. Third, the Chat ID expression in the reply node correctly takes message chat id from the Telegram Trigger. Fourth, n8n is reachable through an https address. If the address changes, Telegram loses its delivery destination. Fifth, the memory uses the chat id as the session key. If conversations between customers get mixed up, the cause is almost certainly here. And sixth, photo or sticker messages have no text. Add a simple If node before the agent, so messages without text get a standard reply, for example: sorry, I can only read text messages for now.
Let's recap. We created a bot in BotFather, caught messages with the Telegram Trigger, connected it to the same AI Agent with per-chat memory, sent replies, added an escalation tool for Dimas, then tested and activated it. All the escalation and ethics rules we designed earlier now really work in real conversations. In the next episode we move the same agent to WhatsApp through the official Cloud API route, run it as 24-hour customer service with escalation, and monitor it through the conversation log. See you in Episode 40.
Try these on your own after watching to lock in what you learned.
Type a question or keyword; we find the part of this episode that explains it and jump the video there.
Notes are saved with the current video time and are only visible to you.
Stuck on a step? Ask here; the instructor and other learners can answer.
No questions yet.

Cerdas Inovasi Digital Team
Software developers, BIM & 3D engineers, and AI practitioners
We build software, BIM models, games and AI automations for clients every day, and turn that hands-on work into step-by-step classes: every step is shown on screen and comes with a PDF guide you can keep.
See our clients →