From aa2c20b37e8d1630d0d23b4ced197c49ad4ba596 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sun, 24 Jan 2021 13:52:44 +0100 Subject: [PATCH] doc: add callback buttons --- bin/edit_buttons.sh | 3 ++- bin/send_buttons.sh | 3 ++- doc/6_reference.md | 11 ++++++++--- modules/sendMessage.sh | 4 ++-- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/bin/edit_buttons.sh b/bin/edit_buttons.sh index 116e7e8..a874d0c 100755 --- a/bin/edit_buttons.sh +++ b/bin/edit_buttons.sh @@ -12,6 +12,7 @@ USAGE='send_message.sh [-h|--help] "CHAT[ID]" "MESSAGE[ID]" "text|url" ...' # MESSAGE[ID] - ID of MESSAGE with buttons to edit # text|url - buttons to send, each button as "text|url" pair or # "url" only to show url as text also, "" starts new row +# "url" not http(s):// or tg:// is sent as callback_data # # -h - display short help # --help - this help @@ -25,7 +26,7 @@ USAGE='send_message.sh [-h|--help] "CHAT[ID]" "MESSAGE[ID]" "text|url" ...' # AUTHOR: KayM (gnadelwartz), kay@rrr.de # CREATED: 21.01.2021 08:10 # -#### $$VERSION$$ v1.32-dev-6-g2832801 +#### $$VERSION$$ v1.35-dev-3-g461e748 #=============================================================================== #### diff --git a/bin/send_buttons.sh b/bin/send_buttons.sh index 86ac108..5aba29e 100755 --- a/bin/send_buttons.sh +++ b/bin/send_buttons.sh @@ -11,6 +11,7 @@ USAGE='send_message.sh [-h|--help] "CHAT[ID]" "message" "text|url" ...' # OPTIONS: CHAT[ID] - ID number of CHAT or BOTADMIN to send to yourself # message - message to send # text|url - buttons to send, each button as "text|url" pair or +# "url" not http(s):// or tg:// is sent as callback_data # "url" only to show url as text also, "" starts new row # # -h - display short help @@ -25,7 +26,7 @@ USAGE='send_message.sh [-h|--help] "CHAT[ID]" "message" "text|url" ...' # AUTHOR: KayM (gnadelwartz), kay@rrr.de # CREATED: 18.01.2021 11:34 # -#### $$VERSION$$ v1.32-dev-6-g2832801 +#### $$VERSION$$ v1.35-dev-3-g461e748 #=============================================================================== #### diff --git a/doc/6_reference.md b/doc/6_reference.md index b830895..ea74960 100644 --- a/doc/6_reference.md +++ b/doc/6_reference.md @@ -240,6 +240,9 @@ Each button is specified as a `"text|url"` pair separated by `|`, `text` is show By default all buttons are displayed on one row, an empty string `""` starts a new button row. If `"url"` without text is given, `url` is shown on the button and opened on button click. +**Important**: An `url` not startung with http(s):// or tg:// will be converted to a +[Callback Button](https://core.telegram.org/bots/2-0-intro#callback-buttons) + *example:* ```bash # one button, same as send_button @@ -257,9 +260,11 @@ send_inline_keyboard "${CHAT[ID]}" "message" "$(_button_row "b1|http://rrr.de" " *usage:* send_inline_keyboard "CHAT[ID]" "message" "[JSON button array]" -A JSON button array has the following format, but I suggest to use `_button_row` to create them: +A JSON button array has the following format, but I suggest to use `_button_row` to create them, +see [Inline Keyboard Markup](https://core.telegram.org/bots/api#inlinekeyboardmarkup) -`[ {"text":"text1", "url":"url1"}, ... {"text":"textN", "url":"urlN"} ],[...]` +URL buttons: `[ {"text":"text1", "url":"url1"}, ... {"text":"textN", "url":"urlN"} ],[...]` +CALLBACK buttons: `[ {"text":"text1", "callback_data":"abc"}, ... {"text":"textN", "callback_data":"defg"} ],[...]` *example:* ```bash @@ -1317,5 +1322,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.32-dev-7-g8bb4b7e +#### $$VERSION$$ v1.35-dev-3-g461e748 diff --git a/modules/sendMessage.sh b/modules/sendMessage.sh index acd0768..4b19434 100644 --- a/modules/sendMessage.sh +++ b/modules/sendMessage.sh @@ -6,7 +6,7 @@ # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # # shellcheck disable=SC1117 -#### $$VERSION$$ v1.35-dev-1-g9023b21 +#### $$VERSION$$ v1.35-dev-3-g461e748 # will be automatically sourced from bashbot @@ -167,7 +167,7 @@ _button_row() { do [ -z "${arg}" ] && sep="],[" && continue type="callback_data" - [[ "${arg##*|}" =~ ^https*:// ]] && type="url" + [[ "${arg##*|}" =~ ^(https*://|tg://) ]] && type="url" json+="${sep}"'{"text":"'"$(JsonEscape "${arg%|*}")"'", "'"${type}"'":"'"${arg##*|}"'"}' sep="," done