mirror of
https://github.com/octoleo/telegram-bot-bash.git
synced 2024-11-11 11:50:54 +00:00
example/webhook: add botname to fifo
This commit is contained in:
parent
9958b5b5e1
commit
d6f37afa3a
@ -16,7 +16,7 @@ Prerequisite: An Apache webserver with a valid SLL certificate chain and php ena
|
|||||||
Prepare Apache to forward webhook to Bashbot:
|
Prepare Apache to forward webhook to Bashbot:
|
||||||
|
|
||||||
- install bashbot as described in [Bashbot Installation](../../doc/0_install.md)
|
- 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-<botname>` (_<botname> as in `botconfig.jssh`_)
|
||||||
- run `bashbot.sh init` to setup bashbot to run as same user as Apache (_e.g. www_)
|
- 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/<your_bot_token>`
|
- go to apache web root and create directory `telegram/<your_bot_token>`
|
||||||
- copy all files from `examples/webhook` to new directory and change to it
|
- 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`
|
- execute `php index.php`
|
||||||
|
|
||||||
Every call to webhook `https://<yourservername>/telegram/<your_bot_token>/` will execute
|
Every call to webhook `https://<yourservername>/telegram/<your_bot_token>/` 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://<yourservername>/telegram/<your_bot_token>/?json={"test":"me"}`
|
E.g. the URL `https://<yourservername>/telegram/<your_bot_token>/?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-<botname>`.
|
||||||
|
|
||||||
Now your Apache is ready to forward data to Bashbot.
|
Now your Apache is ready to forward data to Bashbot.
|
||||||
|
|
||||||
|
|
||||||
#### Simple update processing
|
#### 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-<botname>` after your webhook is working.
|
||||||
All webhook calls are now forwarded to `bin/process_update.sh` for processing.
|
All webhook calls are now forwarded to `bin/process_update.sh` for processing.
|
||||||
|
|
||||||
To start `Simple processing ` enable webhook on Telegram (_see below_).
|
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.
|
**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
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
* @license http://www.wtfpl.net/txt/copying/ WTFPLv2
|
* @license http://www.wtfpl.net/txt/copying/ WTFPLv2
|
||||||
* @since 30.01.2021 20:24
|
* @since 30.01.2021 20:24
|
||||||
*
|
*
|
||||||
#### $$VERSION$$ v1.40-0-gf9dab50
|
#### $$VERSION$$ v1.45-dev-28-g9958b5b
|
||||||
***********************************************************/
|
***********************************************************/
|
||||||
|
|
||||||
// bashbot home dir
|
// 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
|
// script endpoint
|
||||||
$cmd=$BASHBOT_HOME.'/bin/process_update.sh';
|
$cmd=$BASHBOT_HOME.'/bin/process_update.sh';
|
||||||
// fifo endpoint
|
// default fifo endpoint
|
||||||
$fifo=$BASHBOT_HOME.'/data-bot-bash/webhook-fifo';
|
$fifo=$BASHBOT_HOME.'/data-bot-bash/webhook-fifo-'.$botname;
|
||||||
|
|
||||||
// prepeare read, e.g. run from CLI
|
// prepeare read, e.g. run from CLI
|
||||||
$data='';
|
$data='';
|
||||||
|
Loading…
Reference in New Issue
Block a user