first version of send_inline_button

This commit is contained in:
Kay Marquardt (Gnadelwartz) 2019-04-24 17:34:36 +02:00
parent 0cfb9f00dc
commit 991ecd44d8
38 changed files with 65 additions and 102 deletions

View File

@ -76,4 +76,4 @@ Bashbot is not more (in)secure as any other Bot written in any other language, w
If you feel that there's something missing or if you found a bug, feel free to submit a pull request!
#### $$VERSION$$ v0.70-dev2-20-ga3b82f7
#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0

View File

@ -24,38 +24,14 @@ Bashbot https://github.com/topkecleon/telegram-bot-bash[Documentation]
and https://github.com/topkecleon/telegram-bot-bash/releases[Downloads]
are availible on www.github.com
Install bashbot
~~~~~~~~~~~~~~~
1. Go to the directory you want to install bashbot, e.g.
* your $HOME directory (install and run with your user-ID)
* /usr/local if you want to run as service
2. https://github.com/topkecleon/telegram-bot-bash/releases[Download
latest release zip from github] and extract all files.
+
As an alternative you can clone the github repository to get the latest
improvements/fixes, run bashbot test suite `All-tests.sh` afterwards to
see if code looks OK.
+
....
git clone https://github.com/topkecleon/telegram-bot-bash; test/ALL-tests.sh
....
3. Go to directory `telegram-bot-bash`, run `./bashbot.sh init` and
follow the instructions. At this point you are asked for your Bots token
given by botfather.
Update bashbot
~~~~~~~~~~~~~~
1. https://github.com/topkecleon/telegram-bot-bash/releases[Download
latest update zip from github]
2. Extract all files and copy them to your bashbot dir
3. Run `sudo ./bashbot.sh init` to setup your environment after the
update
Documentation
~~~~~~~~~~~~~
* link:doc/0_install.md[Install Bashbot]
** Install release
** Install from githup
** Update Bashbot
** Notes on Updates
* link:doc/1_firstbot.md[Create a new Telegram Bot with botfather]
* link:doc/2_usage.md[Getting Started]
** Managing your Bot
@ -79,27 +55,6 @@ Documentation
* link:doc/7_develop.md[Notes for bashbot developers]
* link:doc/8_customize.md[Customize bashbot environment]
Note on Keyboards
~~~~~~~~~~~~~~~~~
From Version 0.60 on keybord format for `send_keyboard` and
`send_message "mykeyboardstartshere ..."` was changed. Keybords are now
defined in JSON Array notation e.g. "[ \"yes\" , \"no\" ]". This has the
advantage that you can create any type of keyboard supported by
Telegram. The old format is supported for backward compatibility, but
may fail for corner cases.
_Example Keyboards_:
* yes no in two rows:
** OLD format: 'yes' 'no' (two strings)
** NEW format: '[ "yes" ] , [ "no" ]' (two arrays with a string)
* new layouts made easy with NEW format:
** Yes No in one row: '[ "yes" , "no" ]'
** Yes No plus Maybe in 2.row: '[ "yes" , "no" ] , [ "maybe" ]'
** numpad style keyboard: '[ "1" , "2" , "3" ] , [ "4" , "5" , "6" ] , [
"7" , "8" , "9" ] , [ "0" ]'
Security Considerations
~~~~~~~~~~~~~~~~~~~~~~~
@ -168,5 +123,5 @@ That's it!
If you feel that there's something missing or if you found a bug, feel
free to submit a pull request!
latexmath:[\[VERSION\]] v0.70-dev2-18-g097a841
latexmath:[\[VERSION\]] v0.70-dev2-21-g0cfb9f0
++++++++++++++++++++++++++++++++++++++++++++++

View File

