doc: add callback buttons

This commit is contained in:
Kay Marquardt (Gnadelwartz) 2021-01-24 13:52:44 +01:00
parent 461e748c92
commit aa2c20b37e
4 changed files with 14 additions and 7 deletions

View File

@ -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
#===============================================================================
####

View File

@ -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
#===============================================================================
####

View File

@ -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

View File

@ -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