telethonchat | Unsorted

Telegram-канал telethonchat - Telethon Chat

6097

Official Telethon's chat! Rules: • Speak English • Stay on topic (questions about Telethon) • Be respectful • Don't ask to ask • Spam-related uses lead to ban • Read https://docs.telethon.dev before asking things here Read more about us @TelethonUpdates

Subscribe to a channel

Telethon Chat

Hello everyone. How can I catch a session termination event?
I can except for ConnectionError or AuthKeyUnregisteredError, but they work only in 50% of cases when my session is terminated.
If they don't, I try to use .is_connected() and .is_user_authorized(), buy they are showing both True after termination, and if I try to do .get_me() (or actually any client-related method) it just hangs forever. No error, no response.

Читать полностью…

Telethon Chat

Like which part of my code should I implement this? Sorry I don't really know what catch_up is or how it works. Can you explain in greater detail?

Читать полностью…

Telethon Chat

Can you please advice what I can do to my existing code?

Читать полностью…

Telethon Chat

This is the current code I have. Is this the most optimized/right way of writing the code? Previously I was not using asyncio (just using client.start) but a member here recommended me to try it out. But the result is the same, still seeing delays in receiving message.


async def monitor_messages():
async with TelegramClient("session1", API_ID, API_HASH) as client:
# Define the event handler
@client.on(events.NewMessage(chats=SOURCE_CHANNEL))
async def handler(event):
if "Market Cap" in event.message.message:
try:
# Extract token contract address
contract_address = re.search(CONTRACT_REGEX, event.message.message).group(0)
# Construct and send the /buy command to the trading bot
command = f"/buy {contract_address} {BUY_AMOUNT}"
await client.send_message(GMGN_BOT_USERNAME, command)
except Exception as e:
logging.error(f"Error: {e}")

await client.run_until_disconnected()

if __name__ == "__main__":
asyncio.run(monitor_messages())

Читать полностью…

Telethon Chat

@disk6969 Hey sir. If you can recall, I have a similar use case over here where I need to detect new messages from a channel in real-time. You've mentioned switching to iter_messages is an option but has restrictive limits (i.e. unrealistic to be polling every second), and that using catch_up might be an option too. From my understanding, catch_up is intended for scenarios where the client might disconnect and you might want to process missed messages. But my purpose is focused on monitoring new incoming messages in real-time only. With that said, should I still try iter_message with a polling frequency of 1 second, or is that totally not recommended?

Читать полностью…

Telethon Chat

How to catch this exception?

Rn im using except telethon.exceptions.RPCError

Читать полностью…

Telethon Chat

How do I know if someone has read a message I sent to them in Telethon?
in pm

Читать полностью…

Telethon Chat

Thanks, but i fix it in this way:

# media = message.media
# self.obj = message

if isinstance(media, MessageMediaPhoto):
self.downloadMedia(f"P{self.obj.id}.jpg")
self.write(f"[ PHOTO ] - ({self.obj.id})")

Читать полностью…

Telethon Chat

Hey Juan Carlos Cautter, don't do that again (offtopic non-English) or I will ban you. You have been warned.

Читать полностью…

Telethon Chat

You don't 'need' to, unless it's imperative you create custom filename.. then prefer message.file.ext and message.file.mime_type and message.file.media.id

Читать полностью…

Telethon Chat

ah, it simply skips over already assigned ones

Читать полностью…

Telethon Chat

Can't we send messages in broadcast to users accepted by bot in chat join request?

Читать полностью…

Telethon Chat

MessageDeleted.Event doesn't contain any reference to the topic ID, only group ID, and topic msg IDs are not unique

there's no way to know from which topic a delete event originates from?

Читать полностью…

Telethon Chat

how to solve this problem?

Читать полностью…

Telethon Chat

Is there any way to detect media type?

This code always ends with an error

if self.obj.media.photo:
self.downloadMedia(f"P{self.obj.id}.jpg")
self.write("[ PHOTO ] - (self.obj.id)")

elif self.obj.media.voice:
self.downloadMedia(f"A{self.obj.id}.mp3")
self.write("[ VOICE ] - (self.obj.id)")

elif self.obj.media.video:
self.downloadMedia(f"V{self.obj.id}.mp4")
self.write("[ VIDEO ] - (self.obj.id)")

elif self.obj.media.document:
self.downloadMedia(f"D{self.obj.id}.mp4")
self.write("[ DOCUMENT ] - (self.obj.id)")

else:
self.downloadMedia(f"-{self.obj.id}")
self.write("[ FILE ] - (self.obj.id)")

Error:
'MessageMediaDocument' object has no attribute 'photo'

Читать полностью…

Telethon Chat

If I use that then I'll stick with using events.NewMessage?

Читать полностью…

Telethon Chat

same as you were adviced

Читать полностью…

Telethon Chat

It isn't solely for that. mainly when catch_up=True isn't passed to TelegramClient

Читать полностью…

Telethon Chat

/channel/TelethonChat/584288

Читать полностью…

Telethon Chat

But i want more specific exception

Читать полностью…

Telethon Chat

/channel/TelethonChat/594962

Читать полностью…

Telethon Chat

can we use https proxy with telethon?

Читать полностью…

Telethon Chat

you make a pull request if you want something added, providing the timeit benchmark code of old and new

but features aren't added in V1 telethon, but may be merged for V2

Читать полностью…

Telethon Chat

it only occurs when using proxy

Читать полностью…

Telethon Chat

Remember search is your friend

Читать полностью…

Telethon Chat

thanks bro, i just wanted to switch completely from pyro to tele thats why i asked,

Читать полностью…

Telethon Chat

it doesn't matter, there aren't changes in docs

Читать полностью…

Telethon Chat

is there 1.38.1 documentation or 1.37.0 is only last?

Читать полностью…

Telethon Chat

Server closed the connection: 0 bytes read on a total of 8 expected bytes

Читать полностью…

Telethon Chat

it should auto-reconnect, right? So what can the problem be?

Читать полностью…
Subscribe to a channel