Make AI Agents (New)
Create AI agents for different...
Telegram-triggered AI agent
6 min
this telegram triggered ai agent {{scenario singular lowercase}} watches a telegram bot chat for new user messages and the agent replies to them prerequisites a telegram account a https //core telegram org/bots/tutorial your token (you'll use this when creating a webhook in {{product name}} ) step 1 add a watch updates module the telegram bot > watch updates module watches for new messages from your bot channel in telegram to add the telegram bot > watch updates module in the {{scenario singular}} builder, click the giant plus in the app search, search for and click telegram bot click the watch updates module in webhook name , name your webhook to identify it later in connection , click add to create a new telegram bot connection in connection name , name your connection to identify it later in token , paste the token you received when you created the telegram bot click save click save click save on the {{scenario singular}} toolbar you've now added the telegram bot > watch updates module to your {{scenario singular lowercase}} step 2 add a route to reply to /start or non text messages when you start a conversation with a telegram bot, the bot sends a /start message to your {{scenario singular lowercase}} as /start isn't a unique user message, you don't want it to trigger your agent additionally, this example slack {{scenario singular lowercase}} only accepts text, excluding non text media, such as images, videos, or audio files add a route that sends a welcome message in response to /start , or requests text only messages in response to non text messages to add a route click the plus icon next to the telegram bot > watch updates module in the app search, search for and click flow control click router click the 1st route in label , enter welcome response in condition , configure the fields based on the following map the message text value from the telegram bot > watch updates module text operators equal to /start make sure you've selected message\ text here, rather than a similar value, such as edited channel post text click add or rule to add a second condition for non text messages map the message text value from the telegram bot > watch updates module basic operators does not exist click save click save on the {{scenario singular}} toolbar click the giant plus next to the 1st route in the app search, search for and click telegram bot click the send a text message or a reply module in connection , select the same telegram bot connection that you used earlier in chat id , map the message chat id value from the telegram bot > watch updates module in text , enter the following function, so when the message is /start , the agent replies "welcome!", and when it's anything else, the agent replies that it only accepts text click save click save on the {{scenario singular}} toolbar test the module click run once on the {{scenario singular}} toolbar in your telegram bot chat, click start this triggers the correct message as a reply you've now added a route that replies to /start or non text messages step 3 add a route to reply to user messages to add a route to reply to all other user messages click the 2nd route in label , enter " all other user messages " select yes to set the route as a fallback click save right click the telegram > send a message or a reply module and select clone move the cloned module down until it links to the empty giant plus, then unclick right click the empty giant plus and select delete module in the cloned module, in text , delete the function enter "hello" and map the message text value from the telegram bot > watch updates module click save click save on the {{scenario singular}} toolbar toggle immediately as data arrives on the {{scenario singular}} toolbar to activate the {{scenario singular lowercase}} to test the {{scenario singular lowercase}} , go back to your telegram bot chat and send a message to receive an agent reply you've now added a route to reply to user messages step 4 add a run an agent module to add the run an agent module to the user message route right click the 2nd route and select add a module in the app search, search for and click make ai agents (new) click the run an agent module in connection , select an existing ai provider connection from the dropdown or click add to create a new one in model , select a small model smaller models react quickly to new data, which is ideal for this chat based ai agent in instructions , describe who the agent is and what it does for now, enter "you are a friendly agent " in input , map the message text value from the telegram bot > watch updates module in conversation id , map the message chat id value from the telegram bot > watch updates module in telegram, each user has their own message chat id the agent uses it to remember the conversation history with the user and answer any follow up questions as users chat more with your telegram triggered agent, storing all past messages can get expensive to reduce tokens, you can set this field to start fresh conversations periodically (like using a timestamp), so the agent remembers less you've now added the make ai agents (new) > run an agent module to the {{scenario singular lowercase}} step 5 add the agent response to finish this {{scenario singular lowercase}} , map the agent response in the telegram bot > send a text message or a reply module to allow the agent to reply to the user message to add the agent response in the telegram bot > send a text message or a reply module on the 2nd route, in text , delete the existing text and map the response value from the make ai agents (new) > run an agent module click save click save on the {{scenario singular}} toolbar you've now created a telegram triggered ai agent {{scenario singular lowercase}}