@ -1,7 +1,7 @@
#!/bin/sh
# description: Start or stop telegram-bash-bot
#
#### $$VERSION$$ v0.70-dev2-18-g097a841
#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0
# shellcheck disable=SC2009
# shellcheck disable=SC2181

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-dev2-20-ga3b82f7
#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0
#
# Exit Codes:
# - 0 sucess (hopefully)
@ -334,6 +334,15 @@ remove_keyboard() {
shift 2
res="$(curl -s "$MSG_URL" --header "content-type: multipart/form-data" -F "chat_id=$chat" -F "text=$text" -F "reply_markup={\"remove_keyboard\": true}")"
}
send_inline_button() {
local chat='"chat_id": '"$1"
local text='"text": "'"$2"'"'
local button='{ "text" : "'"$3"' , "url": "'"$4"'" }'
local JSON='{ '"${chat}"' , '"${text}"' , "reply_markup": { "inline_keyboard": [[ '"${button}"' ]]} }'
# JSON='{"chat_id":$1, "text":"$2", "reply_markup": {"inline_keyboard": [[ {"text":"$3", "url":"$4"} ]]} }'
res="$(curl -d "$JSON" -H "Content-Type: application/json" -X POST "$MSG_URL")"
}
get_file() {
[ "$1" = "" ] && return

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-dev2-18-g097a841
#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0
#
# shellcheck disable=SC2154
# shellcheck disable=SC2034

View File

@ -1,5 +1,5 @@
#!/usr/bin/env bash
#### $$VERSION$$ v0.70-dev2-18-g097a841
#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0
# magic to ensure that we're always inside the root of our application,
# no matter from which directory we'll run script

View File

@ -1,5 +1,5 @@
#!/usr/bin/env bash
#### $$VERSION$$ v0.70-dev2-18-g097a841
#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0
# magic to ensure that we're always inside the root of our application,
# no matter from which directory we'll run script

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-dev2-18-g097a841
#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0
# magic to ensure that we're always inside the root of our application,
# no matter from which directory we'll run script

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-dev2-18-g097a841
#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0
# magic to ensure that we're always inside the root of our application,
# no matter from which directory we'll run script

View File

@ -1,3 +1,3 @@
# list of additional files to check from shellcheck
#### $$VERSION$$ v0.70-dev2-18-g097a841
#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0
bashbot.rc

View File

@ -1,6 +1,6 @@
#!/bin/bash
#
#### $$VERSION$$ v0.70-dev2-18-g097a841
#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0
# shellcheck disable=SC2016
#
# Easy Versioning in git:

View File

@ -14,16 +14,15 @@ Now your Bot is ready to start ...
### Install from Github
As an alternative to donwload the zip files, you can clone the github repository to get the latest improvements/fixes.
As an alternative to download the zip files, you can clone the github repository to get the latest improvements/fixes.
1. Go to the directory you want to install bashbot, e.g.
* your $HOME directory (install and run with your user-ID)
* /usr/local if you want to run as service
2. Run ```git clone https://github.com/topkecleon/telegram-bot-bash;```
2. Run ```git clone https://github.com/topkecleon/telegram-bot-bash.git```
3. Change into the directory ```telegram-bot-bash```
4. Run ``` test/ALL-tests.sh``` and if everthing finish OK ...
5. Run ```./bashbot.sh init``` to setup the environment and enter your Bots token given by botfather.
5. Run ```sudo ./bashbot.sh init``` to setup the environment and enter your Bots token given by botfather.
### Update bashbot
@ -31,15 +30,16 @@ As an alternative to donwload the zip files, you can clone the github repository
* your $HOME directory
* /usr/local
2. [Download latest release zip from github](https://github.com/topkecleon/telegram-bot-bash/releases)
3. Extract all files to you existing bashbot dir **Note** all files execpt 'mycommands.sh' and 'commands.sh' may overwritten!**
3. Extract all files to your existing bashbot dir
**Note: all files execpt 'mycommands.sh' and 'commands.sh' may overwritten!**
4. Run ```sudo ./bashbot.sh init``` to setup your environment after the update
### Notes on Updates
#### Location of tmp / data dir
From version 0.70 on the tmp dir is renamed to 'data-bot-bash' to refelect the fact that not only temporyry files are stored. an existing 'tmp-bot-bash' will be automatically after update renamed.
From version 0.70 on the tmp dir is renamed to 'data-bot-bash' to reflect the fact that not only temporary files are stored. an existing 'tmp-bot-bash' will be automatically renamed after update.
From version 0.50 on the temporary files are no more placed in '/tmp'. instead a dedicatet tmp dir is used.
From version 0.50 on the temporary files are no more placed in '/tmp'. instead a dedicated tmp dir is used.
#### Changes to send_keyboard in v0.6
From Version 0.60 on keybord format for ```send_keyboard``` and ```send_message "mykeyboardstartshere ..."``` was changed.
@ -50,8 +50,8 @@ The old format is supported for backward compatibility, but may fail for corner
*Example Keyboards*:
- yes no in two rows:
- OLD format: 'yes' 'no' (two strings)
- NEW format: '[ "yes" ] , [ "no" ]' (two arrays with a string)
- OLD format: 'yes' 'no' *(two strings)*
- NEW format: '[ "yes" ] , [ "no" ]' *(two arrays with a string)*
- new layouts made easy with NEW format:
- Yes No in one row: '[ "yes" , "no" ]'
- Yes No plus Maybe in 2.row: '[ "yes" , "no" ] , [ "maybe" ]'
@ -61,5 +61,5 @@ The old format is supported for backward compatibility, but may fail for corner
#### [Next Create Bot](1_firstbot.md)
#### $$VERSION$$ v0.70-dev2-20-ga3b82f7
#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0

View File

@ -62,5 +62,5 @@ group. This step is up to you actually.
#### [Prev Installation](0_install.md)
#### [Next Getting started](2_usage.md)
#### $$VERSION$$ v0.70-dev2-20-ga3b82f7
#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0

View File

@ -1,7 +1,7 @@
#### [Home](../README.md)
## Gettting Started
THe Bots standard commands are in the ```commands.sh``` file. Vou must not add your commands to 'commands.sh' instead place them in ```mycommands.sh```, there you also find examples how to process messages and send out text.
The Bots standard commands are in ```commands.sh``` file. You must not add your commands to 'commands.sh', instead place them in ```mycommands.sh```, there you also find examples how to process messages and send out text.
Once you're done with editing 'mycommands.sh' start the Bot with ```./bashbot.sh start```.
If some thing doesn't work as it should, debug with ```bash -x bashbot.sh```. To stop the Bot run ```./bashbot.sh kill```
@ -166,5 +166,5 @@ send_action "${CHAT[ID]}" "action"
#### [Prev Create Bot](1_firstbot.md)
#### [Next Advanced Usage](3_advanced.md)
#### $$VERSION$$ v0.70-dev2-20-ga3b82f7
#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0

View File

@ -156,5 +156,5 @@ answer_inline_query "$iQUERY_ID" "cached_sticker" "identifier for the sticker"
#### [Prev Advanced Usage](3_advanced.md)
#### [Next Expert Use](4_expert.md)
#### $$VERSION$$ v0.70-dev2-20-ga3b82f7
#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0

View File

@ -104,5 +104,5 @@ An example crontab is provided in ```examples/bashbot.cron```.
#### [Prev Expert Use](4_expert.md)
#### [Next Best Practice](5_practice.md)
#### $$VERSION$$ v0.70-dev2-20-ga3b82f7
#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0

View File

@ -2,7 +2,7 @@
## Best Practices
### Add commands to mycommands.sh only
To ease Updates never change ```bashbot.sh```, instead your commands and functions must go to ```mycommands.sh``` . Insert your Bot commands in the ```case ... esac``` block of the 'mycommands()' function:
To ease updates never change ```bashbot.sh```, instead your commands and functions must go to ```mycommands.sh``` . Insert your Bot commands in the ```case ... esac``` block of the 'mycommands()' function:
```bash
# file: mycommands.sh
# your additional bahsbot commands
@ -32,7 +32,6 @@ every line from ```'/command')``` to ```;;```.
**Note: Never disable the catchall command ``*)```` in 'commands.sh'!!**
```bash
#!/bin/bash
# file: commands.sh
case "$MESSAGE" in
@ -59,10 +58,10 @@ every line from ```'/command')``` to ```;;```.
### Seperate logic from commands
If a command need more than 2-3 lines of code, you should use a function to seperate logic from command. Place your functions in ```mycommands.sh``` and call the from you commands. Example:
If a command need more than 2-3 lines of code, you should use a function to seperate logic from command. Place your functions in ```mycommands.sh``` and call the from your command. Example:
```bash
#!/bin/bash
# file: mycommands.sh
# your additional bahsbot commands
mycommands() {
@ -142,5 +141,5 @@ The second warning is about an unused variable, this is true because in our exam
#### [Prev Best Practice](5_practice.md)
#### [Next Functions Reference](6_reference.md)
#### $$VERSION$$ v0.70-dev2-20-ga3b82f7
#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0

View File

@ -445,5 +445,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-dev2-20-ga3b82f7
#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0

View File

@ -71,5 +71,5 @@ fi
#### [Prev Function Reference](6_function.md)
#### [Next Bashbot Environment](8_custom.md)
#### $$VERSION$$ v0.70-dev2-20-ga3b82f7
#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0

View File

@ -131,5 +131,5 @@ for every poll until the maximum of BASHBOT_SLEEP ms.
#### [Prev Notes for Developers](7_develop.md)
#### $$VERSION$$ v0.70-dev2-20-ga3b82f7
#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0

View File

@ -7,7 +7,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-dev2-18-g097a841
#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0
SHELL=/bin/sh

View File

@ -3,7 +3,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-dev2-18-g097a841
#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0
# adjust your language setting here
# https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment

View File

@ -2,7 +2,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-dev2-18-g097a841
#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0
# adjust your language setting here
# https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment

View File

@ -3,7 +3,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-dev2-18-g097a841
#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0
# adjust your language setting here
# https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment

View File

@ -3,7 +3,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-dev2-18-g097a841
#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0
# adjust your language setting here
# https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment

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-dev2-18-g097a841
#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0
# source from commands.sh to use the aliases
# some handy aliases for use when processing messages:

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-dev2-18-g097a841
#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0
# source from commands.sh if you want ro use interactive or background jobs

View File

@ -5,6 +5,6 @@
# 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-dev2-18-g097a841
#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0
# source from commands.sh to use the inline functions

View File

@ -2,7 +2,7 @@
# files: mycommands.sh.dist
# copy to mycommands.sh and add all your commands and functions here ...
#
#### $$VERSION$$ v0.70-dev2-19-g262bb9e
#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0
#
# shellcheck disable=SC2154
# shellcheck disable=SC2034

View File

@ -2,7 +2,7 @@
#
# ADD a new test skeleton to test dir, but does not activate test
#
#### $$VERSION$$ v0.70-dev2-18-g097a841
#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0
# magic to ensure that we're always inside the root of our application,
# no matter from which directory we'll run script

View File

@ -1,5 +1,5 @@
#!/usr/bin/env bash
#### $$VERSION$$ v0.70-dev2-18-g097a841
#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0
# common variables
export TESTME DIRME TESTDIR LOGFILE REFDIR TESTNAME

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-dev2-18-g097a841
#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0
# magic to ensure that we're always inside the root of our application,
# no matter from which directory we'll run script

View File

@ -1,5 +1,5 @@
#!/usr/bin/env bash
#### $$VERSION$$ v0.70-dev2-18-g097a841
#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0
../dev/hooks/pre-commit.sh

View File

@ -1,4 +1,4 @@
#!/usr/bin/env bash
#### $$VERSION$$ v0.70-dev2-18-g097a841
#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0
../dev/hooks/pre-push.sh

View File

@ -1,5 +1,5 @@
#!/usr/bin/env bash
#### $$VERSION$$ v0.70-dev2-18-g097a841
#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0
# include common functions and definitions
# shellcheck source=test/ALL-tests.inc.sh

View File

@ -1,5 +1,5 @@
#!/usr/bin/env bash
#### $$VERSION$$ v0.70-dev2-18-g097a841
#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0
# include common functions and definitions
# shellcheck source=test/ALL-tests.inc.sh

View File

@ -1,5 +1,5 @@
#!/usr/bin/env bash
#### $$VERSION$$ v0.70-dev2-18-g097a841
#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0
# include common functions and definitions
# shellcheck source=test/ALL-tests.inc.sh

View File

@ -1,5 +1,5 @@
#!/usr/bin/env bash
#### $$VERSION$$ v0.70-dev2-18-g097a841
#### $$VERSION$$ v0.70-dev2-21-g0cfb9f0
# include common functions and definitions
# shellcheck source=test/ALL-tests.inc.sh