diff --git a/examples/webhook/README.md b/examples/webhook/README.md index bae4124..7a55688 100644 --- a/examples/webhook/README.md +++ b/examples/webhook/README.md @@ -16,7 +16,7 @@ Prerequisite: An Apache webserver with a valid SLL certificate chain and php ena Prepare Apache to forward webhook to Bashbot: - install bashbot as described in [Bashbot Installation](../../doc/0_install.md) -- create file `data-bot-bash/webhook-fifo` +- create file `data-bot-bash/webhook-fifo-` (_ as in `botconfig.jssh`_) - run `bashbot.sh init` to setup bashbot to run as same user as Apache (_e.g. www_) - go to apache web root and create directory `telegram/` - copy all files from `examples/webhook` to new directory and change to it @@ -24,16 +24,16 @@ Prepare Apache to forward webhook to Bashbot: - execute `php index.php` Every call to webhook `https:///telegram//` will execute -`index.php` and write received JSON to file `data-bot-bash/webhook-fifo`. +`index.php` and write received JSON to file `data-bot-bash/webhook-fifo-botname`. E.g. the URL `https:///telegram//?json={"test":"me"}` -will append `{"test":"me"}` to the file `data-bot-bash/webhook-fifo`. +will append `{"test":"me"}` to the file `data-bot-bash/webhook-fifo-`. Now your Apache is ready to forward data to Bashbot. #### Simple update processing -To configure `Simple update processing` delete the file `data-bot-bash/webhook-fifo` after your webhook is working. +To configure `Simple update processing` delete the file `data-bot-bash/webhook-fifo-` after your webhook is working. All webhook calls are now forwarded to `bin/process_update.sh` for processing. To start `Simple processing ` enable webhook on Telegram (_see below_). @@ -76,5 +76,5 @@ To stop delivering of Telegram updates via webhook run `bin/any_command.sh delet **Important**: Only https connections with a valid certificate chain are allowed as endpoint for webhook. -#### $$VERSION$$ v1.40-0-gf9dab50 +#### $$VERSION$$ v1.45-dev-28-g9958b5b diff --git a/examples/webhook/index.php b/examples/webhook/index.php index e7d97bf..e92e990 100644 --- a/examples/webhook/index.php +++ b/examples/webhook/index.php @@ -11,7 +11,7 @@ * @license http://www.wtfpl.net/txt/copying/ WTFPLv2 * @since 30.01.2021 20:24 * -#### $$VERSION$$ v1.40-0-gf9dab50 +#### $$VERSION$$ v1.45-dev-28-g9958b5b ***********************************************************/ // bashbot home dir @@ -26,10 +26,26 @@ } } + // bashbot config file + $CONFIG=$BASHBOT_HOME.'/botconfig.jssh'; + // set botname here or read botname from config file if unknown + $botname="unknown"; + if ($botname == "unknown" && file_exists($CONFIG)) { + $prefix='["botname"] "'; + $len=strlen($prefix); + $arr = file($CONFIG, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); + foreach ($arr as $line) { + if(substr($line, 0, $len) == $prefix) { + $botname=substr($line, $len, strlen($line)-$len-1); + } + } + + } + // script endpoint $cmd=$BASHBOT_HOME.'/bin/process_update.sh'; - // fifo endpoint - $fifo=$BASHBOT_HOME.'/data-bot-bash/webhook-fifo'; + // default fifo endpoint + $fifo=$BASHBOT_HOME.'/data-bot-bash/webhook-fifo-'.$botname; // prepeare read, e.g. run from CLI $data='';