如何使用 Telegram 机器人获取频道更新 [英] How to get channel updates with Telegram robot

查看:80
本文介绍了如何使用 Telegram 机器人获取频道更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经搜索了 Telegram API 和 Bot API 文档好几天了,似乎没有直接的方法让机器人在频道(例如新闻频道、体育频道等)有新更新时收到通知.我唯一想到的是:仅当机器人是管理员成员时,钩子才会返回频道更新:

I have searched over Telegram API and Bot API docs for days and it seems there is no direct way for a robot to get notified when there is a new update in a channel say a News channel, Sports channel, etc. The only thing I came up with was: A hook returns updates for channel only when the robot is an administrator member:

{
  "update_id": 673009340,
  "message": {
    "message_id": 160,
    "from": {
      "id": 104911111,
      "is_bot": false,
      "first_name": "Jason",
      "username": "jason",
      "language_code": "en-US"
    },
    "chat": {
      "id": -252946114,
      "title": "jason",
      "type": "group",
      "all_members_are_administrators": true
    },
    "date": 1538468757,
    "photo": [
      {
        "file_id": "AgADBAADFa4xG972mVHqJ-CSWQTFky4lnRoABNEgOrZpJU-OyDgFAAEC",
        "file_size": 1795,
        "width": 90,
        "height": 90
      },
      {
        "file_id": "AgADBAADFa4xG972mVHqJ-CSWQTFky4lnRoABB4OwmYVnYcOyTgFAAEC",
        "file_size": 32559,
        "width": 320,
        "height": 320
      },
      {
        "file_id": "AgADBAADFa4xG972mVHqJ-CSWQTFky4lnRoABIZfLEHYC_NVyjgFAAEC",
        "file_size": 159833,
        "width": 770,
        "height": 770
      }
    ]
  }
}

我知道我无法将机器人添加到不属于我的频道.但是,我几乎可以将我的用户名 jason 添加到任何频道.那么,当有可用于 jason 的新更新时,有没有办法让我的 jason_bot 得到通知?

I know that I cannot add a robot to a channel that is not owned by me. But, I can add my username jason to almost any channel. So, is there a way I get my jason_bot to be notified when there's a new update available for jason?

推荐答案

机器人不能与频道交互,除非他们是频道的管理员之一.

如果您想从其他人的频道接收更新,您必须充当客户端用户而不是机器人.如果您以会员身份加入频道,则可以轻松接收更新.但是,您无需成为会员即可查看任何公共频道的更新.首先,您解析频道@username 并获得 (id, access_hash) 对.然后,您可以访问所有消息,并手动检查您的数据库是否有新消息.

If you want to receive updates from some one else's channels you must act as a client user not a bot. If you join the channel as a member, you can easily receive updates. However, you can check for updates of any public channel without being a member. First, you resolve the channel @username and get (id, access_hash) pair. Then, you can access all messages, and manually check against your database if there is something new.

这篇关于如何使用 Telegram 机器人获取频道更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