mirror of
https://github.com/octoleo/telegram-bot-bash.git
synced 2025-01-27 23:58:24 +00:00
fix running commands.sh in subshell
This commit is contained in:
parent
5a0a5712dd
commit
079eb1c289
@ -30,7 +30,7 @@ BOTCOMMANDS="-h help init start stop status suspendback resumeback killb
|
|||||||
# 8 - curl/wget missing
|
# 8 - curl/wget missing
|
||||||
# 10 - not bash!
|
# 10 - not bash!
|
||||||
#
|
#
|
||||||
#### $$VERSION$$ v1.35-dev-21-gcbf3945
|
#### $$VERSION$$ v1.35-dev-24-g5a0a571
|
||||||
##################################################################
|
##################################################################
|
||||||
|
|
||||||
# emmbeded system may claim bash but it is not
|
# emmbeded system may claim bash but it is not
|
||||||
@ -707,7 +707,7 @@ process_client() {
|
|||||||
# process inline and message events
|
# process inline and message events
|
||||||
# first classic command dispatcher
|
# first classic command dispatcher
|
||||||
# shellcheck source=./commands.sh
|
# shellcheck source=./commands.sh
|
||||||
"${COMMANDS}" "${debug}" &
|
{ source "${COMMANDS}" "${debug}"; } &
|
||||||
|
|
||||||
# then all registered addons
|
# then all registered addons
|
||||||
if [ -z "${iQUERY[ID]}" ]; then
|
if [ -z "${iQUERY[ID]}" ]; then
|
||||||
|
@ -249,7 +249,7 @@ If `"url"` without text is given, `url` is shown on the button and opened on but
|
|||||||
*example:*
|
*example:*
|
||||||
```bash
|
```bash
|
||||||
# one button, same as send_button
|
# one button, same as send_button
|
||||||
send_inline_keyboard "${CHAT[ID]}" "Best Dealz!" "Visit my Shop|https://dealz.rrr.de"
|
send_inline_buttons "${CHAT[ID]}" "Best Dealz!" "Visit my Shop|https://dealz.rrr.de"
|
||||||
|
|
||||||
# result
|
# result
|
||||||
Best Dealz!
|
Best Dealz!
|
||||||
@ -258,7 +258,7 @@ send_inline_keyboard "${CHAT[ID]}" "Best Dealz!" "Visit my Shop|https://dealz.rr
|
|||||||
+----------------------------+
|
+----------------------------+
|
||||||
|
|
||||||
# one button row
|
# one button row
|
||||||
send_inline_keyboard "${CHAT[ID]}" "message" "Button 1|http://rrr.de" "Button 2|http://rrr.de"
|
send_inline_buttons "${CHAT[ID]}" "message" "Button 1|http://rrr.de" "Button 2|http://rrr.de"
|
||||||
|
|
||||||
# result
|
# result
|
||||||
message ...
|
message ...
|
||||||
@ -267,7 +267,7 @@ send_inline_keyboard "${CHAT[ID]}" "message" "Button 1|http://rrr.de" "Button 2|
|
|||||||
+----------------------------+
|
+----------------------------+
|
||||||
|
|
||||||
# multiple button rows
|
# multiple button rows
|
||||||
send_inline_keyboard "${CHAT[ID]}" "message" "Button 1|http://rrr.de" "Button 2|http://rrr.de" "" "Button on second row|http://rrr.de"
|
send_inline_buttons "${CHAT[ID]}" "message" "Button 1|http://rrr.de" "Button 2|http://rrr.de" "" "Button on second row|http://rrr.de"
|
||||||
|
|
||||||
# result
|
# result
|
||||||
message ...
|
message ...
|
||||||
@ -276,6 +276,7 @@ send_inline_keyboard "${CHAT[ID]}" "message" "Button 1|http://rrr.de" "Button 2|
|
|||||||
|----------------------------|
|
|----------------------------|
|
||||||
| Button on second row |
|
| Button on second row |
|
||||||
+----------------------------+
|
+----------------------------+
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
##### edit_inline_buttons
|
##### edit_inline_buttons
|
||||||
@ -316,6 +317,42 @@ answer_callback_query "${iBUTTON[ID]}" "Button data is: ${iBUTTON[DATA]}"
|
|||||||
answer_callback_query "${iBUTTON[ID]}" "Alert: Button pressed!" "alert"
|
answer_callback_query "${iBUTTON[ID]}" "Alert: Button pressed!" "alert"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# CALLBACK button example
|
||||||
|
send_inline_buttons "${CHAT[ID]}" "Press Button ..." " Button |RANDOM-BUTTON"
|
||||||
|
|
||||||
|
# result
|
||||||
|
Press Button ...
|
||||||
|
+----------------------------+
|
||||||
|
| Button |
|
||||||
|
+----------------------------+
|
||||||
|
|
||||||
|
# react on button press from mycommands
|
||||||
|
CALLBACK="1" # enable callbacks
|
||||||
|
...
|
||||||
|
mycallbacks() {
|
||||||
|
local answer
|
||||||
|
#######################
|
||||||
|
# callbacks from buttons attached to messages will be processed here
|
||||||
|
if [ "${iBUTTON[DATA]}" = "RANDOM-BUTTON" ]; then
|
||||||
|
answer="Button pressed"
|
||||||
|
edit_inline_buttons "${iBUTTON[CHAT_ID]}" "${iBUTTON[MESSAGE_ID]}" " Button ${RANDOM}|RANDOM-BUTTON"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Telegram needs an ack each callback query, default empty
|
||||||
|
answer_callback_query "${iBUTTON[ID]}" "${answer}"
|
||||||
|
;;
|
||||||
|
}
|
||||||
|
|
||||||
|
# result, XXXXX: random number changed on each press
|
||||||
|
Press Button ...
|
||||||
|
+----------------------------+
|
||||||
|
| Button XXXXXX |
|
||||||
|
+----------------------------+
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
----
|
----
|
||||||
|
|
||||||
#### Inline keyboards
|
#### Inline keyboards
|
||||||
@ -1451,5 +1488,5 @@ The name of your bot is available as bash variable "$ME", there is no need to ca
|
|||||||
#### [Prev Best Practice](5_practice.md)
|
#### [Prev Best Practice](5_practice.md)
|
||||||
#### [Next Notes for Developers](7_develop.md)
|
#### [Next Notes for Developers](7_develop.md)
|
||||||
|
|
||||||
#### $$VERSION$$ v1.35-dev-23-g5192212
|
#### $$VERSION$$ v1.35-dev-24-g5a0a571
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
# License: WTFPLv2 http://www.wtfpl.net/txt/copying/
|
# License: WTFPLv2 http://www.wtfpl.net/txt/copying/
|
||||||
# Author: KayM (gnadelwartz), kay@rrr.de
|
# Author: KayM (gnadelwartz), kay@rrr.de
|
||||||
#
|
#
|
||||||
#### $$VERSION$$ v1.35-dev-20-gfa0cb75
|
#### $$VERSION$$ v1.35-dev-24-g5a0a571
|
||||||
#######################################################
|
#######################################################
|
||||||
# shellcheck disable=SC1117
|
# shellcheck disable=SC1117
|
||||||
|
|
||||||
@ -131,6 +131,9 @@ else
|
|||||||
'/echo'*) # example echo command
|
'/echo'*) # example echo command
|
||||||
send_normal_message "${CHAT[ID]}" "${MESSAGE}"
|
send_normal_message "${CHAT[ID]}" "${MESSAGE}"
|
||||||
;;
|
;;
|
||||||
|
'/button'*)# inline button, set CALLBACK=1 for processing callbacks
|
||||||
|
send_inline_buttons "${CHAT[ID]}" "Press Button ..." " Button |RANDOM-BUTTON"
|
||||||
|
;;
|
||||||
'/question'*) # start interactive questions
|
'/question'*) # start interactive questions
|
||||||
checkproc
|
checkproc
|
||||||
if [ "${res}" -gt 0 ] ; then
|
if [ "${res}" -gt 0 ] ; then
|
||||||
@ -203,13 +206,19 @@ else
|
|||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
*) # all other callbacks are processed here
|
*) # all other callbacks are processed here
|
||||||
|
local callback_answer
|
||||||
# your processing here ...
|
# your processing here ...
|
||||||
|
# message available?
|
||||||
if [[ -n "${iBUTTON[CHAT_ID]}" && -n "${iBUTTON[MESSAGE_ID]}" ]]; then
|
if [[ -n "${iBUTTON[CHAT_ID]}" && -n "${iBUTTON[MESSAGE_ID]}" ]]; then
|
||||||
# output random button if message data is available
|
if [ "${iBUTTON[DATA]}" = "RANDOM-BUTTON" ]; then
|
||||||
edit_inline_buttons "${iBUTTON[CHAT_ID]}" "${iBUTTON[MESSAGE_ID]}" "Button ${RANDOM}|${RANDOM}"
|
callback_answer="Button pressed"
|
||||||
|
edit_inline_buttons "${iBUTTON[CHAT_ID]}" "${iBUTTON[MESSAGE_ID]}" "Button ${RANDOM}|RANDOM-BUTTON"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
callback_answer="Button to old, sorry."
|
||||||
fi
|
fi
|
||||||
# Telegram needs an ack each callback query, default empty
|
# Telegram needs an ack each callback query, default empty
|
||||||
answer_callback_query "${iBUTTON[ID]}" ""
|
answer_callback_query "${iBUTTON[ID]}" "${callback_answer}"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
# License: WTFPLv2 http://www.wtfpl.net/txt/copying/
|
# License: WTFPLv2 http://www.wtfpl.net/txt/copying/
|
||||||
# Author: KayM (gnadelwartz), kay@rrr.de
|
# Author: KayM (gnadelwartz), kay@rrr.de
|
||||||
#
|
#
|
||||||
#### $$VERSION$$ v1.35-dev-18-ge4ee880
|
#### $$VERSION$$ v1.35-dev-24-g5a0a571
|
||||||
#######################################################
|
#######################################################
|
||||||
# shellcheck disable=SC1117
|
# shellcheck disable=SC1117
|
||||||
|
|
||||||
@ -82,10 +82,11 @@ else
|
|||||||
# callbacks from buttons attached to messages will be processed here
|
# callbacks from buttons attached to messages will be processed here
|
||||||
case "${iBUTTON[USER_ID]}+${iBUTTON[CHAT_ID]}" in
|
case "${iBUTTON[USER_ID]}+${iBUTTON[CHAT_ID]}" in
|
||||||
*) # all other callbacks are processed here
|
*) # all other callbacks are processed here
|
||||||
|
local callback_answer
|
||||||
: # your processing here ...
|
: # your processing here ...
|
||||||
:
|
:
|
||||||
# Telegram needs an ack each callback query, default empty
|
# Telegram needs an ack each callback query, default empty
|
||||||
answer_callback_query "${iBUTTON[ID]}" ""
|
answer_callback_query "${iBUTTON[ID]}" "${callback_answer}"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user