Create your own Telegram bot with Django on Heroku – Part 9 – Creating a model for your messages

Header Image showing Django, Telegram, Heroku logos

Django_Pony

In the previous part of this series, I explained what a database is good for in general and Django in special. I also told about what relational database systems (RDBS) are supported by Django, what migrations and models are and how to create and apply them. Further, I introduced and explained what the Django Admin-Backend is and how to use it to create, alter or delete data in tables resulting from having applied the migrations to SQL databases from a model definition.

Today, we will create another database model to hold the message-data forwarded to our webhook by the Telegram – bot in the future. I will try my best to make this a play-along part which invites everyone to follow step by step in another console. Hopefully, it gives you an idea what thoughts and considerations are involved in writing a model for a real-world problem and how to involve Django’s documentation resources.
Continue reading “Create your own Telegram bot with Django on Heroku – Part 9 – Creating a model for your messages”

Create your own Telegram bot with Django on Heroku – Part 8 – Integrating the database

Header Image showing Django, Telegram, Heroku logos

Django_Pony

In the previous part of this series, we had a bit of a term definition to make it easier for beginners of Django to understand what I am talking about. Also, we created a Django – App called “bot” and created a URL routing for it to be available at (https://dry-tundra-61874.herokuapp.com)/bot/* (or whatever your URL looks like) and how to direct URLs to a view.

Originally, I planned to also show how to start using a database in Django to hold your bot’s data. But since the article grew larger than I anticipated before, I had to cut that down, unfortunately (sorry for that 😰).
Today, I will deliver that part in its own article. We will learn how to work with databases in Django, what migrations are and how to interact with the database from within Django’s Admin-Backend.
Continue reading “Create your own Telegram bot with Django on Heroku – Part 8 – Integrating the database”

Create your own Telegram bot with Django on Heroku – Part 7 – Introducing apps and URLconf

Header Image showing Django, Telegram, Heroku logos

 

Django_Pony

In the previous part of this series, we started with the basics for kicking off a new Django project. We prepared our virtualenv, installed needed modules to it, created and integrated a new Heroku – project for it and learned how to work with variables in Heroku to control our application with an easy example. We also learned how to check our results locally before we publish it to our production space and how we can add an addon to our Heroku project by adding a PostgreSQL database to it.

Today, we will learn what an “app” is in Django and how to create it. Also, we will learn about and create a so-called URLconf / routing to direct specific URLs to specific parts of our code.
Continue reading “Create your own Telegram bot with Django on Heroku – Part 7 – Introducing apps and URLconf”

Create your own Telegram bot with Django on Heroku – Part 6 – Creating the Django app

Header Image showing Django, Telegram, Heroku logos

 

 

Django_Pony

In the previous part of this series, I tried to give you a brief yet thorough introduction to hosting your projects with Heroku.
That part was special because it was a completely optional part of this series; if you prefer to host your applications on a different platform and skipped that article, I’d like to repeat that this is completely OK and that I had shown nothing you will need for anything different but interacting with Heroku. You will hopefully notice no blank spots in the following articles. There is no need to read that article if you do not plan to use Heroku for hosting your bot. But you should be familiar enough with your hosting solution of choice to adopt the Heroku – commands I show here to an adequate setup for your hosting solution.

Today we will finally start creating our bot with Django. What we did up until now was just some kind of preparation and establishing background. In this part, we will finally start with the real stuff. 💪

Continue reading “Create your own Telegram bot with Django on Heroku – Part 6 – Creating the Django app”

Create your own Telegram bot with Django on Heroku – Part 5 – Introduce Heroku

Header Image showing Django, Telegram, Heroku logos

In the previous part of this series, I tried to explain the differences in the two modes a Telegram bot supports: pull (getUpdates) and push (Webhook) methods. I also explained what a webhook is and how to easily giving it a test-drive, without any hassle.

Today we will talk about what Heroku is and about how to prepare your workstation to effectively work with that platform.

If you do not like Heroku or if you simply want to use another hosting service for your bot like AWS, OpenShift, Google Cloud Platform, whatever for any reason: That is perfectly OK and you can do so! I will write this and the next article on Heroku in a way that even when you decide to skip it completely, you won’t miss anything from this Telegram/Python/Django article series but the presentation of how to get the bot hosted on Heroku.
The only thing which you won’t be able to follow 1:1 in the upcoming parts of this series is that you can’t use those commands to trigger new deployments to the hosting platform with or do some minor, hosting platform related steps. But if you are advanced and familiar enough with deploying web applications to have a better idea of hosting an application than me, this shouldn’t be much of a problem for you, since most commands for Heroku are pretty straightforward and easy to adapt for a different system.

Continue reading “Create your own Telegram bot with Django on Heroku – Part 5 – Introduce Heroku”

Create your own Telegram bot with Django on Heroku – Part 4 – pull vs. push method

Header Image showing Django, Telegram, Heroku logos

In the previous part of this series, we started to get familiar with telepot, a Python module to interact with Telegram bots and had a short look at how the Telegram bot API is providing messages as JSON structures.

Today we will talk about the Webhook-method (push) instead of the previously introduced getUpdate-method (pull).

Continue reading “Create your own Telegram bot with Django on Heroku – Part 4 – pull vs. push method”

Fix for audio mutes at low volume in Linux

Recently, I had the issue with my Mint Linux machine’s audio that when the volume of what is played dropped below a threshold, that channel was muted completely. I experienced this especially unpleasant when I had my headphones on since in passages with low volume, the sides switched from “low volume” to “completely off” independently multiple times each minute. It sounded as if there was a broken cable causing a loose contact.

After some searching, I found the solution here:
This can be solved by editing the pulseaudio configfiles as user root. First open the following file in your prefered texteditor as root:

In that file, locate the section “[Element PCM]”. On my Linux Mint 18.3 system, this looked like this:

Change this to the following:

 

 

The original article suggests to experiment with the volume-limit  value but for me, this worked already perfectly. So I did not invest too much time validating this.
I’d love to provide additional details on what these parameters are doing in detail actually, but the truth is that I could not find that info anywhere! I checked the comments in the source code, but these describe a completely different meaning for this:

Feel free to add this info to the comments and I will update this article.

The author of the original forums article which inspired the original article‘s author to his article mentioned additional measures:

Also, adding “ ignore_dB=1”:

load-module module-udev-detect ignore_dB=1

in ‘ /etc/pulse/default.pa’ (line 53~) and setting:

flat-volumes = no

in ‘ /etc/pulse/daemon.conf’ did make the volume control more usable for me.

I can only tell that I did not need any of these to make the issue go away, but maybe this is a valuable info in case this doesn’t work for you like it did for me.

After the changes are in place, you need to restart the PulseAudio daemon as your default user. You do not need to be root for this:

When I did that, my music stopped immediately and I could not make it work again without a restart of the system;  pulseaudio --start  did not work either. But since that restart of the system, I do not have any drops even at the lowest volumes anymore.

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

Header Image showing Django, Telegram, Heroku logos

In the previous part of this series, I explained how to register bots on Telegram, how to configure it and how to validate everything is working.

Today I will explain a bit more on how the HTTP API works, how the JSON data provided by the bots ist structured and I will introduce you to telepot, the Python module of my choice for interacting with Telegram bots using Python.

Continue reading “Create your own Telegram bot with Django on Heroku – Part 3”

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

Header Image showing Django, Telegram, Heroku logos

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.

Continue reading “Create your own Telegram bot with Django on Heroku – Part 1”