Skip to content

Instantly share code, notes, and snippets.

Last active Jan 18, 2023
What would you like to do?
Sending a notification message to Telegram using its HTTP API via cURL
  1. Create a bot
  2. Get the bot's API token from @BotFather
  3. Add your bot to the chat you'll be sending messages to
  4. Get the ID of the chat
    a. Fetch bot updates and look for the chat id:
    curl$TELEGRAM_BOT_TOKEN/getUpdates | jq
    b. 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
  5. Send a message using the HTTP API:
    curl -X POST \
         -H 'Content-Type: application/json' \
         -d '{"chat_id": "123456789", "text": "This is a test from curl", "disable_notification": true}' \$TELEGRAM_BOT_TOKEN/sendMessage
# 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'
bot = TELEGRAM_BOT_TOKEN, logger:
bot.get_updates(fail_silently: true) do |message|
puts "@#{message.from.username}: #{message.text}"
puts "Chat-ID: #{}"
Copy link

Thanks for sharing this:
Also you can just use another curl to get the chat id instead of running this ruby code.<YourBOTToken>/getUpdates


Copy link

dideler commented Jun 16, 2019

Thanks for the tip @thilinapiy! I've updated the instructions.

Copy link


curl -s -X POST $URL -d chat_id=$ID -d text="Hello World"

Example, copy script to /usr/local/bin/



if [ "$PAM_TYPE" != "open_session" ]
	exit 0
	curl -s -X POST $URL -d chat_id=$ID -d text="$(echo -e "Host: `hostname`\nUser: $PAM_USER\nHost: $PAM_RHOST")" > /dev/null 2>&1
	exit 0

Add to end file /etc/pam.d/sshd

session    optional  /usr/local/bin/

Copy link

Is there anyone here please can explain how can you send a media file through HTTP request in telegram bot?

Copy link

dideler commented Nov 16, 2020

Copy link

yvikt commented Dec 12, 2020


Copy link

In Windows I use a small BAT with the help of UnxUtils:

SET ID_CHAT=-000000000
SET MESSAGE="Hello from my Windows"
curl -v -X POST --silent --output /dev/null %URL% -d chat_id=%ID_CHAT% -d text=%MESSAGE%

And in UNIX I use the following SHELL which works very well for me:

SET MESSAGE="Hello from my Solaris"
curl -X POST --silent --output /dev/null $URL -d chat_id=$ID_CHAT -d text="$THE_MESSAGE"
exit 0

You only have to change the Token of the BOT and the ID_CHAT.


Copy link

Dear friens, i need help. Is it possible send a notification message to Telegram using its HTTP API via cURL but using ptiority.normal or priority.low to get a message withouth buzz or get a message in silence mode? Thanks in advanced. Best regards.

Copy link

Yes see
add: -d disable_notification=true

Copy link

Yes see
add: -d disable_notification=true

Ohhh. thank you very much dear friend. Your answer was really useful for me. I have tried it and it works.

Would it be possible to deactivate the notification within a specific time via curl? This would be great for me, but I'm not sure if it would be possible. Thanks in advance. a cordial greeting

Copy link

I think at that moment you are either better of writing a shell script or writing it in another programming language

Copy link

dneprpi commented Sep 17, 2021

hi guys,
is it possible to get the bot's API token from @Botfather NOT through telegram but using some api?
I need to create bots automatically in my .net app

Copy link

This might be helpful if looking for cli examples

Copy link

xjustbmw commented May 4, 2022

is it possible to write "to" a telegram bot using http request ?
i managed to send the message to the chat_id it but appears in the chat as its written by the bot

Copy link

What a great, quick tutorial! Thank you!

Copy link

If you are getting an empty result list when doing getUpdates for your bot, kick the bot out of the group, invite again and fetch again.

Copy link

jogerj commented Oct 7, 2022

Very useful. Made a neat little script that you can import in bash. Adds a title/timestamp to it. Keeps me informed whenever my deployments need my attention.



send_telegram () {
    timestamp="$(date -R)"
    msg="$title\n$timestamp\n\n$(echo "$2" | sed -z -e 's|\\|\\\\|g' -e 's|\n|\\n|g' -e 's|\t|\\t|g' -e 's|\"|\\"|g')"
    data="{\"chat_id\":\"$CHAT_ID\",\"text\":\"$msg\",\"entities\":$entities,\"disable_notification\": true}"
    curl -s -o /dev/null -H 'Content-Type: application/json' -d "$data" -X POST$TELEGRAM_BOT_TOKEN/sendMessage

Import with source /path/to/ then can call the function each time you want to send a message like so send_telegram "title in bold" "this is the message body".
title in bold
Sat, 07 Oct 2022 00:24:57 +0100
this is the message body

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment