How to watch Telegram stories from Python

Masslooking, Masswatching or Mass story viewing. This was quite popular marketing strategy on Instagram couple years ago when they launched Stories. At that time, it was quite easy to watch up to million (!) stories each day.

Recently, Telegram introduced the Stories feature as well. Let's write a code that will log into our Telegram profile and watch stories of users.

Masslooking strategy

You need to find out users with stories. This can be achieved by multiple ways but in this article I'll show the basic strategy:

  1. Find out all public chats you're in (because you can see the participants list)
  2. Filter ones with stories and watch them!

Telegram Story Masswatching with Telethon

Telethon is a great python library that emulates the Telegram client which can be automated with async python scripts.

Find comments in the snippet below to understand the code better:

from telethon import TelegramClient
from telethon import types, functions

api_id, api_hash = "", ""  # get yours on my.telegram.org
client = TelegramClient("masslooking", api_id, api_hash)

# iterate over all chats your TG account has
async for dialog in client.iter_dialogs(limit=500):

	# you can see participants of a public chat
    if dialog.is_group:
 		
        async for user in client.iter_participants(
        	entity=dialog.entity, 
            limit=1000
        ):
        	# check if a person has active stories
            if (
                not user.stories_unavailable and 
                not user.stories_hidden and 
                user.stories_max_id
            ):
                res = await client(
                    functions.stories.ReadStoriesRequest(
                        user_id=user.id, 
                        max_id=user.stories_max_id
                    )
                )

You can also find this snippet on Github Gist.

If you want to improve this script, you may want to add time.sleep(random.random() * m + n) to prevent from Rate Limiting and BAN. Also you can add a logging to make something like a CRM system to measure the results of this "telegram marketing campaign".

How to measure the effectiveness

You can watch hundreds of thousands stories each day but what for? You need a metric that will show you if this marketing strategy works for you.

In Telegram case you can measure the "conversion" to your telegram channel (if you put a link in bio). In that case you can find a % of users that follows your channel after you watched their stories. The similar thing can be done with a conversion to your DMs.

To check if a user follows your channel, you can use sync for res in client.iter_participants("https://t.me/danokhlopkov", search=target_user_id). To check if a user DM'ed you: client.iter_messages(target_user_id).


Hope this was useful! Please share this article and follow me on Twitter and on Telegram (rus blog).