fix / allow more complex keyboards

This commit is contained in:
Kay Marquardt (Gnadelwartz) 2019-04-15 16:32:56 +02:00
parent bf97646361
commit 3824137433
2 changed files with 17 additions and 9 deletions

View File

@ -51,6 +51,20 @@ git clone --recursive https://github.com/topkecleon/telegram-bot-bash
- Seperate Bot logic from command
- Test your Bot with shellcheck
## Note to Keyboards
To make using Keayboards easier I changed the format of send_keyboard as of send_message "mykeyboardstartshere ...".
Now you must provide the keyboards in Telegram JSON style "[ \"yes\" , \"no\" ]".
The advantage is that you can create every type of keyboard iwithout relying on bashbot ```send_keyboard``` functionality.
**This is incompatible with keyboards in bashbot versions older than 0.6!**
*Example Keboards*:
- Yes No in one row: "[ \"yes\" , \"no\" ]"
- Yes No ind two rows: "[ \"yes\" ] , [ \"no\" ]"
- numpad keyboard: "[ \"1\" , \"2\" , \"3\" ] , [ \"4\" , \"5\" , \"6\" ] , [ \"7\" , \"8\" , \"9\" ] , [ \"0\" ]"
## Security Considerations
Running a Telegram Bot means you are conneted to the public, you never know whats send to your Bot.

View File

@ -357,14 +357,8 @@ answer_inline_query() {
send_keyboard() {
local chat="$1"
local text="$2"
shift 2
local keyboard=init
OLDIFS=$IFS
IFS=$(echo -en "\"")
for f in "$@" ;do [ "$f" != " " ] && keyboard="$keyboard, [\"$f\"]";done
IFS=$OLDIFS
keyboard=${keyboard/init, /}
res="$(curl -s "$MSG_URL" --header "content-type: multipart/form-data" -F "chat_id=$chat" -F "text=$text" -F "reply_markup={\"keyboard\": [$keyboard],\"one_time_keyboard\": true}")"
local keyboard="$3"
res="$(curl -s "$MSG_URL" --header "content-type: multipart/form-data" -F "chat_id=$chat" -F "text=$text" -F "reply_markup={\"keyboard\": [${keyboard}],\"one_time_keyboard\": true}")"
}
remove_keyboard() {
@ -470,7 +464,7 @@ checkback() {
}
checkproc() {
tmux ls | grep -q "$1${copname}"; res=$?
tmux ls | grep -q "$1${copname}"; res=$?; return $?
}
killback() {