Loading...
 

Get Chat IDs

 
If you would like to send messages via MQL Telegram you need to find out the specific chat IDs of your message targets. Those might be private chats (e. g. 142365464), group chats (e. g. -365832235) or channels (e. g. -1001167825734).

Requirements:

  • You need to create a bot.
  • Start a conversation with your bot
    • For private chats: Search your bot in the global contact list, hit /start and maybe send a second message. The content does not matter. The point is to send a message (see the picture below).
    • For group chats: Invite your bot as a member into a new or existing group via global contact search. You might enable options of the Privacy mode to receive more types of messages. See the Telegram documentation for more information. Then send a message like in the private chat instructions.
    • For channels: If you just want to receive messages you need to invite your bot as a member into the channel. If you would like to send messages to the channel you need to add the bot as administrator. Then send a message like in the private chat instructions.

2019 09 13 07 46 53 Telegram (1009)

When this is done you need to receive these message to detect the chat IDs. In the simplest scenario you enter this URL into your browsers address field: 

https://api.telegram.org/bot_token/getUpdates


The URL will look like the following after replacing the token with yours:

https://api.telegram.org/bot123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11/getUpdates


The Response from the Telegram API will be a JSON string you can investigate. What you're looking for is the ID in the following examples (in private chats the private id is the same as the chat id):

Private chat:

{
      "update_id": 146878178,
      "message": {
        "message_id": 1352,
        "from": {
          "id": ID,
          "first_name": "stzzzzz",
          "username": "stzzzzz"
        },
        "chat": {
          "id": ID,
          "first_name": "stzzzzz",
          "username": "stzzzzzz",
          "type": "private"
        },
        "date": 1486291815,
        "text": "some text here with a url https://123.com",
        "entities": [
          {
            "type": "url",
            "offset": 0,
            "length": 44
          }
        ]
      }
}

 

Group chat:

{
      "update_id": 146878181,
      "message": {
        "message_id": 1353,
        "from": {
          "id": PRIVATE ID,
          "first_name": "stzzzzz",
          "username": "stzzzzz"
        },
        "chat": {
          "id": ID,
          "title": "MQL Group",
          "type": "group",
          "all_members_are_administrators": true
        },
        "date": 1486296142,
        "group_chat_created": true
      }
}

 

Channel chat:

{
      "update_id": 14646546,
      "channel_post": {
        "message_id": 2,
        "chat": {
          "id": ID,
          "title": "testing channel",
          "type": "channel"
        },
        "date": 1486292382,
        "text": "test"
      }
}