skip to Main Content

I want to figure out the format of telegram bot tokens to implement some validity checks, but there seems not official format description.

from my token and what I have found on the net, I can assume the following:

  • (up to) 46 characters length
  • starts with (up to) 10 digits followed by :
  • the remaining 35 characters are of class [[:alnum:]] plus – and _

can anyone (dis) confirm or point to documentation?

3

Answers


  1. Chosen as BEST ANSWER

    Let me summarize what we know so far:

    • to verify that a telegram API token has the correct format AND is currently valid you must make a Telegram getMe API call, e.g. on command line: curl -s https://api.telegram.org/botYOURTOKEN/getMe

    Nevertheless, we have some good guesses what a correct token must look like:

    • it consists of 8-10 digits followed by a :
    • the : is followed by a 35 character Telegram internal identifier/hash
    • the identifier is consisting of character class [[:alnum:]] plus _-, this fit's the characters documented for the deep linking parameter

    Summary:

    • Token format: 8-10 digits:35 alnum characters plus _- , e.g. 123456789:AaZz0...AaZz9

    • Regex for testing: /^[0-9]{8,10}:[a-zA-Z0-9_-]{35}$/


  2. If you want to check validity of a bot’s token you can use the getMe method.

    https://core.telegram.org/bots/api#getme

    A simple method for testing your bot’s auth token. Requires no
    parameters. Returns basic information about the bot in form of a User
    object.

    Any non valid token will return 401 error.

    I believe this would be a more robust approach than checking for correct formats.

    Login or Signup to reply.
  3. The BOT token consists of two parts. In BOT_ID:BOT_ALPHANUMERIC_PART the BOT_ID is 8 to 10 digit long and the BOT_ALPHANUMERIC_PART has a length of 35 characters. So the total length is 43 to 45 characters.

    If you want to validate a bot token then you can use: https://api.telegram.org/bot< YOUR_BOT_TOKEN>/getMe.
    It will return the JSON data for your bot. It will throw a 401 error if the bot token is not valid.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search