📱

Get Our Mobile App

Take your business learning on the go!

Download on the App StoreGet it on Google Play

N8N. Автоматизируй процессы в пару кликов.

samohosting41:21

Transcription

Well, my little Pentagon hackers. Oh no, it's not Wednesday today. Sorry, we'll be doing that on Wednesday afternoon. But seriously, no, I haven't lost my mind. I'm just in a good mood today. And today we're going to talk about N8N, an automation platform, how we can do it visually in a couple of clicks, without knowing code, practically without knowing code, a disclaimer right away, yes, how we can make certain processes automated. And let's first talk about what processes, yes, what are we talking about. What can be automated here. Only your imagination can limit you, because it can be any task you want to automate. Let's fantasize a little, yes, I will show you with a specific example. We'll talk about it now, but you might want to do anything, starting from when you come home, automation triggers because, in fact, when you come home, your lights can turn on in Home Assistant, yes, your server can start, anything can happen. Here's one of, uh, channel viewers, we talked about what low-code, no-code platforms are in the last video, and someone wrote in the comments: "I have a website, I publish an article. Can I use N8M or some other platform to automate sending a similar post to Telegram and VK?" I haven't looked at the VK API, but it's probably possible too. It's definitely possible with Telegram. Let's talk about how it works in general, and a bit about the architecture first, yes, because one of the first questions is: do I need to publish N8N in, excuse the tautology, in the public space, or can I host it only at home? And here it will depend on the architecture you choose. So, we have our typical home network, yes, an internet connection, and so on. And we deploy N8N on our local server. Some services live nearby, they can live on a neighboring machine, and so on, but N8N, being in the same local network, has access to them. And in this case, you can tie your requests, your triggers, to these services. So, let's have a little bit of basic education, yes? What is a trigger? A trigger is an event that initiates something. It can be an event by time, an event because something happened. And a trigger can be implemented, launched by a webhook. What is a webhook? A webhook is also sometimes called a hook, yes? So, imagine you have a server and you need something to happen there. There's another term. Sorry, there will be many today. Usually, services are developed for communication with the server. This is called an API. And among other things, there are these hooks, yes, you can create such webhooks on your N8 server. This is a link. If you follow it, something will happen. What will happen? The webhook will be triggered. It's a bit unclear for now. We'll get acquainted with how N8N works, but it will be the start command. It's like an on-off switch, yes? So, when someone uses this link, the light will turn on. And who will use this link? Well, you can, for example, take some of your Home Assistant automations, yes, you tell it: "Please, when something happens, trigger this link, yes?" And then the webhook is processed, and some automation process is launched in N8N. And for this, we don't need the internet. If we want to send a message to Telegram, to a channel, to a bot, somewhere for a notification to come to us. Since Telegram itself and its API, i.e., the means of communication with servers, with management, are publicly available, N8N can be deployed locally. It can easily reach the public Telegram server and say: "Hello, here are my logins, passwords, locations, etc. Please do this." And a message will be sent somewhere, or a post will be created, or something else will happen. If you want to be able to build a bot, you can also set it up so that the system polls and asks if there is a new message. And when, yes, there is a new message, start, I see this message and process it on the server, that, yes, I want to do something when I see the message "start," yes, reply, for example, "hello." Or vice versa, you can configure the system so that when you do, you trigger "start," some process should be initiated. Something should happen here, and the request should go somewhere. And in this case, if you want the Telegram server, when someone writes the command "/start" for your bot, it won't be able to call your internal local service. For this, N8N must be public. That is, if you want these webhooks to be accessible from outside, you will have to make N8N a public service, yes? If you don't need this, then you can absolutely use it locally, as I will do in this video. But I actually started a bit, probably, not with the right thing. Let's look again at what N8N is in general. For this, let's go to their official website. And here we will see these diagrams. We will see that we have a first event, yes, user creation, and then it goes on and on, some processes, divisions, and so on. Unfortunately, with my current AI, it's becoming difficult to find examples not related to AI, yes. But nevertheless, look here, so when we have the first event, then some code processing, we will get acquainted with it now, deploy this platform locally, and see what it looks like, but some events happen. You can look at different examples here and so on. Moreover, the N8N interactive board allows you to enter an example. There are a huge number of templates, i.e., templates that you can use for free. And here we have this board. One thing I don't like is that it's so small, inconvenient, yes? So, we'll zoom in on some event now and can double-click on it and, oh, it expanded to full size. Great. But the board is local. I don't know, maybe I'm clicking something wrong. So, it works like this. So, these here, what is this thing? It's just a description for your convenience, yes? But the events themselves, here they are. So, the first thing that happens, let's look at this example directly, is a trigger. So, it can be scheduled, by event, by time, by click, you can launch it manually. Then something happens, yes, a process, for example, receiving mail, then some processing. Processing can occur both with code involvement and with a huge number of already built-in integrations. You can check if a word is contained, if it's not contained. If the word is contained, i.e., if you want a specific email to be sent to you via Telegram or Slack or any other messenger, you can implement it here. To deploy this system locally, we will simply go to the forum. Traditionally, before launching the video, I create a topic, an article, so that you can ask clarifying questions. But I had material that would be easier for me to show you and then calmly provide the code, and so on. So, what will we do? Thanks to N8N, we will automate certain processes. And for the example of this video, it will be a practical task: at my request, at my command, I want a ready-made message of this format to be sent to Telegram once a week about what's happening on the forum, what are the popular topics on the forum. And for this, the first step will be to install N8N. How to do it? We can use the link, go to a separate one. If you don't know what community script is, then these are scripts for installing a container in automatic mode with one command. And we will create a local Docker container with N8N. We can use the official N8N Docker image. There are all the necessary instructions, descriptions. If you use, yes, or there, use the self-hosting edition. where the app store is. You simply go to the app store, there is N8N, and install it. And thus, you will have N8N, which lives in your local network. Before we start, let's go to N8N, let's see what videos are available, yes? So, why did this video come out? N8N, yes? We start searching. And here we will now have a huge number of videos, in every second of which it will be written how to work with AI. By the way, I don't know if there is filtering by language. Let's see. There is no language filter. Well, let's sort by views, yes. And what do we see here? AI agent. Agents. NetworkChuck probably has a general overview. Again, agents. Well, strangely enough. Oh, I also created an army of bots. Templates. A pretty cool video from some iDedic. What happens there? A message is created. You send it to Telegram, it's transcribed from audio, i.e., converted to text. Then AI processes it, and it replies to you. You tell it: "Okay, create an event for me." It goes to Google Calendar, creates an event for you, sends you a message that, yes, it found time for you. It created a meeting with you and Petya. It put it in your calendar. A cool story, but it's already a bit beyond the scope of this video. We won't talk about AI today. We will just talk about creating automation, the one that I want to happen once a week. Let's return again to the logic of narration about how you will architecturally design it, who will go where. Very important. Let me give you a simple example. In one of my previous jobs, there was a kiosk, yes, where we approach and do something with our fingers, order some things, yes, and there was a server that had to interact with this kiosk. And two traditional approaches, as I told you, either it goes here, or it goes there. That is, it's either push or pull, yes? Either someone asks if there's anything new. Or someone, when something new appears, sends it to the server. And what's the catch? If this kiosk has problems with the internet, with the connection, then if the server tries to connect, knock-knock, who's there? And no one answers. The server thinks that everything is fine, there's nothing new, no orders, no one is asking anything. This works poorly. It works much better when the connection to the server is set up here, when orders accumulate. And when the internet appears, this queue just goes away. And the task of this service, without being tied to the server, is to control what it has sent, what it hasn't sent. This is the difference between who goes to whom and who asks what, yes? That is, push or pull. And when you design your automations, you should also think about this, because if you do it wrong, then most likely you will either have a high load on your server, i.e., someone will constantly poll it, yes, and extra CPU percentages will be consumed, yes, and we are talking about a home server. Most likely, you won't have millions of requests there, and it doesn't matter how you design it. Small scale, as a rule, forgives mistakes. When we talk about large scale, yes, orchestration through Kubernetes, all the rest, then a poorly designed solution can cost a lot of money, because you will consume power, deploy automatically. And if you, as an architect, and we, despite being self-hosters, are seemingly small guys who tinker with something at home, you make certain architectural decisions. Therefore, in this sense, I won't be afraid to call you architects. Yes, and if you make a mistake at home, nothing terrible will likely happen. If you make these mistakes on a larger scale, it will cost, well, significant money. So, a little bit of lyricism is over. Let's move on. Now, with the magic of editing, I will move to a deployed N8N instance, and we will see what's happening there. So, we've deployed it. I'm not showing the installation process because it's done via script. You press one button, install, get the IP address, go where you need to, enter your login, password, register, and here you are in the N8N panel. What do we see here? Let's go through what it consists of. N8N, so we have overview, templates. We'll get acquainted with them now. So, it just redirects you to the website link. Then we have blocks that are only available on the enterprise, i.e., paid plan, but they won't interest us, they won't bother us in any way. And here at the bottom are the settings. In the settings, you can see the parameters that interest you, yes, login, password, two-factor authentication. You can add users who will manage processes. Well, if for some reason you want to deploy this within a small business, or something else, yes, so, these are basic settings. What's worth noting, I'll show you now, is the time zone. It's located a bit, well, in my opinion, illogically. There is no default for all processes. It's set during installation as a variable. If you install with Docker, you specify the timezone. If you use LXC from Community Scripts, I think it defaults to Europe or America, it doesn't matter. It doesn't matter what's installed. What's important is that when we set up automations, we need to use the time zone, if we are doing it by time, and you might not understand why I set 8:00 PM and nothing happens, yes? For this, let's go to some, let's create a new workflow. And here at the top, in the three dots, we go in. And here, besides the fact that we can import a file, we have settings that are not yet available here because it's empty. Let's go into some workflow then, which, apparently, is time-related. Well, let's go into the test ones, yes. You can use tags, respectively, to search. And here in the settings, we will see the timezone, yes. You see, American by default. And accordingly, if you set 8 o'clock and expect it to be 8 o'clock in Russia, no, it will be 8 o'clock according to this timezone. Well, basically, just know that it exists. Let's, before we go and solve my specific task, tell you a bit about the logic, how I generally recommend approaching this projectile. So, I want the initial idea, what I wanted to happen, what I wanted to happen next. Discourse forum has this functionality. It's called, uh, email, ta-ta-ta, settings, summary. And this kind of email, in my opinion, is nice, it goes with the main statistics, what's happening there, what are the new and popular topics, etc. And I wanted to send this summary to Telegram in some form. One way to do this is to create an account, receive an email. When the email arrives, N8N will, in fact, receive this email. And here you can, in this case, go and do the first thing, email, yes, in templates. How does this happen? Here are all our, you see what processes are involved here, what nodes, yes? So, these things are called nodes. We have different processes happening here. Search for any that you think you need. Again, use a translator. Let's try. Somewhere here I should have a translation option. So. And where is our Mozilla? Mozilla translate page English Russian. Translate something for us. Enterprises, prices, smart operations. Well, it's clear that it's not perfect, but it allows you to get in. Let's go into some template. Again, there are free ones, there are paid ones, and see how it's implemented. And here, you see, there's a node that times, i.e., requests events every hour, messages, and pulls messages. Then, after new messages arrive, you start doing something with them. The second step, as we see here, is to contain from a specific email address, yes? So, it checks. And here you have logical nodes. Let's talk about what kind of nodes we have. So, we discussed the first options, not the first options, but the first type of node is nodes that launch processes by time, by trigger, by event, webhooks, something else. The second block of nodes will be all sorts of transformations, if statements, yes, text content greater than, less than, quantitative, aggregation, filtering, i.e., you transform something. And then we have integration nodes that can connect to your service. So, in my case, I wanted to interact with Discourse, so there's a separate Discourse node. How to check this? You simply go here and can search for a specific integration, yes? So, for example, I type [music] and we will find some integrations with Discourse, yes, Slack, not Slack, and so on. So, for example, WordPress. Do we have any integrations with WordPress? Yes, of course, there are nodes. How to add these nodes? Let's start from scratch. I'll just show you. Add new workflow. We start either with a manual trigger, or with a chat, or something else. Let's start with a manual trigger. This means it will be launched by clicking. The second event will be a bit of a jump again, sorry, my thought got interrupted. So, initially, I wanted to do it so that we have this. This could be done via email, but then, I understand that then it needs to be transformed, formatting is difficult. The task was to make it simpler. And then I found out, after a little googling, that Discourse has tops. Yes. What are tops? Let's just show you a link. I certainly don't remember it by heart. Let's exit without saving and log in. Digest Telegram RSS resource. And here we have this little thing. It's publicly available. This is about the design, that I don't need to authorize this node, or do anything else with it. I can simply, by following the link, get information without authorization, without anything. Here we have for the week, so, current, past week, there are these popular top topics. There is different information here. And Discourse has something like an RSS feed. If you are not familiar, it's just a dot. RSS is news feeds. It downloaded it for some reason and didn't open it. Well, never mind, it's not important. We'll open it here now. And thus, at the input, I say that I have a trigger that launches a chain of events every week at 6:00 PM on Monday. The first event is a code block that provides a link as input. It could have been implemented differently. It's implemented this way because it can expand into several different links. And then there can be this split-batching, which is needed to separate and get. And the node itself, well, not the node itself, but when we go inside the node, what do we see? On the left, we see the input, what will come into this node. And we can click the "previous step" button to check. We've checked the previous step and see that this link will come here. You see this display, we have the name, the link, something else. And we can view the representation as a schema, in a table, in JSON, yes? We'll go further, and you'll see how convenient and useful this is. So, from a visual perspective, they've done, well, actually, a good job. Everything is very convenient and understandable. Well, again, for someone who has never done programming, it will be practically impossible to do it without examples. You'll have to peek, look at the output. This is what comes out here. We can make some options, add them. Let's see what we have here. Well, specifically in split-batching, there are few nodes. Well, let's take the next node. So, RSS Feed. So, what happened? We launched an event by time, took a link, or rather a set of links, got the first link. If there are many links here, it will loop cyclically, i.e., it will go through each link and perform these actions for each link. Then we have a split into links. Here is RSS FIT. RSS FIT takes a link as input, yes, it's a ready-made node. So, how to find it? You type RSS here and see that you have the possibility of RSS feed trigger. So, at the beginning, there can be a trigger, i.e., if something comes, you subscribe to some feed, and if something comes there, then some events happen. In this case, it's reading the RSS feed, perceiving it. Here it is at the output. Let's execute it to see what it did. Here it received a set of data. What do we see here? We see who created it, and so on. And here it's convenient to use the schema. So, either we look at it in JSON format, or in schema format, yes? Here we have title. And we can work with all these fields, which is what we do next. So, I don't need all the fields, so I aggregate, make a simpler list. What do I do? I transform the incoming data, which we just looked at, into one list. I'll explain why now. The block will be called data. Some, i.e., I can include all fields, but I don't need all of them. So, I include specific fields. I select categories. Category zero title, link creator. How does this happen? I want to add, for example, go ID. Just drag it here. Bam, it's dragged. Let's check that the step has occurred. Everything has come together. So, it has come together in the data block. Then there's data 1, data 2, data 3. So, why this aggregation? Because when I form a message in the chat, you need to know a little bit of JS code here, yes? Well, either with ChatGPT or someone else. Honestly, I'm not good at JS, so, Egorich, thank you very much. Yes, I have a friend who can save me 3-4 hours of time in 30 seconds, just by telling me how, yes? So, what do we do? How to add a block? Let's look again. So, if we want to add for Telegram, Telegram, here's the node. Then we have, you see, how many general options. We have creating actions by chat, by file action, by messages. Very much, yes, there are triggers. So, in this case, I use the send message option. So, in this case, we select credentials, yes, these are your authorization. How to add them? You simply, if they are not here by default, you click "New Credentials." And depending on what node you have, it will ask you here. In this case, we only need the token from your bot. How to create a bot in Telegram, well, I think everyone knows. Open BotFather, it's the official bot management system. Click create, give it a name. And here you have your bot, yes, and there will be an access token. You enter it here and save everything. And you can have several bots, yes, as I have here, yes, a certain number. Then we have some chats, yes, this is where we direct, what we do, rather. The resource will be a message, chat ID, and then text. This is what we send. So, in this case, it suggests below, highlights the result. Looking ahead, here is parse mode. I understand that for those who have never done this, this is very, very difficult right now. Well, you just need to sit down, take an example, practice, poke around, and then you'll figure it out quite quickly. So, our message that we send to Telegram can be sent in different encoding variants. This is either using Markdown, or HTML, as in my example. Why is this needed? So that when I, well, again, I assume that many participants in my channel don't know what HTML code is, these letters B B at the beginning and end, all they do is make the text in between bold. And I want the text to be bold first, yes, emojis are also supported, yes.

Since this is HTML, I've inserted it here, and I'll have this little thing, right? Next, this is exactly it, and now we'll return here. Return to where will we return? Hmm, let's not search like that. Let's find it like this. N8N. So, I'll remind you that I wanted to do something like this with emojis, right, with all sorts of nice things. And for that, I need to use HTML. And then these arrows, they eventually arrive in Telegram like this, right? So you test, see how it looks. And then we have a small piece of JS code, where we write that we will use Jonat to drink by I and these categories. So, what happens? See, I drag the creator here, and the creator has a specific block. It took something from data zero creator. And you see what I got as a result? Ruslan for this value. It can be dynamic. If the next update comes, it won't be Ruslan, but it will be Ivan Petrov, Sidrov, then it will pull up, to go through and iterate through these names, so that I get a list of topics, links, and again, the link is packaged in such a way that it turns out like this, right, blacklists. Here you need to understand the syntax of how it works. Start with the simple, right? So, first just a message, just a crooked, slanted link, tidy it up, then you'll be able to do it. Let's actually, well, let's try to do it simply, if without the niceties, how would it look, right? So, if I just wanted to delete everything here. And we want to simply send some data. We move the data into the text, and here we have some gibberish. We click execute and see what happens. My message has even been sent successfully now. I'll show you how it looks now. Just a second. It looks like this, right? So, unkempt. And it's not very convenient to live with something like that. Plus, we'll hit some limit, most likely. How to cut off limits, right? So, you need to understand that you will definitely encounter a situation at some point where something stops working and so on, and you will search and refine. Here you can insert, for example, some filter or, right, limiting the quantity. Why? Because Telegram cannot, for example, perceive a message longer than a certain amount. I know, so I have experience in terms of knowing that this exists, but have I set any limits here? As you can see, no, because in my use case, I don't believe I'll hit this limit, because I don't have that much, but when there are many, specifically the top is limited by topics, so there are no problems. If I were doing this without a dependency, or in some other way, then I would have to add another restriction. You will refine this, change it. Therefore, with these steps, little by little, looking at templates, you can automate quite a lot. You can receive an email, write it to a table, write a note, it will be saved in a list. You can do anything, right? If we're talking about some cool things that can be implemented at home, as I said at the beginning of the video, you can do it, have the desire to do it so that when you come home, the home server starts, the light turns on, and so on. Question: how to do this? Well, here you need to apply general logic, that you, who will generate this event. Probably, Home Assistant has functions like Bluetooth scanning, right? And if your phone comes home or connects to the Wi-Fi network, some scenario event can be triggered. There is such a service, we looked at Net Net Alert, I think it's called Net Alert X, which scans devices on the network. And there you can also write, right, or rather, specify. So, in N8N, we go here, say webhook. And here we have a local webhook, and we can give it to another service. And when some event happens there, so, it sees our device on the network, this webhook will trigger, right, and thus we can calmly continue processing the chain. So, if we continue the logic and try to figure out how to implement this task, then the webhook starts, it arrives here. Then there are code snippets here, right? So, you can execute one command or another. And, for example, you have such a service, we looked at it, it's called, damn, I can't believe I forgot its name. by it was called on our channel self-hosting upsnap that's what it was called so memory is failing us we can knock on anap webhook.com and trigger the event of turning our machine on and off, right, any action that you can imagine in your head can probably be automated, the question is how to do it more elegantly, more correctly, and so on. So, despite the fact that I initially wanted to send a completely different type of message, in the process of designing, I decided that it would be much easier for me to get. By the way, we are now looking at another node, right? So, we are not using any integration, no integration node. We just looked at an example where I launched, took an RSS feed, did something with it, sent it to Telegram, right? So, I just looked at what the top topics are, right, and I send them to Telegram once a week. In this same node, there is an integration with Discourse, and I had to turn off, release a key for integration, right, in particular, create a key. And then, using this node, let's open it, you can get users with the flag new, but it downloads quite a lot of users. Here again, there is a limit of 50, right, but it downloads them all in a list. And I don't want all new users. Well, meaning, everyone was once new. I want it for a specific date. And I use filtering here, right? So, I have Jon created, we looked at it. So, this is exactly the field, right? Then I have a bit of JS to translate this substring 010 into human-readable Russian. This means that the date, which is in the format, I won't highlight it, just so that no one's names, emails, or anything else are revealed. Again, this is data only for internal use, right, so I'm not worried that someone will take it somewhere, because the service is only local. And, here we have the date in the format with timezone, with minutes, with hours. And to equate it to what I set, and here on the right is today -2 days, right? So, in operational mode, it's -1 day. So, I'm only interested in new users. with a creation date of yesterday. So, that in the evening a message comes: "Congratulations, users have arrived, users registered yesterday such and such." And then after I have aggregated this data again, so that I have the opportunity to go through the list not in this format, right? So, it goes through i and lists all users and shows what there is. Well, let's execute it. This is our test, right? This is our test. Here the nodes have executed. Here are our users. And at the output, we see what we get, right? So, we get an HRF link with the user's name. As a result, it's just a user as a person, but one that you can click on and go to their profile on the forum, right? And thus, I get this message sent, I get this message at the output, in which, in fact, our code, which we see, is transformed into a relatively nice readable format. Yes, well, in fact, this is a very powerful tool. You can synchronize, automate, link different systems here. And for this, you don't need to pay anyone anything. Everything can happen automatically. Yes, it requires setup, yes, it requires your knowledge. And as I said in the previous video, without coding knowledge, without a basic understanding of how syntax works in HTML, in CSS, in JS, including, it will be difficult for you, right? But can you do some simple things based on examples? Definitely can. Search, see what you want to do. Search. Again, go to the forum, write what you want to do, and ask for help. Right? So, just go to the no Low CД section, create a topic here N8N there, how, I don't know, how to turn off the light by pressing the gas pedal in the car. I'm exaggerating, of course, but maybe someone from the community will suggest how to do it. At least it will give you some ideas, that there is a service for turning on and off, there is such a service, you need to go there, you need to go here. Don't expect to be answered for sure. Not a fact, because, well, there are a lot of beginners here who don't know how it works, right, but try, play around. This is definitely a service worth trying, at least to understand how it works. And don't fall for this whole story about only AI. N8N is far from just about AI, right? Why was this video shot? To highlight that, guys, this is an automation platform. That there are a lot of agents here now, that there are videos about how to set up an agent in NEN, there are plenty of them. Yes, but this is not only N8N, not only and not so much about AI, but about automation in general. Okay, let me add a quick insert on how to work with import, because, well, it might not be obvious to beginners. So, we've entered our N8N. We don't have anything here yet. We just create a new workflow. We go and search. Let's search for something. For example, something related to email, right? AIL. And here we want a smart operational assistant. Well, let's assume we use it for free. And here we can either copy the Jon, or, you see, it even managed to understand that I have a related entity nearby. I don't know how it does it under the hood, by the way. Well done. Accordingly, to the clipboard, if we copy, then we save it as a file and then go and do import file here. We can just click add template, and it opens our local N8N instance. It tells you, you need one account, you see, create credentials, create this, create that. We can skip it for now. Well, because we'll just have this scheme, it won't work. You see, we have a cross drawn because we don't have the necessary credentials, at least, logins, passwords, I, everything else. And how to deal with this? If you want to do something with this? So, you understand, you see what's happening in the first node, open it. Here again, you need to add credentials, right? You can absolutely calmly edit it. You say: "Okay, I don't need this, right? I don't want this, this shouldn't go here, this should go here, and so on." So, you can absolutely calmly add some nodes, delete something. I think it can delete in bulk too, right? Let's see, the Dell key, right, through the D button, bulk deletion too. And you can calmly start with some simple process, right, take some simple template, search and start with it. Well, this is, in fact, a small remark on how to use templates. Well, I hope the video was useful to you. Thank you very much for watching it to the end. Be sure to give it a like, write comments to support the channel's promotion. Also, subscribe to our forum, register, come visit, come visit Telegram. Well, and you can always support projects through the links in the description. This was the Self-hosting channel. All successful self-hosting and bye-bye.