Skip to content

Instantly share code, notes, and snippets.

@sokil
Last active June 26, 2022 23:42
Show Gist options
  • Save sokil/091296778755c9d90550d1e2ea26515d to your computer and use it in GitHub Desktop.
Save sokil/091296778755c9d90550d1e2ea26515d to your computer and use it in GitHub Desktop.
Telegram Bot / Send message

Links

Available Methods

Send message

  1. Open https://telegram.me/botfather and create bot
  2. Get messages from your bot: https://api.telegram.org/bot<Bot_token>/getUpdates
  3. Get chat id from response result.$.message.chat.id
  4. Send message to bot: https://api.telegram.org/bot<Bot_token>/sendMessage?chat_id=<chat_id>&text=hello

Message with buttons:

https://api.telegram.org/bot<Bot_token>/sendMessage?chat_id=-<chat_id>&text=hello&reply_markup={"inline_keyboard":[[{"text":"button","url":"https://pravyysektor.info"}]]}

Get bot info

https://api.telegram.org/<Bot_token>/getMe

Отримання chat_id

Для групи

Ідемо в веб-версію і переходимо в групу. Отримуємо урл https://web.telegram.org/#/im?p=g{chat_id}.

Chat_id = -{chat_id}

Для канала

Ідемо в веб-версію і переходимо в групу. Отримуємо урл https://web.telegram.org/#/im?p=c{chat_id}_1111111111111.

Chat_id = -100{chat_id}

Для приватного чата з ботом

  • Стартуємо чат з ботом, пишемо йому повідомлення.
  • Отримуємо повідомлення https://api.telegram.org/bot<Bot_token>/getUpdates
  • Шукаємо в відповіді сервера повідомлення, яке ми надіслали, і звідтри отримуємо char_id = result.$.message.chat.id

Posting from bot to chat

  • Add bot to chat as administrator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment