【问题标题】:Telethon Get Update When Contact Join TelegramTelethon 在联系时获取更新 加入电报
【发布时间】:2021-04-23 01:41:13
【问题描述】:

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

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

你能帮帮我吗?

谢谢!!

【问题讨论】:

    标签: telethon telegram-api


    【解决方案1】:

    收听events.Raw 并对event 对象进行一些检查,该对象应类似于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()
    

    【讨论】:

      猜你喜欢
      • 2017-11-19
      • 1970-01-01
      • 1970-01-01
      • 2021-06-11
      • 1970-01-01
      • 2019-04-25
      • 1970-01-01
      • 1970-01-01
      • 2020-11-01
      相关资源
      最近更新 更多