mirror of
https://github.com/octoleo/telegram-bot-bash.git
synced 2024-06-08 05:10:52 +00:00
add documentation for inline keyboards
This commit is contained in:
parent
8f4b1688bd
commit
8b8da67465
10
bashbot.sh
10
bashbot.sh
|
@ -12,7 +12,7 @@
|
||||||
# This file is public domain in the USA and all free countries.
|
# This file is public domain in the USA and all free countries.
|
||||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||||
#
|
#
|
||||||
#### $$VERSION$$ v0.70-dev3-3-g0f220bd
|
#### $$VERSION$$ v0.70-dev3-4-g8f4b168
|
||||||
#
|
#
|
||||||
# Exit Codes:
|
# Exit Codes:
|
||||||
# - 0 sucess (hopefully)
|
# - 0 sucess (hopefully)
|
||||||
|
@ -166,7 +166,7 @@ export BOTSENT USER MESSAGE URLS CONTACT LOCATION CHAT FORWARD REPLYTO VENUE
|
||||||
send_normal_message() {
|
send_normal_message() {
|
||||||
text="$2"
|
text="$2"
|
||||||
until [ "$(echo -n "$text" | wc -m)" -eq "0" ]; do
|
until [ "$(echo -n "$text" | wc -m)" -eq "0" ]; do
|
||||||
res="$(curl -s "$MSG_URL" -d "chat_id=$1" --data-urlencode "text=${text:0:4096}")"
|
sendJson "${1}" '"text":"'"${text:0:4096}"'"' "$MSG_URL"
|
||||||
text="${text:4096}"
|
text="${text:4096}"
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
@ -174,7 +174,7 @@ send_normal_message() {
|
||||||
send_markdown_message() {
|
send_markdown_message() {
|
||||||
text="$2"
|
text="$2"
|
||||||
until [ "$(echo -n "$text" | wc -m)" -eq "0" ]; do
|
until [ "$(echo -n "$text" | wc -m)" -eq "0" ]; do
|
||||||
res="$(curl -s "$MSG_URL" -d "chat_id=$1" --data-urlencode "text=${text:0:4096}" -d "parse_mode=markdown" -d "disable_web_page_preview=true")"
|
sendJson "${1}" '"text":"'"${text:0:4096}"'","parse_mode":"markdown"' "$MSG_URL"
|
||||||
text="${text:4096}"
|
text="${text:4096}"
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
@ -182,7 +182,7 @@ send_markdown_message() {
|
||||||
send_html_message() {
|
send_html_message() {
|
||||||
text="$2"
|
text="$2"
|
||||||
until [ "$(echo -n "$text" | wc -m)" -eq "0" ]; do
|
until [ "$(echo -n "$text" | wc -m)" -eq "0" ]; do
|
||||||
res="$(curl -s "$MSG_URL" -d "chat_id=$1" --data-urlencode "text=${text:0:4096}" -d "parse_mode=html")"
|
sendJson "${1}" '"text":"'"${text:0:4096}"'","parse_mode":"html"' "$MSG_URL"
|
||||||
text="${text:4096}"
|
text="${text:4096}"
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
@ -352,7 +352,7 @@ send_inline_button() {
|
||||||
|
|
||||||
# usage: sendJson "chat" "JSON" "URL"
|
# usage: sendJson "chat" "JSON" "URL"
|
||||||
sendJson(){
|
sendJson(){
|
||||||
res="$(curl -d '{"chat_id":'"${1}"', '"$2"'}' -H "Content-Type: application/json" \
|
res="$(curl -s -d '{"chat_id":'"${1}"', '"$2"'}' -H "Content-Type: application/json" \
|
||||||
-X POST "${3}" | "${JSONSHFILE}" -s -b -n )"
|
-X POST "${3}" | "${JSONSHFILE}" -s -b -n )"
|
||||||
BOTSENT[OK]="$(echo "$res" | JsonGetLine '"ok"')"
|
BOTSENT[OK]="$(echo "$res" | JsonGetLine '"ok"')"
|
||||||
BOTSENT[ID]="$(echo "$res" | JsonGetValue '"result","message_id"')"
|
BOTSENT[ID]="$(echo "$res" | JsonGetValue '"result","message_id"')"
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
#
|
#
|
||||||
# works together with git pre-push.sh and ADD all changed files since last push
|
# works together with git pre-push.sh and ADD all changed files since last push
|
||||||
|
|
||||||
#### $$VERSION$$ v0.70-dev3-3-g0f220bd
|
#### $$VERSION$$ v0.70-dev3-4-g8f4b168
|
||||||
|
|
||||||
# magic to ensure that we're always inside the root of our application,
|
# magic to ensure that we're always inside the root of our application,
|
||||||
# no matter from which directory we'll run script
|
# no matter from which directory we'll run script
|
||||||
|
@ -25,6 +25,3 @@ do
|
||||||
done
|
done
|
||||||
echo "done."
|
echo "done."
|
||||||
|
|
||||||
# shellcheck disable=SC2086
|
|
||||||
git add ${FILES}
|
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,6 @@
|
||||||
|
|
||||||
*"action":* ```typing```, ```upload_photo```, ```record_video```, ```upload_video```, ```record_audio```, ```upload_audio```, ```upload_document```, ```find_location```.
|
*"action":* ```typing```, ```upload_photo```, ```record_video```, ```upload_video```, ```record_audio```, ```upload_audio```, ```upload_document```, ```find_location```.
|
||||||
|
|
||||||
|
|
||||||
*example:*
|
*example:*
|
||||||
```bash
|
```bash
|
||||||
send_action "${CHAT[ID]}" "typing"
|
send_action "${CHAT[ID]}" "typing"
|
||||||
|
@ -37,8 +36,8 @@ Telegram supports a [reduced set of Markdown](https://core.telegram.org/bots/api
|
||||||
|
|
||||||
*example:*
|
*example:*
|
||||||
```bash
|
```bash
|
||||||
send_normal_message "${CHAT[ID]}" "this is a markdown message, next word is *bold*"
|
send_markdown_message "${CHAT[ID]}" "this is a markdown message, next word is *bold*"
|
||||||
send_normal_message "${CHAT[ID]}" "*bold* _italic_ [text](link)"
|
send_markdown_message "${CHAT[ID]}" "*bold* _italic_ [text](link)"
|
||||||
```
|
```
|
||||||
|
|
||||||
##### send_html_message
|
##### send_html_message
|
||||||
|
@ -126,6 +125,33 @@ send_keyboard "${CHAT[ID]}" "Enter digit" "[ \\"1\\" , \\"2\\" , \\"3\\" ] , [ \
|
||||||
##### remove_keyboard
|
##### remove_keyboard
|
||||||
*usage:* remove_keybord "$CHAT[ID]" "message"
|
*usage:* remove_keybord "$CHAT[ID]" "message"
|
||||||
|
|
||||||
|
#### send_inline_button
|
||||||
|
*usage:* send_inine_button "chat-id" "message" "Button text" "Buttton URL"
|
||||||
|
|
||||||
|
*alias:* _inline_button "Button text" "Buttton URL"
|
||||||
|
|
||||||
|
*example:*
|
||||||
|
```bash
|
||||||
|
send_inline_button "${CHAT[ID]}" "MAKE MONEY FAST!!!" "Visit my Shop" "https://dealz.rrr.de"
|
||||||
|
```
|
||||||
|
|
||||||
|
#### send_inline_keyboard
|
||||||
|
An inline keyboard is used to place multiple inline buttons in a row. The inline buttons must specified as a JSON array in the following format. Each button consists of a text for the button and an URL to got to if the button is clicked, button definitions
|
||||||
|
are sourrounded by a pair of '**{ }**' and seperated by a '**,**'.
|
||||||
|
|
||||||
|
```[ {"text":"text1", "url":"url1"}, ... {"text":"textN", "url":"urlN"} ]```
|
||||||
|
|
||||||
|
*usage:* send_inline_keyboard "chat-id" "message" "[{"text":"text", "url":"url"} ...]"
|
||||||
|
|
||||||
|
*alias:* _inline_keyboard "[{"text":"text", "url":"url"} ...]"
|
||||||
|
|
||||||
|
*example:*
|
||||||
|
```bash
|
||||||
|
send_inline_keyboard "${CHAT[ID]}" "MAKE MONEY FAST!!!" '[{"text":"Visit my Shop", url"":"https://dealz.rrr.de"}]'
|
||||||
|
send_inline_keyboard "${CHAT[ID]}" "" '[{"text":"button 1", url"":"url 1"}, {"text":"button 2", url"":"url 2"} ]'
|
||||||
|
send_inline_keyboard "${CHAT[ID]}" "" '[{"text":"b 1", url"":"u 1"}, {"text":"b 2", url"":"u 2"}, {"text":"b 2", url"":"u 2"} ]'
|
||||||
|
```
|
||||||
|
|
||||||
----
|
----
|
||||||
|
|
||||||
### Manage users
|
### Manage users
|
||||||
|
@ -135,21 +161,21 @@ If your Bot is Admin of a chat he can kick and ban a user.
|
||||||
|
|
||||||
*usage:* kick_chat_member "${CHAT[ID]}" "${USER[ID]}"
|
*usage:* kick_chat_member "${CHAT[ID]}" "${USER[ID]}"
|
||||||
|
|
||||||
*alias* _kick_user "${USER[ID]}"
|
*alias:* _kick_user "${USER[ID]}"
|
||||||
|
|
||||||
##### unban_chat_member
|
##### unban_chat_member
|
||||||
If your Bot is Admin of a chat he can unban a kicked user.
|
If your Bot is Admin of a chat he can unban a kicked user.
|
||||||
|
|
||||||
*usage:* unban_chat_member "${CHAT[ID]}" "${USER[ID]}"
|
*usage:* unban_chat_member "${CHAT[ID]}" "${USER[ID]}"
|
||||||
|
|
||||||
*alias* _unban "${USER[ID]}"
|
*alias:* _unban "${USER[ID]}"
|
||||||
|
|
||||||
##### leave_chat
|
##### leave_chat
|
||||||
Bot will leave given chat.
|
Bot will leave given chat.
|
||||||
|
|
||||||
*usage:* leave_chat "${CHAT[ID]}"
|
*usage:* leave_chat "${CHAT[ID]}"
|
||||||
|
|
||||||
*alias* _leave
|
*alias:* _leave
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
if _is_admin ; then
|
if _is_admin ; then
|
||||||
|
@ -218,19 +244,19 @@ You must use ```source modules/aliases.sh``` in commands.sh or mycommands.sh to
|
||||||
|
|
||||||
*usage:* _is_botadmin
|
*usage:* _is_botadmin
|
||||||
|
|
||||||
*alias for* user_is_botadmin "${USER[ID]}"
|
*alias for:* user_is_botadmin "${USER[ID]}"
|
||||||
|
|
||||||
#### _is_admin
|
#### _is_admin
|
||||||
|
|
||||||
*usage:* _is_admin
|
*usage:* _is_admin
|
||||||
|
|
||||||
*alias for* user_is_admin "${CHAT[ID]}" "${USER[ID]}"
|
*alias for:* user_is_admin "${CHAT[ID]}" "${USER[ID]}"
|
||||||
|
|
||||||
#### _is_allowed
|
#### _is_allowed
|
||||||
|
|
||||||
*usage:* _is_allowed "what"
|
*usage:* _is_allowed "what"
|
||||||
|
|
||||||
*alias for* user_is_allowed "${USER[ID]}" "what" "${CHAT[ID]}"
|
*alias for:* user_is_allowed "${USER[ID]}" "what" "${CHAT[ID]}"
|
||||||
|
|
||||||
----
|
----
|
||||||
|
|
||||||
|
@ -238,19 +264,19 @@ You must use ```source modules/aliases.sh``` in commands.sh or mycommands.sh to
|
||||||
|
|
||||||
*usage:* _kick_user "${USER[ID]}"
|
*usage:* _kick_user "${USER[ID]}"
|
||||||
|
|
||||||
*alias for* kick_chat_member "${CHAT[ID]}" "${USER[ID]}"
|
*alias for:* kick_chat_member "${CHAT[ID]}" "${USER[ID]}"
|
||||||
|
|
||||||
##### unban_chat_member
|
##### unban_chat_member
|
||||||
|
|
||||||
*usage:* _unban "${USER[ID]}"
|
*usage:* _unban "${USER[ID]}"
|
||||||
|
|
||||||
*alias for* unban_chat_member "${CHAT[ID]}" "${USER[ID]}"
|
*alias for:* unban_chat_member "${CHAT[ID]}" "${USER[ID]}"
|
||||||
|
|
||||||
##### leave_chat
|
##### leave_chat
|
||||||
|
|
||||||
*usage:* _leave
|
*usage:* _leave
|
||||||
|
|
||||||
*alias for* leave_chat "${CHAT[ID]}"
|
*alias for:* leave_chat "${CHAT[ID]}"
|
||||||
|
|
||||||
----
|
----
|
||||||
|
|
||||||
|
@ -258,25 +284,25 @@ You must use ```source modules/aliases.sh``` in commands.sh or mycommands.sh to
|
||||||
|
|
||||||
*usage:* _message "message"
|
*usage:* _message "message"
|
||||||
|
|
||||||
*alias for* send_normal_message "${CHAT[ID]}" "message"
|
*alias for:* send_normal_message "${CHAT[ID]}" "message"
|
||||||
|
|
||||||
#### _normal_message
|
#### _normal_message
|
||||||
|
|
||||||
*usage:* _normal_message "message"
|
*usage:* _normal_message "message"
|
||||||
|
|
||||||
*alias for* send_normal_message "${CHAT[ID]}" "message"
|
*alias for:* send_normal_message "${CHAT[ID]}" "message"
|
||||||
|
|
||||||
#### _html_message
|
#### _html_message
|
||||||
|
|
||||||
*usage:* _html_message "message"
|
*usage:* _html_message "message"
|
||||||
|
|
||||||
*alias for* send_html_message "${CHAT[ID]}" "message"
|
*alias for:* send_html_message "${CHAT[ID]}" "message"
|
||||||
|
|
||||||
#### _markdown_message
|
#### _markdown_message
|
||||||
|
|
||||||
*usage:* _markdown_message "message"
|
*usage:* _markdown_message "message"
|
||||||
|
|
||||||
*alias for* send_markdown_message "${CHAT[ID]}" "message"
|
*alias for:* send_markdown_message "${CHAT[ID]}" "message"
|
||||||
|
|
||||||
----
|
----
|
||||||
|
|
||||||
|
@ -445,5 +471,5 @@ Send Input from Telegram to waiting Interactive Chat.
|
||||||
#### [Prev Best Practice](5_practice.md)
|
#### [Prev Best Practice](5_practice.md)
|
||||||
#### [Next Notes for Developers](7_develop.md)
|
#### [Next Notes for Developers](7_develop.md)
|
||||||
|
|
||||||
#### $$VERSION$$ v0.70-dev2-27-g2da31c1
|
#### $$VERSION$$ v0.70-dev3-4-g8f4b168
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
# This file is public domain in the USA and all free countries.
|
# This file is public domain in the USA and all free countries.
|
||||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||||
#
|
#
|
||||||
#### $$VERSION$$ v0.70-dev2-27-g2da31c1
|
#### $$VERSION$$ v0.70-dev3-4-g8f4b168
|
||||||
#
|
#
|
||||||
# source from commands.sh to use the aliases
|
# source from commands.sh to use the aliases
|
||||||
|
|
||||||
|
@ -46,17 +46,17 @@ _markdown_message() {
|
||||||
}
|
}
|
||||||
# easy handling of keyboards
|
# easy handling of keyboards
|
||||||
_inline_button() {
|
_inline_button() {
|
||||||
send_inline_button "${CHAT[ID]}" "${1}" "${2}" "${3}"
|
send_inline_button "${CHAT[ID]}" "" "${1}" "${2}"
|
||||||
}
|
}
|
||||||
_inline_keyboard() {
|
_inline_keyboard() {
|
||||||
send_inline_keyboard "${CHAT[ID]}" "${1}" "${2}"
|
send_inline_keyboard "${CHAT[ID]}" "" "${1}"
|
||||||
}
|
}
|
||||||
_keyboard_numpad() {
|
_keyboard_numpad() {
|
||||||
send_keyboard "${CHAT[ID]}" "${1}" '["1","2","3"],["4","5","6"],["7","8","9"],["-","0","."]' "yes"
|
send_keyboard "${CHAT[ID]}" "" '["1","2","3"],["4","5","6"],["7","8","9"],["-","0","."]' "yes"
|
||||||
}
|
}
|
||||||
_keyboard_yesno() {
|
_keyboard_yesno() {
|
||||||
send_keyboard "${CHAT[ID]}" "${1}" '["yes","no"]'
|
send_keyboard "${CHAT[ID]}" "" '["yes","no"]'
|
||||||
}
|
}
|
||||||
_del_keyboard() {
|
_del_keyboard() {
|
||||||
remove_keyboard "${CHAT[ID]}" "${1}"
|
remove_keyboard "${CHAT[ID]}" ""
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user