2021-01-30 20:36:38 +00:00
|
|
|
#### [Examples](../README.md)
|
|
|
|
|
2021-01-31 20:18:40 +00:00
|
|
|
## Bashtbot webhook example
|
2021-01-30 20:36:38 +00:00
|
|
|
|
2021-01-31 20:18:40 +00:00
|
|
|
### Webhooks
|
2021-01-30 20:36:38 +00:00
|
|
|
|
2021-02-20 07:34:42 +00:00
|
|
|
Bashbot default mode is to poll Telegram server for updates but Telegram offers webhook
|
2021-01-31 20:18:40 +00:00
|
|
|
as a more efficient method to deliver updates.
|
2021-02-20 07:34:42 +00:00
|
|
|
If your server is reachable from the Internet you can use the methods described here.
|
|
|
|
|
|
|
|
You need a valid SSL certificate or Telegram will refuse to deliever update via webhook.
|
|
|
|
A self signed certificate will not be sufficient.
|
2021-01-30 20:36:38 +00:00
|
|
|
|
|
|
|
|
2021-01-31 20:18:40 +00:00
|
|
|
#### Setup Apache webhook
|
2021-01-30 20:36:38 +00:00
|
|
|
|
2021-01-31 20:18:40 +00:00
|
|
|
Prerequisite: An Apache webserver with a valid SLL certificate chain and php enabled.
|
2021-01-30 20:36:38 +00:00
|
|
|
|
2021-01-31 20:18:40 +00:00
|
|
|
Prepare Apache to forward webhook to Bashbot:
|
2021-01-30 20:36:38 +00:00
|
|
|
|
2021-01-31 20:18:40 +00:00
|
|
|
- install bashbot as described in [Bashbot Installation](../../doc/0_install.md)
|
2021-02-15 14:17:50 +00:00
|
|
|
- create file `data-bot-bash/webhook-fifo-<botname>` (_<botname> as in `botconfig.jssh`_)
|
2021-01-31 20:18:40 +00:00
|
|
|
- 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>`
|
|
|
|
- copy all files from `examples/webhook` to new directory and change to it
|
|
|
|
- write bashbot installation directory as first line to file `BASHBOT_HOME`
|
|
|
|
- execute `php index.php`
|
2021-01-30 20:36:38 +00:00
|
|
|
|
2021-01-31 20:18:40 +00:00
|
|
|
Every call to webhook `https://<yourservername>/telegram/<your_bot_token>/` will execute
|
2021-02-15 14:17:50 +00:00
|
|
|
`index.php` and write received JSON to file `data-bot-bash/webhook-fifo-botname`.
|
2021-01-31 20:18:40 +00:00
|
|
|
E.g. the URL `https://<yourservername>/telegram/<your_bot_token>/?json={"test":"me"}`
|
2021-02-15 14:17:50 +00:00
|
|
|
will append `{"test":"me"}` to the file `data-bot-bash/webhook-fifo-<botname>`.
|
2021-01-30 20:36:38 +00:00
|
|
|
|
2021-01-31 20:18:40 +00:00
|
|
|
Now your Apache is ready to forward data to Bashbot.
|
2021-01-30 20:36:38 +00:00
|
|
|
|
|
|
|
|
2021-02-24 15:33:03 +00:00
|
|
|
#### Webhook update processing for Bashbot
|
2021-01-30 20:36:38 +00:00
|
|
|
|
2021-02-20 07:34:42 +00:00
|
|
|
To enable update processing delete the file `data-bot-bash/webhook-fifo-<botname>` after your webhook is working manually.
|
2021-02-01 11:58:57 +00:00
|
|
|
All webhook calls are now forwarded to `bin/process_update.sh` for processing.
|
2021-01-31 20:30:28 +00:00
|
|
|
|
|
|
|
Every incoming Telegram update load Bashbot once for processing one command. Even it seems overkill to load
|
2021-02-20 07:34:42 +00:00
|
|
|
Bashbot on every incoming update, it's more responsive and create less server load than polling Telegram
|
2021-01-31 20:30:28 +00:00
|
|
|
|
|
|
|
|
2021-02-24 15:33:03 +00:00
|
|
|
This webhook works without running `bashbot.sh` and thus has the following limitations:
|
|
|
|
- no startup actions
|
|
|
|
- no backgroundi* and interactive jobs
|
|
|
|
- `addons` and `BASHBOT_EVENTs' are not working
|
|
|
|
|
|
|
|
\* workaround for background jobs is to start them in the channel and execute `./bashbot.sh restartback` afterwards.
|
|
|
|
|
2021-01-31 20:30:28 +00:00
|
|
|
|
2021-02-01 09:30:47 +00:00
|
|
|
|
2021-02-20 07:34:42 +00:00
|
|
|
#### Enable webhook on Telegram side
|
2021-01-31 20:30:28 +00:00
|
|
|
|
|
|
|
To get updates via webhook your server must be reachable from the internet and you must
|
|
|
|
instruct Telegram where to deliver updates, this is done by calling bashbot function `set_webhook`.
|
|
|
|
|
|
|
|
*Example:*
|
|
|
|
|
|
|
|
```bash
|
|
|
|
bin/any_command.sh set_webhook "https://myserver.com/telegram"
|
|
|
|
```
|
|
|
|
|
|
|
|
instruct Telegram to use the URL `https://myserver.com/telegram/<your_bot_token>/` to deliver updates.
|
|
|
|
After you enable webhook to deliver Telegram updates it's no more possible to poll updates with `bashbot.sh start`.
|
|
|
|
|
|
|
|
To stop delivering of Telegram updates via webhook run `bin/any_command.sh delete_webhook`.
|
|
|
|
|
2021-02-20 07:34:42 +00:00
|
|
|
**Important**: Telegram will refuse to deliver updates if your webhook has no valid SSL certificate chain.
|
|
|
|
|
|
|
|
|
|
|
|
#### Bash webhook
|
|
|
|
|
|
|
|
A pure bash webhook implementaition is not possible without additional software because Telegram deliver
|
|
|
|
updates only over secure TLS connections and if a valid SSL certificate chain exists.
|
|
|
|
|
|
|
|
`socat` looks like a tool we can use to listen for Telegram updates from bash scripts, let's see ...
|
|
|
|
|
|
|
|
|
|
|
|
#### High traffic processing?
|
|
|
|
|
|
|
|
Initially I planned to implement a mode for `High traffic update processing` where Bashbot is started once
|
|
|
|
and read updates from the named pipe `data-bot-bash/webhook-fifo-<botname>`, similar like polling from Telegram.
|
|
|
|
|
|
|
|
But the default webhook method is so convincing and responsive that a special high traffic mode is not necessary.
|
2021-01-31 20:30:28 +00:00
|
|
|
|
|
|
|
|
2021-02-24 15:33:03 +00:00
|
|
|
#### $$VERSION$$ v1.45-dev-46-gc57e927
|
2021-01-30 20:36:38 +00:00
|
|
|
|