Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- timeout=10
- token=TOKEN
- chat_id=CHAT_ID
- json_s="https://api.telegram.org/bot$token/sendMessage -d chat_id=$chat_id"
- # initial message
- curl -s -X POST https://api.telegram.org/bot$token/sendMessage -d chat_id=$chat_id -d text="start" &> /dev/null
- sleep 2
- curl -s -X POST https://api.telegram.org/bot$token/sendMessage -d chat_id=$chat_id -d text="enter commands" &> /dev/null
- json_r_init="https://api.telegram.org/bot$token/getUpdates"
- json_r="https://api.telegram.org/bot$token/getUpdates?offset="
- wget "$json_r" -q -O jsontest_init
- counts_init=0
- counts_init=$(cat jsontest_init | jq -r '.result | length')
- upd_id_init=$(cat jsontest_init | jq ".result[$counts_init-1].update_id")
- upd_id=$upd_id_init
- wget "$json_r"$upd_id_init -q -O jsontest0
- counts=0
- counts=$(cat jsontest0 | jq -r '.result | length')
- while true
- do
- wget "$json_r"$upd_id -q -O jsontest1
- if [ $(stat -c %s jsontest0) -ne $(stat -c %s jsontest1) ]; then
- counts=$(cat jsontest1 | jq -r '.result | length')
- cmd=$(cat jsontest1 | jq ".result[$counts-1].message.text")
- upd_id=$(cat jsontest1 | jq ".result[$counts-1].update_id")
- wget "$json_r"$upd_id -q -O jsontest0
- result=$(bash -c \""$cmd"\")
- if [ $? -eq 0 ]; then
- echo "Success"
- curl -s -X POST https://api.telegram.org/bot$token/sendMessage -d chat_id=$chat_id -d text="$result" &> /dev/null
- fi
- #else
- # echo "no command"
- # curl -s -X POST https://api.telegram.org/bot$token/sendMessage -d chat_id=$chat_id -d text="$upd_id" &> /dev/null
- fi
- sleep $timeout
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement