diff --git a/README.html b/README.html index 31f62fb..90dc011 100644 --- a/README.html +++ b/README.html @@ -76,7 +76,11 @@
  • Prepare a new version
  • Bashbot testsuite
  • -
  • Customize bashbot environment
  • +
  • Expert Use +
  • Examples
  • Security Considerations

    @@ -108,6 +112,6 @@

    @Gnadelwartz

    That’s it!

    If you feel that there’s something missing or if you found a bug, feel free to submit a pull request!

    -


    VERSION
    v0.90-dev-0-g75691dc

    +


    VERSION
    v0.90-dev-2-g51aa2ed

    diff --git a/README.md b/README.md index ec4a652..85c1304 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,9 @@ Bashbot [Documentation](https://github.com/topkecleon/telegram-bot-bash) and [Do * Test, Add, Push changes * Prepare a new version * Bashbot testsuite -* [Customize bashbot environment](doc/8_custom.md) +* [Expert Use](doc/8_custom.md) + * Use from CLI and Scripts + * Customize Bashbot Environment * [Examples](examples/README.md) @@ -109,4 +111,4 @@ Hey no Problem, if you are finished with your cool bot run ```dev/make-standalon If you feel that there's something missing or if you found a bug, feel free to submit a pull request! -#### $$VERSION$$ v0.90-dev-0-g75691dc +#### $$VERSION$$ v0.90-dev-2-g51aa2ed diff --git a/README.txt b/README.txt index a608cb3..3190678 100644 --- a/README.txt +++ b/README.txt @@ -67,7 +67,9 @@ all](https://core.telegram.org/bots#3-how-do-i-create-a-bot) * Test, Add, Push changes * Prepare a new version * Bashbot testsuite -* [Customize bashbot environment](doc/8_custom.md) +* [Expert Use](doc/8_custom.md) + * Use from CLI and Scripts + * Customize Bashbot Environment * [Examples](examples/README.md) @@ -158,4 +160,4 @@ down Version of your Bot](doc/7_develop.md) If you feel that there's something missing or if you found a bug, feel free to submit a pull request! -#### $$VERSION$$ v0.90-dev-0-g75691dc +#### $$VERSION$$ v0.90-dev-2-g51aa2ed diff --git a/bashbot.sh b/bashbot.sh index 486660a..2746f56 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -11,7 +11,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.90-dev-0-g75691dc +#### $$VERSION$$ v0.90-dev-2-g51aa2ed # # Exit Codes: # - 0 sucess (hopefully) @@ -35,6 +35,13 @@ fi export SCRIPT SCRIPTDIR MODULEDIR RUNDIR RUNUSER SCRIPT="$0" SCRIPTDIR="$(dirname "$0")" + +if [ "$BASHBOT_HOME" != "" ]; then + SCRIPTDIR="$BASHBOT_HOME" + [ "${BASHBOT_ETC}" = "" ] && BASHBOT_ETC="$BASHBOT_HOME" + [ "${BASHBOT_VAR}" = "" ] && BASHBOT_VAR="$BASHBOT_HOME" +fi + MODULEDIR="${SCRIPTDIR}/modules" RUNDIR="${SCRIPTDIR}" @@ -42,7 +49,7 @@ RUNDIR="${SCRIPTDIR}" RUNUSER="${USER}" # USER is overwritten by bashbot array -if [ "$1" != "source" ] && ! cd "${RUNDIR}" ; then +if [ "$1" != "source" ] && [ "$BASHBOT_HOME" != "" ] && ! cd "${RUNDIR}" ; then echo -e "${RED}ERROR: Can't change to ${RUNDIR} ...${NC}" exit 1 fi @@ -52,6 +59,7 @@ if [ ! -w "." ]; then ls -ld . fi + TOKENFILE="${BASHBOT_ETC:-.}/token" if [ ! -f "${TOKENFILE}" ]; then if [ "${CLEAR}" = "" ] && [ "$1" != "init" ]; then diff --git a/doc/8_custom.md b/doc/8_custom.md index 53d2af4..5ff6f81 100644 --- a/doc/8_custom.md +++ b/doc/8_custom.md @@ -1,16 +1,97 @@ #### [Home](../README.md) -## Customize bashbots environment + +## Expert use + +### Use bashbot from CLI and scripts +You can use bashbot to send messages, locations, venues, pictures etc from command line and scripts. + +For interactive use and script use should set and export BASHBOT_HOME to bashbots installation dir, +e.g. '/usr/local/telegram-bot-bash'. see [Bashbot environemnt](#Bashbot-environment) + +**Note:** If you don't set BASHBOT_HOME bashbot is expecting you are in the installation directory +of bashbot and will use relative pathnames to access ressources. + +#### Environment variable exported from bashbot +If you have sourced 'bashbot.sh' you have the following bashot internal variables availible to +locate varoius ressources: +```bash +COMMANDS # default ./commands.sh" +MODULEDIR # default ./modules" +TOKENFILE # default ./token" +BOTADMIN # default ./botadmin" +BOTACL # default ./botacl" +TMPDIR # default ./data-bot-bash" +COUNTFILE # default ./count" + +BOTTOKEN # default content of ${TOKENFILE} +URL # telegram api URL -default https://api.telegram.org/bot${BOTTOKEN}" +``` + +#### Interacctive use +For Test purposes you can use bashbot functions from bash command line after setting BASHBOT_HOME +and sourcing 'bashbot.sh'. +```bash +# are we running bash? +echo $SHELL +/bin/bash + +# source bashbot.sh WITHOUT BASHBOT_HOME set +./bashbot.sh source + + +# output bashbot internal variables +echo $COMMANDS $MODULEDIR $TOKENFILE $BOTADMIN $BOTACL $TMPDIR $COUNTFILE +./commands.sh ./modules ./token ./botadmin ./botacl ./data-bot-bash ./count + +# source bashbot.sh WITH BASHBOT_HOME set +export BASHBOT_HOME=/usr/local/telegram-bot-bash +source ./bashbot.sh source + +# output bashbot internal variables +echo $COMMANDS $MODULEDIR $TOKENFILE $BOTADMIN $BOTACL $TMPDIR $COUNTFILE +/usr/local/telegram-bot-bash/commands.sh /usr/local/telegram-bot-bash/modules /usr/local/telegram-bot-bash/token +/usr/local/telegram-bot-bash/botadmin /usr/local/telegram-bot-bash/botacl /usr/local/telegram-bot-bash/data-bot-bash +/usr/local/telegram-bot-bash/count + +``` +Now you can use the bashot 'send_xxx' functions to send Message, Locations, Pictures etc. to any Telegram +User or Chat you are in. See [Send Messages](2_usage.md#sending-messages). + +*Examples:* You can test this by sending messages to yourself: +```bash +# fist Hello World +send_normal_message "$(< $BOTADMIN)" "Hello World! This is my first message" + +# now with some markdown and HTML +send_markdown_message "$(< $BOTADMIN)" '*Hello World!* _This is my first markdown message_' +send_html_message "$(< $BOTADMIN)" 'Hello World! This is my first HTML message' +send_keyboard "$(< $BOTADMIN)" 'Do you like it?' '[ "Yep" , "No" ]' +``` +Nnow something more useful ... +```bash +# sending output from system commands: +send_normal_message "$(< $BOTADMIN)" "$(date)" + +send_normal_message "$(< $BOTADMIN)" "$(uptime)" + +send_normal_message "$(< $BOTADMIN)" '`'$(free)'`' +# same but sent as monospaced text +send_markdown_message "$(< $BOTADMIN)" "\`$(free)\`" +``` + + +### Bashbot environment This section describe how you can customize bashbot to your needs by setting environment variables. -### Change file locations +#### Change file locations In standard setup bashbot is self containing, this means you can place 'telegram-bot-bash' any location and run it from there. All files - programm, config, data etc - will reside in 'telegram-bot-bash'. If you want to have other locations for config, data etc, define and export the following environment variables. **Note: all specified directories and files must exist or running 'bashbot.sh' will fail.** -#### BASHBOT_ETC +##### BASHBOT_ETC Location of the files ```commands.sh```, ```mycommands.sh```, ```token```, ```botadmin```, ```botacl``` ... ```bash unset BASHBOT_ETC # keep in telegram-bot-bash (default) @@ -24,7 +105,7 @@ Location of the files ```commands.sh```, ```mycommands.sh```, ```token```, ```bo e.g. /etc/bashbot -#### BASHBOT_VAR +##### BASHBOT_VAR Location of runtime data ```data-bot-bash```, ```count``` ```bash unset BASHBOT_VAR # keep in telegram-bot-bash (default) @@ -36,7 +117,7 @@ Location of runtime data ```data-bot-bash```, ```count``` export BASHBOT_VAR "/var/spool/bashbot/bot2" # multibot configuration bot 2 ``` -#### BASHBOT_JSONSH +##### BASHBOT_JSONSH Full path to JSON.sh script, default: './JSON.sh/JSON.sh', must end with '/JSON.sh'. ```bash unset BASHBOT_JSONSH # telegram-bot-bash/JSON.sh/JSON.sh (default) @@ -46,9 +127,25 @@ Full path to JSON.sh script, default: './JSON.sh/JSON.sh', must end with '/JSON. ``` -### Change config values +##### BASHBOT_HOME +Bashbot Home directory (where bashbot is installed). If set bashbot autodetection of installation dir is disabled +and value of BASHBOT_HOME is used. -#### BASHBOT_URL +This is usefull if you want to force bashbot to always use full pathnames instead of relative ones or if you +want to tell your own scripts where to look for bashbot.sh. +```bash + unset BASHBOT_HOME # autodetection (default) + export BASHBOT_HOME "" # autodetection + + export BASHBOT_HOME "/usr/local/telegram-bot-bash" # unix like location + export BASHBOT_HOME "/usr/local/bin" # Note: you MUST set ETC, VAR and JSONSH correct to make this work! +``` + +---- + +#### Change config values + +##### BASHBOT_URL Uses given URL instead of offical telegram API URL, useful if you have your own telegram server or for testing. ```bash @@ -60,9 +157,9 @@ Uses given URL instead of offical telegram API URL, useful if you have your own ``` -#### BASHBOT_TOKEN +##### BASHBOT_TOKEN -#### BASHBOT_WGET +##### BASHBOT_WGET Bashbot uses ```curl``` to communicate with telegram server. if ```curl``` is not availible ```wget``` is used. If 'BASHBOT_WGET' is set to any value (not undefined or not empty) wget is used even is curl is availible. ```bash @@ -74,7 +171,7 @@ If 'BASHBOT_WGET' is set to any value (not undefined or not empty) wget is used ``` -#### BASHBOT_SLEEP +##### BASHBOT_SLEEP Instead of polling permanently or with a fixed delay, bashbot offers a simple adaptive polling. If messages are recieved bashbot polls with no dealy. If no messages are availible bashbot add 100ms delay for every poll until the maximum of BASHBOT_SLEEP ms. @@ -88,10 +185,10 @@ for every poll until the maximum of BASHBOT_SLEEP ms. ``` -### Testet configs as of v.07 release +#### Testet configs as of v.07 release **Note: Environment variables are not stored, you must setup them before every call to bashbot.sh, e.g. from a script.** -#### simple Unix like config, for one bot. bashbot is installed in '/usr/local/telegram-bot-bash' +##### simple Unix like config, for one bot. bashbot is installed in '/usr/local/telegram-bot-bash' ```bash # Note: all dirs and files must exist! export BASHBOT_ETC "/etc/bashbot" @@ -100,7 +197,7 @@ for every poll until the maximum of BASHBOT_SLEEP ms. /usr/local/telegram-bot-bash/bashbot.sh start ``` -#### Unix like config for one bot. bashbot.sh is installed in '/usr/bin' +##### Unix like config for one bot. bashbot.sh is installed in '/usr/bin' ```bash # Note: all dirs and files must exist! export BASHBOT_ETC "/etc/bashbot" @@ -110,7 +207,7 @@ for every poll until the maximum of BASHBOT_SLEEP ms. /usr/local/bin/bashbot.sh start ``` -#### simple multibot config, everything is keept inside 'telegram-bot-bash' dir +##### simple multibot config, everything is keept inside 'telegram-bot-bash' dir ```bash # config for running Bot 1 # Note: all dirs and files must exist! @@ -131,5 +228,5 @@ for every poll until the maximum of BASHBOT_SLEEP ms. #### [Prev Notes for Developers](7_develop.md) -#### $$VERSION$$ v0.90-dev-0-g75691dc +#### $$VERSION$$ v0.90-dev-2-g51aa2ed