telegram-notify.sh 984 B

1234567891011121314151617181920212223242526272829
  1. #!/bin/bash
  2. # This program is free software: you can redistribute it and/or modify
  3. # it under the terms of the COMMON DEVELOPMENT AND DISTRIBUTION LICENSE
  4. #
  5. # You should have received a copy of the
  6. # COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0
  7. # along with this program. If not, see http://www.sun.com/cddl/cddl.html
  8. #
  9. # 2022 http://www.bananas-playground.net
  10. # this is a simple bash script witch accepts a text input as arg1 or pipe
  11. # and writes this text to your telegram chat
  12. # https://core.telegram.org/bots
  13. # https://core.telegram.org/bots#6-botfather
  14. BOTTOKEN="xxxxxxxxxxxxxxxx"
  15. CHAT_ID="xxxxxxxxxxx"
  16. URL="https://api.telegram.org/bot$BOTTOKEN/sendMessage"
  17. INPUT_TEXT="Something is ready..."
  18. if test -n "$1"; then
  19. INPUT_TEXT=$1;
  20. elif test ! -t 0; then
  21. INPUT_TEXT=$(</dev/stdin)
  22. fi
  23. curl -s -X POST -H 'Content-Type: application/json' -d '{"chat_id": "'${CHAT_ID}'", "text": "'"${INPUT_TEXT}"'", "disable_notification": false}' ${URL} > /dev/null 2>&1