Skip to content

Instantly share code, notes, and snippets.

@parrazam
Created May 25, 2020 09:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save parrazam/21904a4789942b8fbc038ee8235a14e4 to your computer and use it in GitHub Desktop.
Save parrazam/21904a4789942b8fbc038ee8235a14e4 to your computer and use it in GitHub Desktop.
Publish message to a Telegram bot
#!/bin/bash
if [[ $# -ne 1 ]]
then
echo "\nSe requiere un mensaje para enviar. Ejemplo de uso: $0 \"Mensaje de prueba\""
exit 1
fi
source /home/$USER/.tg_keys
MESSAGE=${1// /+}
URL="https://api.telegram.org/bot$API_KEY/sendMessage?chat_id=$CHAT_ID&text=$MESSAGE&parse_mode=Markdown"
curl -i -H "Accept: application/json" -X GET -g $URL
if [[ $? -eq 0 ]]
then
echo "\nMensaje $1 publicado."
else
echo "\nError al publicar el mensaje. Consulta el log para más detalle."
exit 2
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment