I have joined a certain telegram channel with two different telegram accounts. I run the below code to start both sessions using pyrogram and print the received message. But I noticed that when a message was received on the telegram channel only one of them printed and the other didn’t. However when I tested using my own test telegram channel I couldn’t repro the issue, i.e., both the sessions printed the message on the test channel. I’m at a loss why the problem happens with the other channel. Both the numbers are subscribed to the channel. What would possibly cause this behavior?
#!/usr/bin/python3
from pyrogram import Client, filters, idle
from pyrogram.handlers import MessageHandler
import config
from pytz import timezone
from datetime import datetime
import requests
import asyncio
CHANNEL_ID = -1000123456789
def india_number_handler(client, message):
message_handler('india_number', message)
def uk_number_handler(client, message):
message_handler('uk_number', message)
def message_handler(session_name, message):
if message.sender_chat is not None and message.sender_chat.id == CHANNEL_ID and message.text is not None:
print(datetime.now().strftime('%d-%m-%Y-%H:%M:%S-%f') + ': ' + session_name + ' received channel message: ' + message.text, flush = True
async def main():
app = Client("india_number", api_id=config.getEnv("api_id"), api_hash=config.getEnv("api_hash"))
app_uk = Client("uk_number", api_id=config.getEnv("api_id"), api_hash=config.getEnv("api_hash"))
app.add_handler(MessageHandler(india_number_handler))
app_uk.add_handler(MessageHandler(uk_number_handler))
await app.start()
await app_uk.start()
await idle()
await app.stop()
await app_uk.stop()
asyncio.run(main())