modules: button url not starting with hhttp is sent as data

This commit is contained in:
Kay Marquardt (Gnadelwartz) 2021-01-24 12:30:56 +01:00
parent 9023b21791
commit 1fe22a0345
3 changed files with 17 additions and 11 deletions

View File

@ -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.32-dev-13-gf995eee #### $$VERSION$$ v1.35-dev-1-g9023b21
################################################################## ##################################################################
# emmbeded system may claim bash but it is not # emmbeded system may claim bash but it is not
@ -689,8 +689,8 @@ process_client() {
"${iQUERY[USERNAME]:0:20} (${iQUERY[USER_ID]})" "${iQUERY[0]}" >>"${UPDATELOG}" "${iQUERY[USERNAME]:0:20} (${iQUERY[USER_ID]})" "${iQUERY[0]}" >>"${UPDATELOG}"
elif [ -n "${iBUTTON[ID]}" ]; then elif [ -n "${iBUTTON[ID]}" ]; then
process_inline_button "${num}" "${debug}" process_inline_button "${num}" "${debug}"
printf "%(%c)T: Inline Button update received FROM=%s iBUTTON=%s\n" -1\ printf "%(%c)T: Inline Button update received FROM=%s CHAT=%s ID=%s DATA:%s \n" -1\
"${iBUTTON[USERNAME]:0:20} (${iBUTTON[USER_ID]})" "${iBUTTON[0]}" >>"${UPDATELOG}" "${iBUTTON[USERNAME]:0:20} (${iBUTTON[USER_ID]})" "${iBUTTON[CHAT_ID]}" "{iBUTTON[ID]" "{iBUTTON[DATA]" >>"${UPDATELOG}"
else else
if grep -qs -e '\["result",'"${num}"',"edited_message"' <<<"${UPDATE}"; then if grep -qs -e '\["result",'"${num}"',"edited_message"' <<<"${UPDATE}"; then
# edited message # edited message
@ -866,17 +866,20 @@ process_inline_query() {
return 0 return 0
} }
process_inline_button() { process_inline_button() {
# debugging for impelemetation
log_message "${res}"
set -x
local num="$1" local num="$1"
iBUTTON[0]="$(JsonDecode "${UPD["result,${num},inline_callback,query"]}")" iBUTTON[DATA]="${UPD["result,${num},inline_callback,data"]}"
iBUTTON[CHAT_ID]="${UPD["result,${num},inline_callback,chat_instance"]}" iBUTTON[CHAT_ID]="${UPD["result,${num},inline_callback,chat_instance"]}"
iBUTTON[MESSAGE_ID]="${UPD["result,${num},inline_callback,inline_message_id"]}" iBUTTON[MESSAGE_ID]="${UPD["result,${num},inline_callback,inline_message_id"]}"
iBUTTON[MESSAGE_TEXT]="${UPD["result,${num},inline_callback,message,text"]}" iBUTTON[MEESSAGE]="$(JsonDecode "${UPD["result,${num},inline_callback,message,text"]}")"
# XXX should we give back pressed button or all buttons? # XXX should we give back pressed button, all buttons or nothing?
iBUTTON[MESSAGE_BUTTONS]="${UPD["result,${num},inline_callback,message,reply_markup"]}"
iBUTTON[USER_ID]="${UPD["result,${num},inline_callback,from,id"]}" iBUTTON[USER_ID]="${UPD["result,${num},inline_callback,from,id"]}"
iBUTTON[FIRST_NAME]="$(JsonDecode "${UPD["result,${num},inline_callback,from,first_name"]}")" iBUTTON[FIRST_NAME]="$(JsonDecode "${UPD["result,${num},inline_callback,from,first_name"]}")"
iBUTTON[LAST_NAME]="$(JsonDecode "${UPD["result,${num},inline_callback,from,last_name"]}")" iBUTTON[LAST_NAME]="$(JsonDecode "${UPD["result,${num},inline_callback,from,last_name"]}")"
iBUTTON[USERNAME]="$(JsonDecode "${UPD["result,${num},inline_callback,from,username"]}")" iBUTTON[USERNAME]="$(JsonDecode "${UPD["result,${num},inline_callback,from,username"]}")"
set +x
# always true # always true
return 0 return 0
} }

View File

@ -5,7 +5,7 @@
# #
# Description: run all tests, exit after failed test # Description: run all tests, exit after failed test
# #
#### $$VERSION$$ v1.30-0-g3266427 #### $$VERSION$$ v1.35-dev-0-gd9b3342
############################################################# #############################################################
#shellcheck disable=SC1090 #shellcheck disable=SC1090

View File

@ -6,7 +6,7 @@
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
# #
# shellcheck disable=SC1117 # shellcheck disable=SC1117
#### $$VERSION$$ v1.32-dev-1-g662c6f4 #### $$VERSION$$ v1.35-dev-1-g9023b21
# will be automatically sourced from bashbot # will be automatically sourced from bashbot
@ -159,13 +159,16 @@ send_button() {
# helper function to create json for a button row # helper function to create json for a button row
# buttons will specified as "text|url" ... "text|url" empty arg starts new row # buttons will specified as "text|url" ... "text|url" empty arg starts new row
# url not starting with http:// or https:// will be send as callback_data
_button_row() { _button_row() {
[ -z "$1" ] && return 1 [ -z "$1" ] && return 1
local arg json sep local arg type json sep
for arg in "$@" for arg in "$@"
do do
[ -z "${arg}" ] && sep="],[" && continue [ -z "${arg}" ] && sep="],[" && continue
json+="${sep}"'{"text":"'"$(JsonEscape "${arg%|*}")"'", "url":"'"${arg##*|}"'"}' type="callback_data"
[[ "${arg##*|}" =~ ^https*:// ]] && type="url"
json+="${sep}"'{"text":"'"$(JsonEscape "${arg%|*}")"'", "'"${type}"'":"'"${arg##*|}"'"}'
sep="," sep=","
done done
printf "[%s]" "${json}" printf "[%s]" "${json}"