How I made a simple survey bot

How I made a simple survey bot

Main
Goals
Solution
Result

And what you should know before you start developing your own bot

There was no trouble at all when I was creating this bot. Aiogram's documentation is good. I would say exhaustive. Asynchronousness didn't cause as many problems as I expected. And the template for displaying results is my favorite part.

The only thing I've had trouble with is translation for English-speaking users. I caught up too early, and I didn't want to rewrite the bot completely from scratch. Therefore, we have only a Russian-language bot.

Goals

  • Deploy bot on VPS
  • Implement changing the bot's answers dynamically.
  • Implement a template for displaying quiz results.

Solution

Dynamic bot's messages

After implementing the sequential logic of the bot ( questions are asked one by one ), I started to implement the dynamic change of the bot's answers when choosing the format of the data display (in percent or in absolute numbers).

inlineKeyboardButton for settings | Tim the webmaster

While diving into the aiogram's documentation, I found the method I needed. And I actually solved one of the tasks.

Result template

Next, I wrote a normal text file. And I added markers (these are special words that I could stick to when generating results).

Text wit markers for python | Tim the webmaster

Template for result displaying by bot | Tim the webmaster

Deploying bot on VPS

It was my first time deploying bots. I would therefore like to thank the author for this article and the website. He showed me the right way to do this.

The essence of this decision is that you rent virtual hosting. 

Create a script and a deamon (a process that would automatically run the bot when the server restarts).

You start and forget. The bot will not need to be modified yet. (It will need to be reloaded personally before the changes come into effect.)

Translation

Now to the translations. I decided to use my familiar Python package to generate translation files. The same package for internationalization is used by Django.

But after a day of trying to translate all the lines (partial translation I managed to do), I gave up and published the bot not internationalized. Shame on me.

You just need to allocate free time and deal with all the nuances.

Result

All existing tasks I've completed, excluding internationalization

And the results you can check for yourself by entering TimQuizzer in the telegram search field.

Or by a link in the browser: https://t.me/TimQuizzerBot

Additional materials


heart 1
3 connected dots 0