diff --git a/examples/README.md b/examples/README.md index 1e89153..55bfa80 100644 --- a/examples/README.md +++ b/examples/README.md @@ -56,6 +56,10 @@ convert existing bots. **jsonDB-keybords** contains a stripped down real world example from my bot showing the usage of jsonDB to store and retrieve values plus use of keyboards in private chats. It's an extended version of mycommands.sh.dist. Messages and help are in german. -#### $$VERSION$$ v1.30-0-g3266427 +### Webhook + +**Webhook** contains instructions on how use webhook API to get updates from telegram instead polling Telegram server. + +#### $$VERSION$$ v1.40-dev-10-gc0f1af5 diff --git a/examples/webhook/README.md b/examples/webhook/README.md new file mode 100644 index 0000000..533db63 --- /dev/null +++ b/examples/webhook/README.md @@ -0,0 +1,42 @@ +#### [Examples](../README.md) + +## Bashtbot webhook examples + +### webhooks + +Bashbot default mode is to poll Telegram server for updates. Telegram offers the more efficiemt webhook method to deliver updates. +Instead of running bashbot with `bashbot.sh start` permanently you can use the webhook method described here (experimental) + +#### Setup webhook + +To get updates with webhooks you must inform Telegram about where to deliver updates, this will be done with `set_webhook`. +For security reasons bashbot adds you bottoken to the path. + +*Example:* + +```bash +bin/any_command.sh set_webhook "https://myserver.com/telegram" +``` + +will instruct Telegram to use the URL `https://myserver.com/telegram//` to deliver updates. +After you setup webhook to deliver updates it'sno more possible to poll updates with `bashbot.sh start`. + +To stop delivering of updates with webhook run `bin/any_command.sh delete_webhook` + + +**Important**: Only https connections with a valid certificate chain are allowed as endpoint for webhook. + +#### Using Apache with php enabled + +If you have an Apache webserver with a valid SLL certificate chain and php running you can use it as webhook endpoint: + +- setup bashbot to run as the same user as your web server (_`bashbot.sh init`_) +- create the directory `telegram/` in webserver root +- copy `index.php` into new directory +- edit `index.php` to point to your bashbot installation +- setup webhook for your server (_e.g. `bin/any_command.sh set_webhook "https://myserver.com/telegram`_) + + +#### $$VERSION$$ v1.40-dev-10-gc0f1af5 + + diff --git a/examples/webhook/index.php b/examples/webhook/index.php new file mode 100644 index 0000000..78377b6 --- /dev/null +++ b/examples/webhook/index.php @@ -0,0 +1,19 @@ + diff --git a/examples/webhook/json.example b/examples/webhook/json.example new file mode 100644 index 0000000..16fdd30 --- /dev/null +++ b/examples/webhook/json.example @@ -0,0 +1,2 @@ +{"update_id":665220889, +"message":{"message_id":760,"from":{"id":586928566,"is_bot":false,"first_name":"Kay","last_name":"M","username":"KayM_Dealz","language_code":"de"},"chat":{"id":586928566,"first_name":"Kay","last_name":"M","username":"KayM_Dealz","type":"private"},"date":1612029749,"text":"/info","entities":[{"offset":0,"length":5,"type":"bot_command"}]}} \ No newline at end of file