buttons for send_message

This commit is contained in:
Kay Marquardt (Gnadelwartz) 2019-04-26 17:19:48 +02:00
parent d6d640a3d9
commit 45f042d2cc
7 changed files with 31 additions and 21 deletions

View File

@ -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}"'"}]'
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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