Skip to content

Instantly share code, notes, and snippets.

@cuongnv23
Last active April 24, 2018 02:30
Show Gist options
  • Select an option

  • Save cuongnv23/13bdd4c89050dbb980ca14ac4ff3434b to your computer and use it in GitHub Desktop.

Select an option

Save cuongnv23/13bdd4c89050dbb980ca14ac4ff3434b to your computer and use it in GitHub Desktop.
How to get chat_id for Telegram bot
  1. Create telegram bot https://core.telegram.org/bots/api#authorizing-your-bot. Make sure the bot works as expected:
$ export TELEGRAM_TOKEN=your_token
$ curl -s https://api.telegram.org/bot$TELEGRAM_TOKEN/getMe
{
  "ok": true,
  "result": {
    "id": xxx,
    "is_bot": true,
    "first_name": "drone",
    "username": "cuongnv23_telegram_bot"
  }
}
  1. Create a group, add your bot to that group with admin right. Send any message to the group
  2. Get the chat_id:
$ curl https://api.telegram.org/bot$TELEGRAM_TOKEN/getUpdates -s | jq '.result[0].message.chat.id'
-xxx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment