How to get channel updates with Telegram robot

爷,独闯天下 提交于 2020-05-29 21:11:56

问题


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
      }
    ]
  }
}

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?


回答1:


Bots cannot interact with channels unless they are one of the administrators of the channel.

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.



来源:https://stackoverflow.com/questions/52736324/how-to-get-channel-updates-with-telegram-robot

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!