Skip to content

Instantly share code, notes, and snippets.

@clementlecorre
Created October 26, 2017 15:20
Show Gist options
  • Save clementlecorre/ed7bfb38d2cd9253ffb004c1fb01c9a5 to your computer and use it in GitHub Desktop.
Save clementlecorre/ed7bfb38d2cd9253ffb004c1fb01c9a5 to your computer and use it in GitHub Desktop.
Example for my bash argparse
#!/bin/bash
TIMEOUT=10
# Telegram bot User info bot Python
# search bot @myidbot
ID=0
TOKEN=0
function usage()
{
echo "TelBot Sender"
echo ""
echo "get id user with @myidbot"
echo "get token with @botfather"
echo ""
echo -e "$0"
echo -e "\t-h --help"
echo -e "\t--token=$TOKEN"
echo -e "\t--id=$ID"
echo -e "\t--text=$TEXT"
echo ""
}
while [ "$1" != "" ]; do
PARAM=`echo $1 | awk -F= '{print $1}'`
VALUE=`echo $1 | awk -F= '{print $2}'`
case $PARAM in
-h | --help)
usage
exit
;;
--token)
TOKEN=$VALUE
;;
--id)
USERID=$VALUE
;;
--text)
TEXT=$VALUE
;;
*)
echo "ERROR: unknown parameter \"$PARAM\""
usage
exit 1
;;
esac
shift
done
URL="https://api.telegram.org/bot$TOKEN/sendMessage"
curl --data-urlencode -s --max-time $TIMEOUT -d "parse_mode=markdown&chat_id=$USERID&disable_web_page_preview=1&text=$TEXT" $URL > /dev/null
echo "Send $TEXT to $USERID"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment