- Create a bot
- Gets its API token (via @BotFather)
- Get the ID of the chat
- Add your bot to the chat
- Fetch bot updates and look for the chat id:
curl https://api.telegram.org/bot$TELEGRAM_BOT_TOKEN/getUpdates | jq .message.chat.id
- OR, run bot.rb and @-mention your bot in the chat. The chat id will appear in
bot.rb
's output.
The bot may need temporary message access:@BotFather > Bot Settings > Group Privacy > Turn off
- Send a message via their HTTP API: https://core.telegram.org/bots/api#sendmessage
curl -X POST \ -H 'Content-Type: application/json' \ -d '{"chat_id": "123456789", "text": "This is a test from curl", "disable_notification": true}' \ https://api.telegram.org/bot$TELEGRAM_BOT_TOKEN/sendMessage
-
-
Save kirbsraspberrypi/f684a257470d7a760d93468d573069a4 to your computer and use it in GitHub Desktop.
Sending a notification message to Telegram (via cURL)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Use this script to test that your Telegram bot works. | |
# | |
# Install the dependency | |
# | |
# $ gem install telegram_bot | |
# | |
# Run the bot | |
# | |
# $ ruby bot.rb | |
# | |
# Send a message to the bot to get the current chat's ID in the console output. | |
# If it's a group chat, invite them to the chat first. | |
require 'logger' | |
require 'telegram_bot' | |
TELEGRAM_BOT_TOKEN = "YOUR_BOT_API_TOKEN" | |
bot = TelegramBot.new(token: TELEGRAM_BOT_TOKEN, logger: Logger.new(STDOUT)) | |
bot.get_updates(fail_silently: true) do |message| | |
puts "@#{message.from.username}: #{message.text}" | |
puts "Chat-ID: #{message.chat.id}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment