It’s always been part of human nature to automate the boring and mundane tasks of everyday life — whether it’s scraping a website every 4 days or sharing updates to a Slack channel. I was doing so myself until I wound up on a really interesting workflow automation tool called n8n. You know — like Kubernetes is k8s, nodemation is n8n. It’s pretty sweet.
Out of the box, it doesn’t look like it has much to do with programming. A quick check on the integrations page and you see a growing number of third party APIs available to make your life oh so easy. Don’t worry if you can’t find inspiration immediately, the templates and community inspired workflows page has a cool list of already automated workflows you can either use yourself or get a few ideas from. This product has a pretty cool thing going on.
Today we’ll be adding to that list of workflows. We aren’t going through the easiest time at the moment with everything going on in the world and sometimes we need a little lift up. We’re going to create a workflow that sends positive affirmations to your telegram chat or group every day at a time you want.
Getting up and started with n8n is rather straightforward.
Note: You might have some trouble if you don’t have node-gyp installed. The official GitHub page has instructions for how to get it running on multiple operating systems.
Once you meet all the prerequisites, install the n8n CLI with
npm install n8n -g and run it with
When prompted, press ‘o’ in your terminal to open the local address in your browser and begin automating workflows. You’ll be met with this screen.
n8n calls integrations nodes. It has a good number of third party nodes and inbuilt nodes. Sometimes, nodes can be used to trigger or start a workflow. To start it off, we’ll add a Cron trigger that will start our workflow at a specific time. If you click the + in the top right corner, you open up a menu of nodes. Click on the trigger tab and search for Cron. Click on it to add the time you want it to be triggered.
Click on the Execute Workflow button and you should see a small alert in the bottom right corner telling you that the workflow ran successfully.
Note: Make sure to change settings in the panel on the left so that the Cron job runs at a time in your timezone.
We have made sure that our workflow gets triggered at a specific time every day. Now we need need to request data from an API to get us these affirmations. Luckily for us, n8n has an HTTP Request node and thanks to the folks at affirmations.dev we have some awesome messages to return.
Again, we click the + in the top right corner and search for HTTP and click on the HTTP Request node. Paste https://affirmations.dev in the URL section and execute the workflow. Successfully runs again but this time you get some data, which is always good when making a request. Close the modal. Click and hold the circle on the Cron node and drag it to the left side of the HTTP Request node. This way, we’re telling n8n that when the Cron node is triggered, we need to make a request and return some data.
We’re being returned affirmations in JSON format and we want to be able to send these out via Telegram. We have a Telegram node at our disposal. As we did before with the Cron and HTTP Request nodes, search for and click on Telegram.
There are a few fields highlighted and we don’t have that data yet. So before we use the Telegram node, we have to get those details. Here’s what we need to do:
- Create a Telegram account and get the Desktop client
- Talk to the Botfather, a bot we use to create our bot.
- Here, you give your bot name and unique username and get back a URL that directs you to the bot and token to access the bot via HTTP, we need to keep this safe. Click on the bots URL (t.me/<bot username>) and press start when taken to its chat window.
- Add the bot to a group
/test hiin the group chat you just added the bot to.
- In your browser go to https://api.telegram.org/bot<TOKEN>/getUpdates and replace <TOKEN> with the token you get when creating the bot. You get back some JSON, look for a property called chat and get the corresponding ID.
Now we have our Telegram API token and chat ID. We need to add credentials in our n8n credentials section. We’ll name it Telegram Token and then paste the token from Botfather in the Access Token field.
We connected the HTTP Request node and Telegram so we can send the response as a message. n8n lets us take data from other nodes and use it in different fields. In our case, we’re getting the response data from the HTTP Request node and adding it to a message that we’ll send using the Telegram node.
We open the Telegram node, click the gears next to the text field, and click on Add Expression. We have two sections — variable selector and expression. In the expression section we type out the message and because we want the affirmation to be sent at the end of the text we make a few new lines before we head over to the variable selector. We use this section to “interpolate” data from other nodes into the main expression. To select the data, we click on the Current Node > Input Data > JSON and then select the JSON property we want which in our case is affirmations. This way, at the end of the expression “Hey Daniel, here is your daily affirmation”, we have a different affirmation every day depending on what the API request returned.
Add your Chat ID and made sure all other credentials in the Telegram field have been filled. We’ll leave the chat operation as send message because that’s what we’re going for. Close the node and click on the Execute Workflow button.
Check your Telegram and you should have a new message from your Daily Good Vibes bot.
Looking back it’s pretty cool what we’ve got done with practically no code. We’re requesting data from an API and delivering it to our Telegram client. With tonnes of other cool nodes — there’s so much to do with n8n.
Now this is a really basic example of workflow automation, check it out here. These happen to be some of my favorite that aren’t as basic.
- API which queries data from GraphQL
- Typeform to Google Sheet and depending on severity to Slack or Email
- Scheduled Web-Scraping to Google Sheets
- Notification on GitHub star in Slack
Hopefully with this you have an understanding of how to use n8n and I hope you’ll go on to create some really useful workflows. Let me know on Twitter if you do or add them to be displayed on the n8n.io workflows page. Stay safe and take care.