From 45f042d2cca6b12b49696bedb0eb9993f5bade7a Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Fri, 26 Apr 2019 17:19:48 +0200 Subject: [PATCH] buttons for send_message --- bashbot.sh | 4 ++-- dev/all-tests.sh | 4 ++-- doc/3_advanced.md | 6 ++++- doc/6_reference.md | 10 ++++---- modules/background.sh | 24 ++++++++++++------- .../d-send_message-test.input | 2 +- .../d-send_message-test.result | 2 +- 7 files changed, 31 insertions(+), 21 deletions(-) diff --git a/bashbot.sh b/bashbot.sh index 5c18cb6..eb9c3a4 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -12,7 +12,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ v0.70-dev3-15-gfba8951 +#### $$VERSION$$ v0.70-dev3-16-gd6d640a # # Exit Codes: # - 0 sucess (hopefully) @@ -335,7 +335,7 @@ send_inline_keyboard() { sendJson "${1}" "${text}"', "reply_markup": {"inline_keyboard": [ '"${3}"' ]}' "$MSG_URL" # JSON='"text":"$2", "reply_markup": {"inline_keyboard": [ $3->[{"text":"text", "url":"url"}]<- ]}' } -send_inline_button() { +send_button() { send_inline_keyboard "${1}" "${2}" '[ {"text":"'"${3}"'", "url":"'"${4}"'"}]' } diff --git a/dev/all-tests.sh b/dev/all-tests.sh index 3f69543..9a0edbc 100755 --- a/dev/all-tests.sh +++ b/dev/all-tests.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # this has to run once atfer git clone # and every time we create new hooks -#### $$VERSION$$ v0.70-dev3-15-gfba8951 +#### $$VERSION$$ v0.70-dev3-16-gd6d640a # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script @@ -49,7 +49,7 @@ else find "${TESTENV}/"* ! -name '[a-z]-*' -delete fi -echo "${passed} / ${tests}" +echo -e "${passed} / ${tests}\\n" [ -d "${TESTENV}" ] && echo "Logfiles from run are in ${TESTENV}" ls -ld /tmp/bashbot.test* 2>/dev/null && echo "Don not forget to deleted bashbot test files in /tmp!!" diff --git a/doc/3_advanced.md b/doc/3_advanced.md index 5305786..47ac999 100644 --- a/doc/3_advanced.md +++ b/doc/3_advanced.md @@ -74,6 +74,10 @@ Same goes for files: ```bash echo "Text that will appear in chat? myfilelocationstartshere /home/user/doge.jpg" ``` +And buttons: +```bash +echo "Text that will appear in chat. mybtextstartshere Klick me myburlstartshere https://dealz.rrr.de" +``` And locations: ```bash echo "Text that will appear in chat. mylatstartshere 45 mylongstartshere 45" @@ -162,5 +166,5 @@ answer_inline_query "$iQUERY_ID" "cached_sticker" "identifier for the sticker" #### [Prev Getting started](2_usage.md) #### [Next Expert Use](4_expert.md) -#### $$VERSION$$ v0.70-dev3-15-gfba8951 +#### $$VERSION$$ v0.70-dev3-16-gd6d640a diff --git a/doc/6_reference.md b/doc/6_reference.md index 45c8884..449102b 100644 --- a/doc/6_reference.md +++ b/doc/6_reference.md @@ -125,14 +125,14 @@ send_keyboard "${CHAT[ID]}" "Enter digit" "[ \\"1\\" , \\"2\\" , \\"3\\" ] , [ \ ##### remove_keyboard *usage:* remove_keybord "$CHAT[ID]" "message" -##### send_inline_button -*usage:* send_inine_button "chat-id" "message" "text" "URL" +##### send_button +*usage:* send_button "chat-id" "message" "text" "URL" -*alias:* _inline_button "text" "URL" +*alias:* _button "text" "URL" *example:* ```bash -send_inline_button "${CHAT[ID]}" "MAKE MONEY FAST!!!" "Visit my Shop" "https://dealz.rrr.de" +send_button "${CHAT[ID]}" "MAKE MONEY FAST!!!" "Visit my Shop" "https://dealz.rrr.de" ``` ##### send_inline_keyboard @@ -473,5 +473,5 @@ Send Input from Telegram to waiting Interactive Chat. #### [Prev Best Practice](5_practice.md) #### [Next Notes for Developers](7_develop.md) -#### $$VERSION$$ v0.70-dev3-15-gfba8951 +#### $$VERSION$$ v0.70-dev3-16-gd6d640a diff --git a/modules/background.sh b/modules/background.sh index fcc8e16..3c4822b 100644 --- a/modules/background.sh +++ b/modules/background.sh @@ -5,7 +5,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ v0.70-dev3-15-gfba8951 +#### $$VERSION$$ v0.70-dev3-16-gd6d640a # source from commands.sh if you want ro use interactive or background jobs @@ -15,19 +15,21 @@ export res #### # I placed send_message here because main use case is interactive chats and background jobs send_message() { - local text arg keyboard file lat long title address sent + local text arg keyboard btext burl no_keyboard file lat long title address sent [ "$2" = "" ] && return local mychat="$1" - text="$(sed <<< "${2}" 's/ mynewlinestartshere /\r\n/g; s/ my[kflta][a-z]\{2,13\}startshere.*//g;s/ mykeyboardendshere.*//g')" + text="$(sed <<< "${2}" 's/ mynewlinestartshere /\r\n/g; s/ my[kfltab][a-z]\{2,13\}startshere.*//g;s/ mykeyboardendshere.*//g')" arg="$3" [ "$arg" != "safe" ] && { no_keyboard="$(sed <<< "${2}" '/mykeyboardendshere/!d;s/.*mykeyboardendshere.*/mykeyboardendshere/')" - keyboard="$(sed <<< "${2}" '/mykeyboardstartshere /!d;s/.*mykeyboardstartshere //g;s/ my[kflta][a-z]\{2,13\}startshere.*//g;s/ mykeyboardendshere.*//g')" - file="$(sed <<< "${2}" '/myfilelocationstartshere /!d;s/.*myfilelocationstartshere //g;s/ my[kflta][a-z]\{2,13\}startshere.*//g;s/ mykeyboardendshere.*//g')" - lat="$(sed <<< "${2}" '/mylatstartshere /!d;s/.*mylatstartshere //g;s/ my[kflta][a-z]\{2,13\}startshere.*//g;s/ mykeyboardendshere.*//g')" - long="$(sed <<< "${2}" '/mylongstartshere /!d;s/.*mylongstartshere //g;s/ my[kflta][a-z]\{2,13\}startshere.*//g;s/ mykeyboardendshere.*//g')" - title="$(sed <<< "${2}" '/mytitlestartshere /!d;s/.*mytitlestartshere //g;s/ my[kflta][a-z]\{2,13\}startshere.*//g;s/ mykeyboardendshere.*//g')" - address="$(sed <<< "${2}" '/myaddressstartshere /!d;s/.*myaddressstartshere //g;s/ my[kflta][a-z]\{2,13\}startshere.*//g;s/ mykeyboardendshere.*//g')" + keyboard="$(sed <<< "${2}" '/mykeyboardstartshere /!d;s/.*mykeyboardstartshere //g;s/ my[kfltab][a-z]\{2,13\}startshere.*//g;s/ mykeyboardendshere.*//g')" + btext="$(sed <<< "${2}" '/mybtextstartshere /!d;s/.*mybtextstartshere //g;s/ my[kfltab][a-z]\{2,13\}startshere.*//g;s/ mykeyboardendshere.*//g')" + burl="$(sed <<< "${2}" '/myburlstartshere /!d;s/.*myburlstartshere //g;s/ my[kfltab][a-z]\{2,13\}startshere.*//g;s/ mykeyboardendshere.*//g')" + file="$(sed <<< "${2}" '/myfilelocationstartshere /!d;s/.*myfilelocationstartshere //g;s/ my[kfltab][a-z]\{2,13\}startshere.*//g;s/ mykeyboardendshere.*//g')" + lat="$(sed <<< "${2}" '/mylatstartshere /!d;s/.*mylatstartshere //g;s/ my[kfltab][a-z]\{2,13\}startshere.*//g;s/ mykeyboardendshere.*//g')" + long="$(sed <<< "${2}" '/mylongstartshere /!d;s/.*mylongstartshere //g;s/ my[kfltab][a-z]\{2,13\}startshere.*//g;s/ mykeyboardendshere.*//g')" + title="$(sed <<< "${2}" '/mytitlestartshere /!d;s/.*mytitlestartshere //g;s/ my[kfltab][a-z]\{2,13\}startshere.*//g;s/ mykeyboardendshere.*//g')" + address="$(sed <<< "${2}" '/myaddressstartshere /!d;s/.*myaddressstartshere //g;s/ my[kfltab][a-z]\{2,13\}startshere.*//g;s/ mykeyboardendshere.*//g')" } if [ "$no_keyboard" != "" ]; then remove_keyboard "$mychat" "$text" @@ -40,6 +42,10 @@ send_message() { send_keyboard "$mychat" "$text" "$keyboard" sent=y fi + if [ "$btext" != "" ] && [ "$burl" != "" ]; then + send_button "$mychat" "$text" "$btext" "$burl" + sent=y + fi if [ "$file" != "" ]; then send_file "$mychat" "$file" "$text" sent=y diff --git a/test/d-send_message-test/d-send_message-test.input b/test/d-send_message-test/d-send_message-test.input index 8fdcafb..d63cdde 100644 --- a/test/d-send_message-test/d-send_message-test.input +++ b/test/d-send_message-test/d-send_message-test.input @@ -14,4 +14,4 @@ Text plus vuene will appear in chat mylatstartshere la10 mylongstartshere lo20 m All in one will appear in chat mykeyboardstartshere [ "Yep, sure" , "No, highly unlikely" ] myfilelocationstartshere /home/user/doge.jpg mylatstartshere la10 mylongstartshere lo20 # test for new inline button -Text plus keyboard will appear in chat mybuttonstartshere "Button Text" "https://www..." +Text plus keyboard will appear in chat mybtextstartshere Button Text myburlstartshere https://www... diff --git a/test/d-send_message-test/d-send_message-test.result b/test/d-send_message-test/d-send_message-test.result index 7721a3c..4c3b28d 100644 --- a/test/d-send_message-test/d-send_message-test.result +++ b/test/d-send_message-test/d-send_message-test.result @@ -49,6 +49,6 @@ URL:https://api.telegram.org/botbashbottestscript/sendLocation chat:123456 JSON:"text":"# test for new inline button" URL:https://api.telegram.org/botbashbottestscript/sendMessage -chat:123456 JSON:"text":"Text plus keyboard will appear in chat mybuttonstartshere "Button Text" "https://www..."" +chat:123456 JSON:"text":"Text plus keyboard will appear in chat", "reply_markup": {"inline_keyboard": [ [ {"text":"Button Text", "url":"https://www..."}] ]} URL:https://api.telegram.org/botbashbottestscript/sendMessage