Create your own Telegram bot with Django on Heroku – Part 1

This entry is part 1 of 11 in the series Create your own Telegram bot with Django on Heroku

⚠️ This article is outdated and discontinued since Heroku decided to no longer offer their free tiers as this article series suggests to use in August, 2022. Please see this post for details. ⚠️

Recently, I finished my first Django application ✌. Since it took me some time to find a proper starting point to wrap my head around the basics of Django well enough to actually do something with it (apart from following tutorials, which pretty much all aim for creating a polling app for any reason ?), I’d like to recap and share that journey by writing this article about that.

I will describe the project, my thoughts and considerations about it and every step which has lead to what the project has become. I will try my best to make this a guide which everybody can follow along if he wants.

Also, I will make this a series, to not end up with an article so long and boring, that even interested readers cannot afford to read it in their spare time.
In this first part of the series, I will explain what this series will be about, mainly.

About the idea ?

Like most people, from time to time I’m calculating my finances and try to get an overview of my spendings. The non-cash payments by credit- or debit-card are automatically captured by the bank and can be easily extracted from the customer interface in CSV or another, convenient format to be further progressed by the customer in any way he wants.

For cash payments, you either have to write that down somewhere immediately or take the receipt with you, to write it down in some list or whatever you are using, later. Sure there are smartphone apps out there for each and every manner and I do not doubt there is for this case as well, but I could not find any which convinced me, even for myself only.
In my case, I also need to track not only my own spendings but those of my wife, too, to get a fair idea about where our money goes. Finding a proper app for this most certainly has one or more of the following issues:

  • Maybe the app is not available for Android and iOS
  • The syncing is not working very well
  • The app takes ages to launch or to fill the required fields for a simple recording
  • It is hard to grab the data recorded from the app to process it in the way you want; maybe you want to import it to your banking application on your PC or to an Excel / Calc sheet?

If you are like me and my wife, you probably are miss-using one of your messaging apps like WhatsApp, Threema or Telegram to take quick notes by sending texts to your partner, because it is so convenient:

  • Since you are using these applications multiple times a day, their icons are usually placed in some prominent and easy-to-reach location on your device
  • They load in an instant, without showing a loading animation or similar
  • Data sent is automatically archived on your peer’s phone and you can be sure this is “saved” even when your battery dies immediately after the sending
  • You do not need to stick to any form or select a project or similar
  • You have your notes all in one, regularly checked location, so you can be sure you neither will forget where you noted it nor forget about that note because you do not check your notes app as regular as your messaging app

Of course, you need to explain something like “do not mind; that’s just for myself ?” or similar, but still many people consider this more comfortable than to launch a notepad-app like Evernote or similar for that; even if you are doing so, you still need to give your note a subject or search for the note you want to extend, wait for Evernote to launch and sync, you still do not have easy sync with your partner and at least I did not find a way to export Evernote notes properly in a reusable format ?

Then the following idea came to my mind: Instead of spam my partner with my cash payments, make that a Bot! This covers pretty much all the formerly mentioned requirements and, more or less, we are doing so today in our daily routine already, anyways (with the only difference of pesting another human being with our notes instead ?).
Telegram has that Bot-feature and the rest is only about some text pattern matching recognition and details in your application. Nothing too difficult even for an inexperienced programmer.
Today, I’m using that bot on a daily basis. Even my non-technically affine wife is really enjoying the experience since the solution has a next-to-zero learning curve and has turned out to be a really convenient way to record our expenses in the daily stress and fits our daily routine nicely.

But … I do not need to track my cash payments – I’m rich already ?

Instead of recording your cash payments, you can follow this series to learn how to build your own Telegram bot, host it for free on Heroku and make it do whatever you like. Maybe you want to record your voice and have that sent to your mailbox as a mail attachment or transcribed to text? Or you want to trigger some fancy application or tinker board based mechanism? Use your creativity on this – I’d love to hear about your ideas and see them in action ❤!

Outlook for the next part of the series

To not make this article too long, I will end this first part of the series here. Having nothing more shared but the idea and reason for the project so far, the next part will cover the details to create and control a bot on Telegram. That process is completely free, very easy and all you need is a smartphone with Telegram installed (something I recommend anyways since it is by far my favorite messenger app out there).

If you want to prepare even more for the upcoming parts of this series, you can sign up for an account at Heroku already; they offer a permanent “Free” subscription model which already comes with more than enough computing resources to have your bot ready to receive messages 24/7; I usually do not spend more than 7% of my monthly contingent with that bot and I never paid one cent, even.

To make this series more easy to follow, I promise that I won’t let pass too much time until I publish the next part!
If you encounter any questions or have any suggestions to improve this series, please let me know by writing it to the comments below. I will pick that up then in the next parts or have it added here.

Stay tuned for it! ✌

Series Navigation Jump to next part of this series (Part 2) >>