skip to Main Content

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?

2

Answers


  1. You haven’t mentioned the PHP code, but using CURL you can simply call:

    curl https://api.telegram.org/bot123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11/sendMessage?chat_id=1234&text=hi
    

    Replace 123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11 with your own bot token and 1234 with your id. Don’t forget to start the bot before messaging yourself.

    Login or Signup to reply.
  2. 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
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search