How To Make Money From Telegram In 2022 Unique Earning Way

Making $300 Per Month With A Telegram Bot?

Making $300 Per Month With A Telegram Bot?

A few weeks ago I stumbled across this YouTube video by H-Educate and it blew my mind. The guy bought the PHP script of a URL shortener service, host it on his own website, and made hundreds of dollars by doing nothing.

So I decided to give it a shot and see whether I can actually make some real cash from providing a URL shorter service or not. However, my major problem was that I didn’t want to spend $30 on buying the script and whatsoever. Therefore, I started searching for some APIs that would allow me to shorten unlimited URL links free of charge or at least at a minimal cost.

I found a couple of websites like Bitly or Rebrandly but both of them had imposed limits on the number of URL links you can shorten (via their APIs) and when you surpass the limit you will be charged. This didn’t work for me since I wanted to keep the project as cost-effective as possible. After a little bit of more research I came across cuttly, one of the greatest websites that not only allows you to shorten as many links as you want for $0 but also let you keep track of your URLs and view their stats (see how many people clicked on your shortened link).

Creating the Bot

The next thing I had to deal with after choosing the cuttly API, was a way to present my service. Should I create a website, a mobile app, or a social media bot? Personally, my go-to option was to create a Telegram bot. I had created a lot of advanced Telegram bots previously and it’s an effortless job for me.

I am not going to explain the codes of the bot because It’s not what this article is intended for. Instead, I’ll mention the Python libraries I used for those who are interested:

  • python-telegram-bot (to access Telegram)
  • requests (to access Cuttly)
  • redis (to access Redis database)

The GIF below shows the bot’s functionality:

A preview of the URL Cutter Telegram bot — Shorten your URL and view its stats

At this point you might ask:

“Then how do you make money ?”

In answer to this question, every bot user can shorten 10 URL links for free. Once they reach the limit, they are asked to upgrade their account. The subscription is worth $1 for Life-Time access which is a quite reasonable price for such a service. By clicking on the “Upgrade ⭐️” button in the bot, a Stripe invoice is sent to the user and they can pay directly through Telegram (one of the coolest features of Telegram!). See the pictures below:

Pay the subscription fee through Telegram

This is all you needed to know about how I integrated the URL shortening service into a Telegram bot. In the next section, I’ll explain where I got my users from.

Finding Client

Let’s say my service functions flawlessly and is ready to be used, but where do I actually get my users from and how should I convince them to use it?

Unfortunately, neither I am an expert in marketing nor do I have the budget to advertise my services. So I went for the old-fashion method of advertising; posting ads on Reddit, Facebook, and of course, Telegram group chats.

In the first 7 days, I received a handful of users. I was kind of sure that this project is a failure.

The second week is when things changed. A lot of people started using the bot and every 1 hour I had roughly 5 new registered users. My theory is that the very early users shared the bot with their friends and it just became the word of mouth. Users brought new users.

At the time that I am writing this article, my Telegram bot has around 500 VIP users (users who have upgraded their subscription) and my earning to this date is approximately $300 per month. All passive income!


How I made my first advanced telegram bot using python

I know it might sound a little too complicated to do but believe me, it’s not! This is How our Telegram bot will look like at the end of this blog.

The setup

In your project directory add the following files.

bot.py
requirements.txt
Procfile

The bot.py file as you may guess from its name is the python file in which we will code the logic of our bot. On the other hand, the requirements.txt file, as well as the Procfile, are the files that are needed for deploying the bot on Heroku servers. I will later discuss what each of these two files are responsible for. Note that the Procfile has no extension!

Programming the bot

As a starter, we will follow a raw template of a Telegram bot as shown below and build up our application on it.

It is very important to comprehend what the above code snippet does. In particular, we are creating two handlers. One command handler (def start()) and one message handler (def textHandler()). The start() function is executed every time a user sends the /start command in the Telegram chat. And the textHandler() function is executed every time a text message is sent to the bot. In the case of our application, we don’t want the user to send any kind of text. In fact, we only want to accept texts that are of type URL. That’s why we added the following if statement to the def textHandler():

if update.message.parse_entities(types=MessageEntity.URL)

Now that we have learned the basics of our bot, it’s time to figure our a way to get the download link of the URL that the user sends. There are two possible methods to tackle this problem. The old-fashioned method is to create a web scrapper that goes to that specific URL and downloads the contents. However, this method is not the most efficient method as it requires a lot of RAM and is slow. Thus, we will stick to the new-fashioned method that is using public APIs which does this job for us. More specially, there are bunch of free APIs out there which provide us the download link to almost any video URL. Note that it depends on which websites the API supports.

For the purpose of our application we are going to use the “get-video-and-audio-url” API . You can find the documantion of the API here.

So what we just did was to add a new function to our file called def get_Download_URL_From_API(url). This function takes one url parameter and passes this url to the API. Then, the API return a json response that contains data such as the title, website, upload_date, duration, format and last but not least the download url of the video. Bear in mind that the the structure of json data varies from API to API so it is important to take a look at the json response of the API and see where the data you are looking for is located. We are looking for the download url and this can be accessed via:

data[‘streams’][0][‘url’]

To recap the code, every time a user sends a text message and it’s of type URL , we are going to call the get_Download_URL_From_API(url) function passing the user’s url message as a parameter to this function. This function will then send a get request to the API and ask for the download url of the video and return it to the user. That’s it! As simple as that! Let’s take a look out how the bot operates to this point.

Feel free to add more features to the code such as printing the title, duration, number of views, etc so it look more professional like the video I showed you in the beginning of the blog.

Deploy the bot on Heroku

At this point we need to make small changes in the bot.py file. We first import os, and then set the port number to listen in for the webhook.

import os
PORT = int(os.environ.get('PORT', 5000))

Then, modify the following line from

updater.start_polling()

to

updater.start_webhook(listen="0.0.0.0",
port=int(PORT),
url_path=TOKEN)
updater.bot.setWebhook('https://yourherokuappname.herokuapp.com/' + TOKEN)

If you wonder why we switched from long polling to webhook, it’s simply because long polling frequently requests Telegram servers to update the status of the bot which is very inefficient. Whereas webhook that is triggered one a new message is sent to the bot. If you want to learn more about webhook versus long pollin please read this article.

Now let’s deal with the Procfile and the requirements.txt file that I mentioned earlier in the blog. The Procfile is a file that specified the commands that are executed by the app on startup. So add the following line to your Procfile

web: python3 bot.py

In simple words, the above line tells the Heroku server to execute the bot.py file.

Likewise, the requirements.txt file tells the Heroku servers what dependencies are needed in order to be able to run the the bot.py file. To generate the requirements.txt file simply redirect to your project directory and write the following command in your cmd or terminal:

pip freeze > requirements.txt

Now we have everything needed but before we get to deploying our bot on Heroku, make sure you to publish everything to your Github repository.

Login to your Heroku account -> Create new app -> Connect your Github repository to your Heruko account > Deploy your bot

read this article for more info on how to deploy a Telegram bot on Heroku

Congratulations you have made it!

*

Post a Comment (0)
Previous Post Next Post