diff --git a/commands.sh b/commands.sh index 0b10d04..d83597b 100644 --- a/commands.sh +++ b/commands.sh @@ -15,7 +15,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ v1.31-dev-13-g127cc85 +#### $$VERSION$$ v1.35-dev-6-gc90b565 # # bashbot locale defaults to c.UTF-8, adjust locale in mycommands.sh if needed @@ -66,6 +66,7 @@ fi # copy "mycommands.sh.dist" to "mycommands.sh" and change the values there # defaults to no inline, all commands and nonsense home dir export INLINE="0" +export CALLBACK="0" export MEONLY="0" export FILE_REGEX="${BASHBOT_ETC}/.*" @@ -76,14 +77,18 @@ export FILE_REGEX="${BASHBOT_ETC}/.*" if [ -z "$1" ] || [[ "$1" == *"debug"* ]];then - # detect inline commands.... - # no default commands, all processing is done in myinlines() - if [ "${INLINE}" != "0" ] && [ -n "${iQUERY[ID]}" ]; then + ################# + # detect inline and callback query + if [[ -n "${iQUERY[ID]}" && "${INLINE:-0}" != "0" ]]; then # forward iinline query to optional dispatcher _exec_if_function myinlines - # regular (global) commands ... - # your commands are in mycommands() + elif [[ -n "${iBUTTON[ID]}" && "${CALLBACK:-0}" != "0" ]]; then + # forward iinline query to optional dispatcher + _exec_if_function mycallbacks + + ################# + # regular command else ################### diff --git a/doc/6_reference.md b/doc/6_reference.md index 731b7d5..390bddd 100644 --- a/doc/6_reference.md +++ b/doc/6_reference.md @@ -216,8 +216,10 @@ _keyboard_numpad *See also: [Keyboard Markup](https://core.telegram.org/bots/api/#replykeyboardmarkup)* +---- + ##### send_button -`send_button` sends a text message with a single button for opneing and URL. +`send_button` sends a text message with a single button to open an URL attached. *usage:* send_button "$CHAT[ID]" "message" "text" "URL" @@ -253,8 +255,8 @@ send_inline_keyboard "${CHAT[ID]}" "message" "$(_button_row "b1|http://rrr.de" " ``` ##### send_inline_keyboard -`send_inline_keyboard` send a message with attached buttons, buttons are given as an array of buttons in JSON format. -In contrast to `send_keyboard` the button are attached to a message and do not send text to the chat. +`send_inline_keyboard` sends a message with buttons attached, buttons must be given in JSON format. +In contrast to `send_keyboard` buttons are attached to the message and do not send text. *usage:* send_inline_keyboard "CHAT[ID]" "message" "[JSON button array]" @@ -1321,5 +1323,5 @@ The name of your bot is available as bash variable "$ME", there is no need to ca #### [Prev Best Practice](5_practice.md) #### [Next Notes for Developers](7_develop.md) -#### $$VERSION$$ v1.35-dev-5-gcc7afdb +#### $$VERSION$$ v1.35-dev-6-gc90b565 diff --git a/mycommands.conf b/mycommands.conf index 736928d..f2052d0 100644 --- a/mycommands.conf +++ b/mycommands.conf @@ -12,7 +12,7 @@ # Author: KayM (gnadelwartz), kay@rrr.de # Created: 09.01.2021 07:27 # -#### $$VERSION$$ v1.31-dev-15-g07f026c +#### $$VERSION$$ v1.35-dev-6-gc90b565 ####################################################### ########## @@ -47,6 +47,10 @@ Edit commands and messages in mycommands.sh! # To enable this option in your bot, send the /setinline command to @BotFather. export INLINE="0" +# Set CALLBACK to 1 in order to receive callback queries. +# callbacks are sent from inline_keyboards (buttons) attached tp bot messages +export CALLBACK="0" + # if your bot is group admin it get commands sent to other bots # Set MEONLY to 1 to ignore commands sent to other bots export MEONLY="0" diff --git a/mycommands.sh b/mycommands.sh index bc27071..c441061 100644 --- a/mycommands.sh +++ b/mycommands.sh @@ -13,7 +13,7 @@ # License: WTFPLv2 http://www.wtfpl.net/txt/copying/ # Author: KayM (gnadelwartz), kay@rrr.de # -#### $$VERSION$$ v1.30-0-g3266427 +#### $$VERSION$$ v1.35-dev-6-gc90b565 ####################################################### # shellcheck disable=SC1117 @@ -179,6 +179,40 @@ else esac } + mycallbacks() { + ####################### + # callbacks from buttons bot has attached to messages can processed here + # we have no standard use case for processing callbacks, we log them based on user and chat + case "${USER[ID]}+${CHAT[ID]}" in + 'USERID1+'*) # do something for all callbacks from USER + printf "%s: U=%s C=%s D=%s\n" "$(date)" "${iBOTTON[USER_ID]}" "${iBOTTON[CHAT_ID]}" "${iBUTTON[DATA]}"\ + >>"${DATADIR}/${iBOTTON[USER_ID]}.log" + answer_callback_query "${iBUTTON[ID]}" "Request has been logged in your user log..." + return + ;; + *'+CHATID1') # do something for all callbacks from CHAT + printf "%s: U=%s C=%s D=%s\n" "$(date)" "${iBOTTON[USER_ID]}" "${iBOTTON[CHAT_ID]}" "${iBUTTON[DATA]}"\ + >>"${DATADIR}/${iBOTTON[CHAT_ID]}.log" + answer_callback_query "${iBUTTON[ID]}" "Request has been logged in chat log..." + return + ;; + 'USERID2+CHATID2') # do something only for callbacks form USER in CHAT + printf "%s: U=%s C=%s D=%s\n" "$(date)" "${iBOTTON[USER_ID]}" "${iBOTTON[CHAT_ID]}" "${iBUTTON[DATA]}"\ + >>"${DATADIR}/${iBOTTON[USER_ID]}-${iBOTTON[CHAT_ID]}.log" + answer_callback_query "${iBUTTON[ID]}" "Request has been logged in user-chat log..." + return + ;; + *) # all other callbacks are processed here + : # your processing here ... + : + # Telegram needs an ack each callback query, default empty + answer_callback_query "${iBUTTON[ID]}" "" + ;; + esac + + + } + myinlines() { ####################### # Inline query examples, do not use them in production (except image search ;-)