Skip to content

Instantly share code, notes, and snippets.

@spac3unit
Forked from zmts/telegramChannelBot.md
Created October 21, 2021 20:34
Show Gist options
  • Save spac3unit/af8a3a40f4ad253b3ee2c8a2e470825d to your computer and use it in GitHub Desktop.
Save spac3unit/af8a3a40f4ad253b3ee2c8a2e470825d to your computer and use it in GitHub Desktop.
Используем Telegram канал в качестве системы оповещения

Используем Telegram канал в качестве системы оповещения

  • Создаем бота через глобального бота телеграма @BotFather
  • Создаем публичный канал через обычный клиент(desktop/mobile) с публичным именем
  • Добавляем бота в администраторы канала (с правами отправлять сообщения)
  • Отправляем тестовое сообщение в канал от имени только что созданного бота
#POST: https://api.telegram.org/bot<token>/sendMessage
{
  "chat_id": "@mysuperchannel",
  "text": "hello!!!"
}

В ответ получам

{
  "ok": true,
  "result": {
    "message_id": 10,
    "chat": {
      "id": -2222222222222,
      "title": "mysuperchannel",
      "username": "mysuperchannel",
      "type": "channel"
    },
    "date": 1520000117,
    "text": "hello!!!"
  }
}
  • Меняем канал на приватный
  • Для последующих запросов меням chat_id на result.chat.id из тестового ответа
  • В итоге имеем приватный канал для оповещения средстами обычного REST запроса
#POST: https://api.telegram.org/bot<token>/sendMessage
{
  "chat_id": "-2222222222222",
  "text": "hola !!!"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment