Developing a Money-Making Telegram Bot on Python — Pt 2. – Telegram 中文版

Telegram

Developing a Money-Making Telegram Bot on Python — Pt 2.

The Text Emoticon Bot

I really love it when people use emoticons in their bios. Not only does it give the person that edgy/retro feel, but also looks very funky in every conversation. Emoticons are emojis made of text symbols, here are a few:

Some very cool emoticons for you to enjoy xD

The Idea:

  1. The user would input the emotion they want — happy, angry, sad etc.
  2. The bot would output an emoticon that represents this emotion, that can bet then copied to just about anywhere.
  3. There is a ‘random’ function, that outputs a random emoticon
  4. Extension idea: the bot quizzes the user on their mood and outputs an emoticon that best matches it.

Okay, let’s get to the nits and grits!

How will we make it?

To make our lives simple, we will start with 3basic emotions: happy, angry and wtf. Next, we will create a database of emoticons that represent these emotions. Then, whenever the user will enter their emotion as a command, the bot will retrieve a random value from the appropriate column of the database. This will be displayed and ready for the user to copy and use!

First thing First

When working with a Telegram bot, a very important piece of information is the API token. You need to keep this safe and secure, to prevent anyone tempering with it. There is a super easy way to do this from virtually any code editor — store it in a JSON file that only you can access!

You can retrieve the API token as discussed in Part 1 of these series

Retrieving the API token from your file:

You can open the file and retrieve the API token from there

Great! Now that we have our details safe let’s get going!

Creating the Database

I want to first make a database of text-based emoticons (or find one if it exists). After a bit of searching, I could not find what I was looking for, so it’s time to create our own dataset!

We will use Python’s built in SQL editor to do this. There is a number of different ways, but after running into lots of errors with cursors at this stage (basically what allows you to navigate the SQL database), I decided to go with the old and trusted built in version.

  • Connect to the ‘emoticon’ database:
  • Create the main_table within the dataset:
  • Now we insert the appropriate values into the table. These are the emojis and the emotions associated with them.
  • Now if we select all of the values in the table, we get the following output:
The resulting table with the 3 emotions we get
  • It’s time to create the main function of our bot. The bot will receive a command from the user, stating what emotion they want. The bot will then output the emoji with the corresponding emotion from the table. Let’s see this in action:
An important thing to note here is the print(angry[0]) statements. This is because the .fetchall() statement returns a list value, from which the first element needs to be retrieved

Main Program Code

Yey! We now have the complete version of the program code. The logic of this is: there are commands defined above to retrieve the appropriate values from the SQL table. Whenever the user sends a command to the bot, the bot would output the emoji from the table associated with this value.

Here is what it looks like in action:

The Emoticon Bot MVP trying its best…

The Next Steps

Now that we have the main part of the project, it’s time to plan out the next steps:

Aesthetic improvements:

  • Adding a ‘greetings’ message explaining the bot’s functionality and purpose, as well as how it works
  • Making commands

Technical improvements:

  • Making a larger database and a wider spectrum of emotions. I will either try to find a database of text-based emoticons, or try to create one myself. Perhaps through web scraping or extracting emojis from various websites.

That’s it for now, folks! Stay tuned for part 3, where I will implement the changes described above and launch my very fist bot on Telegram. Have a great day!

Ten articles before and after

Best Autoresponder for Telegram to set auto reply messages – Telegram 中文版

Day 4,5,6 – Telegram 中文版

data-rh=”true”>Ixinium (XXA) Official Telegram Channel – Ixinium (XXA) – Medium – Telegram 中文版

Build an e-commerce telegram web app bot? – Telegram 中文版

CROWD Ask Me Anything with FCM. Segment 1 – Telegram 中文版

Let’s Make A Telegram Bot With Node.js – Telegram 中文版

1097+ Best Telegram Group Join Links List Updated – Telegram 中文版

Create your beautiful sticker pack in Telegram using Figma – Telegram 中文版

Pro-Kremlin Telegram channels promote narrative that Poland will annex western Ukraine – Telegram 中文版

Выходные с книгой. Рассказываем. Вып. 253 – Telegram 中文版

About Me

Pretium lorem primis senectus habitasse lectus donec ultricies tortor adipiscing fusce morbi volutpat pellentesque consectetur risus curae malesuada dignissim lacus convallis massa mauris.