2

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?

Mehdi Haghgoo
  • 3,144
  • 7
  • 46
  • 91
  • Jason can have update_listener and this listener can have bot api calls in itself. – tashakori Oct 10 '18 at 10:33
  • @tashakori do you mean web hooks by update_listeners? Because bot updates are delivered to hooks as far as I know. – Mehdi Haghgoo Oct 10 '18 at 11:39
  • No, I didn't mean bot webhooks. Take a look at Telethon library or any well-implemented Telegram core APIs. E.g. https://telethon.readthedocs.io/en/stable/extra/basic/working-with-updates.html – tashakori Oct 10 '18 at 11:46
  • @tashakori So, I guess Telethon does not use bots to get channel updates. It acts as a client that receives channel updates for the logged-in user. Is this right? By the way, I am using PHP. – Mehdi Haghgoo Oct 10 '18 at 12:00

1 Answers1

2

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.

Ali Hashemi
  • 3,158
  • 3
  • 34
  • 48