I have the following script, simple to send messages to Telegram from linux:
#!/bin/bash
USERID="XXXXXXXXXX"
KEY="ZZZZZZZZZ:YYYYYYYYYYYYYYYYYYYYYYYYYY"
URL="https://api.telegram.org/bot$KEY/sendMessage"
MSG="Mensaje de Prueba"
curl -s --max-time 10 -d "chat_id=$USERID&disable_web_page_preview=1&text=$MSG" $URL
The program doesn't give me an error, but I don't get the messages from the servers, I'm starting in the world of scripts, I hope you understand.
It is very interesting to use the Telegram API to monitor processes in Linux and whatever comes to mind.
In your script you are using the method
sendMessage
to send text messages but you are using it in the wrong way, you are omitting thechat_id
y variabletext
Correct method:
Wrong method:
I made some modifications to your script so that you have a Log where you can check the error returned by the API in case you can't send the message.
In this way the script should serve you, of course substituting what would be the USERID and KEY :
To use the script it is so simple to execute it as follows, passing it a parameter that in this case would be the text to send:
I leave you this link with the official information of the API
This English SO link
chat_id
shows you how to get the if you don't know it