printf "Content-Type: text/plain\n\n" input=$(cat /dev/stdin) token=1493641835:AAGR7kLksUIjcrM-PXiVEM_yxLGqLGRWKZA cmd=$(jq -r '.message.text' <<< $input) chat=$(jq -r '.message.chat.id' <<< $input) sendmsg(){ curl -sX POST "https://api.telegram.org/bot$token/sendMessage" \ -d "chat_id=$chat" -d "parse_mode=markdownv2" -d "text=$1" } alive(){ sendmsg "Alive and well\!" } stat(){ total=$(grep MemTotal /proc/meminfo | awk '{print $2}') avail=$(grep MemAvailable /proc/meminfo | awk '{print $2}') used=$(bc <<< "$total-$avail") sendmsg "I am using $used KB of memory\." } case "$cmd" in /alive*) alive ;; /stat*) stat ;; esac