SHARE
TWEET

Untitled

a guest Jun 24th, 2019 127 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/sh
  2. # POSIX
  3.  
  4. show_help() {
  5. echo "Telegram Sender"
  6. echo ""
  7. echo "usage: [FILENAME] [FILETYPE]"
  8. echo ""
  9. echo "  -t,--token      Provide Telegram bot token"
  10. echo "  -c,--chatid     Provide ID to Send to"
  11. echo "  -f,--file       File to send"
  12. echo "  -a,--audio      Send as Audio File"
  13. echo "  -v,--voice      Send as Voice File"
  14. echo "  -d,--document       Send as Document aka any filetype"
  15. echo "  --text          Text to Send"
  16. echo ""
  17. echo "  Examples:"
  18. echo "  telegram --text \"TEST\" -c 1111111 -t BoTtOkEn"
  19. echo "  telegram -f /somefile -d -c 111111 -t BoTtOkEn"
  20. echo ""
  21. }
  22.  
  23. URL=https://api.telegram.org/bot
  24.  
  25. FILE=
  26. SETTYPE2=
  27. TYPE=
  28.  
  29.  
  30. verbose=0
  31.  while :; do
  32.    case $1 in
  33.         -h|-\?|--help)
  34.              show_help;  exit ;;
  35.     -f|--file)
  36.     if  [ "$2" ]; then FILE=$2; shift
  37.     else echo "ERROR: "--file" requires a non-empty option argument."; exit 1
  38.     fi ;;
  39.    
  40.     --text)
  41.     if  [ "$2" ]; then TEXT=$2; shift
  42.     else echo 'ERROR: "--text" requires a non-empty option argument.'; exit 1
  43.     fi
  44.     SETTYPE=""; SETTYPE2="Message"
  45.     ;;
  46.    
  47.     -d|--document)
  48.     SETTYPE="document"; SETTYPE2="Document"
  49.     ;;
  50.     -v|--voice)
  51.     SETTYPE="voice"; SETTYPE2="Voice"
  52.     ;;
  53.     -a|--audio)
  54.     SETTYPE="audio"; SETTYPE2="Audio"
  55.     ;;
  56.     -c|--chatid)
  57.         if [ "$2" ]; then CHATID=$2; shift
  58.         else echo 'ERROR: "--chatid" requires a non-empty option argument.'
  59.     fi
  60.         ;;
  61.     -t|--token)
  62.         if [ "$2" ]; then TOKEN=$2; shift
  63.         else echo 'ERROR: "--token" requires a non-empty option argument.'
  64.         fi
  65.         ;;
  66.     --)              # End of all options.
  67.         shift
  68.         break ;;
  69.     -?*)
  70.              printf 'WARN: Unknown option (ignored): %s\n' "$1" >&2; exit 1 ;;
  71.              
  72.     *)               # Default case: No more options, so break out of the loop.
  73.      break
  74.      esac
  75.      shift
  76. done
  77.  
  78. if [ "$TOKEN" = "" ]; then
  79.     echo 'ERROR: "--token" needed'
  80.     exit 1
  81. fi
  82.  
  83. if [ "$CHATID" = "" ]; then
  84.     echo "ERROR: "--chatid" needed"
  85.     exit 1
  86. fi
  87.  
  88. if [ "$SETTYPE2" = "" ]; then
  89.     echo 'ERROR: provide a Mediatype'
  90.     exit
  91. elif [ "$SETTYPE2" = "Message" ]; then
  92. echo "Sending Text Mesaage"
  93. elif [ "$FILE" = "" ]; then
  94.         echo 'ERROR: Provide a Filename with option "-f"'
  95.         exit 1
  96. else
  97. echo "Sending Media"
  98.     TYPE="-F $SETTYPE=@$FILE"
  99. fi
  100.  
  101.  
  102. /usr/bin/curl $TYPE "$URL$TOKEN/send$SETTYPE2?chat_id=$CHATID&parse_mode=Markdown&text=$TEXT"
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top