Telethon 在联系人加入 Telegram 时获取更新

Telethon Get Update When Contact Join Telegram

我正在使用 Telethon 并且我正在尝试实现一个处理程序来监听我的联系人加入 Telegram 时的事件,但我没有找到任何相关文档。

我看到了 telethon 更新事件的文档 Telethon Doc - Update Events 但我找不到过滤此特定事件的方法。现在,当您的任何联系人加入电报并创建聊天时,Telegram 会发送推送通知,所以我认为应该有一个事件来标记此

你能帮帮我吗?

谢谢!!

events.Raw and do a few checks on the event object that should look like this.

import asyncio
from telethon import TelegramClient, events
from telethon.tl.types import MessageActionContactSignUp, UpdateNewMessage

client = TelegramClient('YOUR_SESSION_NAME', 'YOUR_API_ID', 'YOUR_API_HASH')
client.start()

@events.register(events.Raw)
async def contact_join(event):
    if isinstance(event, UpdateNewMessage) and isinstance(event.message.action, MessageActionContactSignUp):
        print(event.message.from_id) #show the id of the contact joined

loop = asyncio.get_event_loop()
client.add_event_handler(check_join)
loop.run_forever()