How to build a Telegram AI bot with n8n – Step-by-step tutorial
9:10

How to build a Telegram AI bot with n8n – Step-by-step tutorial

n8n 05.02.2024 115 577 просмотров 1 334 лайков

Machine-readable: Markdown · JSON API · Site index

Поделиться Telegram VK Бот
Транскрипт Скачать .md
Анализ с AI
Описание видео
In this video, we’ll guide you through the workflow that integrates with Telegram to create an AI-powered chatbot. It uses OpenAI's Chat Model and Dall-E 3 to understand and respond to user messages, correct errors, and generate and send images based on user queries. Get the workflow template for free: https://bit.ly/4920pJx More workflows and documentation for the OpenAI Chat Model integration in n8n: https://bit.ly/3SqsVO6 About n8n n8n is a source-available workflow automation tool designed for technical users, and with over 300 pre-built integrations and a general HTTP Request connector for anything with an API, n8n enables you to connect anything to everything. With n8n you can move beyond simple one-step integrations to build multi-step workflows that integrate your tools exactly the way you want. Thanks to its fair-code distribution model, n8n will always have visible source code, be available to self-host, is free to use. Get n8n for free: https://bit.ly/492XjF5 Join the community forum and ask your questions: https://community.n8n.io/

Оглавление (2 сегментов)

Segment 1 (00:00 - 05:00)

hello and welcome back to this step-by-step tutorial today we are going to build a telegram bot that can chat with users and generate D 3 images on demand we will do the whole project in Anan a source available workflow automation tool and use the new Lang chain nodes you will find the link to the template for this tutorial in the description below the video by the end of this tutorial you'll be able to create a similar bot without any coding here's how the telegram bot will work when a user sends a start command the bot greets the person it can also react to other bot commands without explicit instructions there is also a lang chain tool for creating dowly 3 images the bot only uses this tool when asked to draw something impressive isn't it you will need a couple of additional things to complete this tutorial a token for a t bot and open AI API key we will explain how to create these in just a few seconds so let's get started before we dive into creating our telegram bot the first thing you'll need to do is sign up for an Anan account you have two options here opt for the Anan cloud service which allows you to get started quickly with a free trial and no setup required or you can choose to self-host it by self-hosting you'll have to go through a setup process but it's free to use forever and offers complete privacy for your workflows with your account ready it's time to open a workflow template anic an has a variety of pre-made workflows to get you started just log into your account click on the templates button browse through the template gallery and pick one that aligns with what you want to achieve these templates are great timesavers and can be easily tailored to fit your needs if you don't find what you are looking for you can always build your own workflow from scratch once you found the perfect template click on the use this workflow button and configure credentials for the nodes with red outline now as you created your Anan account let's create a telegram bot from scratch together add a new telegram trigger and select message as the trigger event if you don't have a bot yet check out the link to the blog article with step-by-step instructions once you created a new bot in botf father and receed the access token paste it into the credentials window and click save now drag the Lang chain agent node onto the canvas connect a new chat model to the AI agent create new credentials on the setting screen you will need to add a secret key from your open AI account you can then adjust some additional model parameters via the node options exit the open AI chat model settings screen and navigate to the AI AG agent settings page tweak the text input Fields so that it only receives a text message from the telegram bot user configure the system message we have prepared a custom prompt so that the bot knows the username responds in the HTML format according to the telegram bot API rules and knows how to react to the bot commands that are text messages starting with the sl/ symbol finally add a new telegram node so that our bot can send back the replies in the settings window configure the chat ID and text Fields as described also add a parse mode option you can also switch off the Anan attribution great now let's test the bot at the moment the bot doesn't remember anything about the past messages let's add a window buffer memory this is the easiest way to save the message history simply pick a new node and adjust the number of messages don't forget to edit the session key name let's add a telegram user ID so that the bot can have separate conversations with different users let's try this out and ask something related to the previous conversation with the bot before we go any further please make sure to hit the like button subscribe to the channel and turn on notifications for all future videos we release new content regularly so stay tuned right now our bot can chat and it remembers the last 10 interactions with the user it's time to give a bot an extra tool so

Segment 2 (05:00 - 09:00)

that it can also generate doly 3 images this tool will use additional anic can nodes to request an image the AI agent will decide when to use this tool so we won't program any additional logic now let's add a new custom an can workflow node edit the name of the tool and provide a description of when it should be used this information will be added to the gp4 prompt Lang chain nodes will take care of this so you can focus on your main task and not on the technical details also specify a workflow ID in the settings window in this tutorial we create the entire bot in a single anic can workflow but you can also move this tool to a separate workflow finally configure the workflow values and add a new chat ID variable with the user's telegram ID this value is needed for sending back the image now let's take a look at the lower part of the screen add a new trigger to the canvas and select when called by another workflow when the bot needs to use a tool it will trigger the same workflow again but only the part relevant to image generation add a new HTTP request node at the moment an can doesn't have a dedicated do3 node so we will create a custom connection to save our time let's copy paste a curl example for do 3 from the openai documentation click the import curl button in Anan paste the text example and click import let's tweak the node settings a little switch off the send headers toggle and select the open AI credential in the authentication section scroll down to the send body part and change the value we need to add an expression containing the user request instead also increase the timeout value in case it takes more time for do3 to create an image leave the other settings unchanged and close the window next let's add a new telegram node you can copy paste the existing one select a send photo operation and provide both the chat ID and a URL from the do3 output this URL will point to a new image that has just been created finally add a set node and configure the response that will be sent back to the AI agent since we explicitly specify the telegram user ID and send the image right away we minimize is the risk of the AI agent confusing the telegram IDs or the image URLs one last hint sometimes even the best large language models hallucinate and do not respond with the correctly formatted text we can catch this moment and send the text without formatting let's open the main telegram node connected to the agent click on the gear icon and select continue using error output in the on error drop down list now we add another telegram node connect it to the new error output and specify the chat ID as before in the text field however we will encode special HTML characters so that telegram treats such messages as plain text this trick helps the bot to remain robust in some unexpected cases now let's activate the workflow and test the bot congratulations You' successfully created an AI powered telegram bot with Annie can and Lang chain nodes whenever a user interacts with the bot it responds to both user messages and telegram commands in addition this bot can generate and send doly 3 images the best part is that we haven't programmed anything at all the decision when to send what is made by the gp4 model this is just one workflow example but you can create many other use cases for telegram and AI with Lang chain improve the bot even further with an Dan give it more tools fine-tune the workflow logic integrate the bot with your business systems be sure to check out the links in the description below see you next time

Другие видео автора — n8n

Ctrl+V

Экстракт Знаний в Telegram

Экстракты и дистилляты из лучших YouTube-каналов — сразу после публикации.

Подписаться

Дайджест Экстрактов

Лучшие методички за неделю — каждый понедельник