Search code examples
windowscurltelegramcommand-prompttelegram-bot

Telegram example of how to use CURL for windows 10 to message myself with a bot


I found the following curl example to use a telegram bot to message a user. But that is written in PHP.

Is there an example of how to use the curl command in windows 10 command prompt to send a message to myself in telegram messenger?


Solution

  • Those who landed here due to above method is not working anymore -> you can use curl POST request like the following:

    curl -s -o /dev/null -X POST -H "Content-Type: application/json" -d "{\"chat_id\": \"-100XXXXXXXXXX\", \"text\": \"test_message\", \"disable_notification\": false}" https://api.telegram.org/bot{API_TOKEN}/sendMessage
    

    Where

    • -s - Silent mode,
    • -o /dev/null - redirect result output to nowhere, in case where the command is not working remove the argument to find possible cause,
    • disable_notification: false - send the message silently without telegram notification.

    For those who really likes .bat/.sh scripts there is an option to put the command into a .bat/.sh script, replace test_message with %~1/$1 placeholders respectively and execute the script with message argument like:

    . ./sendMessage.sh "Specific message having spaces"
    

    or

    . ./sendMessage.sh singleWordWithoutSpaces