I am using the method send_message
from Pyrogram to send messages to our users on Telegram. Sometimes it takes a while to finish its execution (up to 15 seconds) and some other times it works really fast (less than 1 second).
Is it a characteristic of the Telegram MTProto API or is there a way to keep the send_message
method always fast?
Note: Tgcrypto is installed
Below is a code snippet showing the script:
from pyrogram import Client
app = Client(
settings.TELEGRAM_BOT_NAME,
api_id=settings.TELEGRAM_API_ID,
api_hash=settings.TELEGRAM_API_HASH,
bot_token=settings.TELEGRAM_BOT_TOKEN,
in_memory=True
)
with app:
while True:
msg = Message.objects.next_to_send()
response = app.send_message(msg.contact._id, msg.text) # Might take a while.
sleep(2)
On every 2 seconds the script looks for a new message in our Database and send it to Telegram.
Thanks in advance,
Rhenan