>_ klevrhub

Building an automated ledger using n8n

n8n

I first heard of this tool while scrolling LinkedIn. Network Chuck, who is a popular YouTuber in the cybersecurity space, made a video about it where he was implementing an n8n workflow for his home lab. The way he put this tool to use made me curious, and I went down a rabbit hole of looking up the AI agents people were building using this tool. A lot of other LinkedIn creators had implemented this workflow to automate some of the other things. This was the first instance in a long time where I was actually hyped to test out a new technology. A no-code automation tool that could take care of the repetitive tasks we carry out in everyday life. There were so many integrations available, including almost every service of Google, APIs, Weather APIs, etc. You could execute shell commands, integrate every single LLM available in the market, and build your own AI Agents to cater to your needs. This felt exciting, and I needed to use it ASAP.

Firstly, I was confused. I opened the interface and put together a very basic (and useless) workflow that integrated an OpenAI LLM in a Telegram chatbot. It was literally meaningless, but I just wanted to experiment with something. Later, I spent hours wondering about what problem I could solve using n8n so that I could build something meaningful and something that I actually use.

So I came up with a problem. An automated ledger that keeps track of all my monthly expenses. I receive a certain amount of cash from my father every month and I have to keep a record of all my expenses along with their particulars. This is to keep a record of where I am spending my money, which my father stated is a good practice, so that you know where you are spending the cash.

I used to write everything down on paper, which I felt was really inefficient. Sometimes I used to forget to update my records,and then days later, while doing the calculations, I would have a hard time matching the records. Hence, I decided to digitize this whole process and automate it using n8n.

The workflow

workflow

I basically created a Telegram bot and connected it to Google Sheets which had three columns. Date, Particulars, Debit, Credit, and Final. Whenever I used to spend any money I would add the amount in the Debit column and subtract it from the initial amount. I would also state the purpose of my spending in the Particulars column, along with the date of spending. It was a pretty easy workflow to create but still took me over 4 hours to do so. sample

Above is the workflow in action. This way, you will get a better idea of how the workflow automates the whole process.

  1. A trigger on Telegram has been implemented, which initiates the process once it receives a message.

  2. The message is split into two parts, i.e, Particulars and Amount. For example, in the above demonstration, the message Book:-300 says that I spent 300 on a book hence I want the tool to update it in my ledger. After Telegram receives the message, I wrote a small Python script that splits the message into Book and -300 and sends it further to process.

  3. After that ,the tool fetches the last updated record from the Google Sheet and gets the initial price. For example, my account had 1938 INR before I spent the 300 on a book, hence the tool will fetch that amount from the Sheet.

  4. After fetching the initial amount it subtracts the spent amount, i.e 300 in this case.

  5. After this step, the tool fetches the current date of spending on its own and sends that along with the spending data to the Google sheet.

  6. An if condition comes into play here, if I spend my amount, then the record will be updated in the Debit column and if I add any amount to my wallet, it will be logged in the Credit column.

  7. After that, the records will be updated in my Google sheet as follows. recs

  8. After updating the records successfully, a message will be sent back in reply on Telegram with the updated records as shown above.

  9. This way, I will be able to keep track of the amount I am left with, and I will be able to update my ledger on the go without having to worry about maintaining a piece of paper with me or updating the Google Sheet manually.

I still use this workflow every day whenever I have to update my spending accounts. n8n is a game-changer when it comes to building no-code solutions or automating tedious tasks. It's easy to learn, easier to implement. The only trouble I have come to face till now is regarding hosting solutions to keep my workflow online 24/7. There used to be a lot many services like Heroku, Fly.io, and Railway.app, which provided free tiers for users to host their services, but most of them have shut down those free tiers and replaced them with limited-period trials in order to prioritize profitability. If you want to keep using n8n, you can just run a local Docker instance of it on your device. I personally use n8n locally on Ubuntu via Docker.

When it comes to hosting, you can either pay a fee to get a standard hosting plan on any good platform or buy a VPS. You can also run a local on-premise server for your workflow if you can afford to.

That was it for this post. I am also working on a workflow in n8n that automatically scans incoming emails on Gmail for malicious links and immediately reports them to the user to keep them safe. I will soon write a detailed post about it once it's completed. :)