mirror of
https://github.com/octoleo/telegram-bot-bash.git
synced 2024-12-27 04:32:49 +00:00
doc: webhook functions bin: do not show JSON.sh error
This commit is contained in:
parent
2a3663a463
commit
4833712246
@ -15,7 +15,7 @@ USAGE='process_update.sh [-h|--help] [debug] [<file]'
|
||||
# AUTHOR: KayM (gnadelwartz), kay@rrr.de
|
||||
# CREATED: 30.01.2021 19:14
|
||||
#
|
||||
#### $$VERSION$$ v1.40-dev-9-g1e49f6c
|
||||
#### $$VERSION$$ v1.40-dev-13-g2a3663a
|
||||
#===============================================================================
|
||||
|
||||
####
|
||||
@ -32,7 +32,7 @@ print_help "${1:-nix}"
|
||||
|
||||
# read json from stdin and convert update format
|
||||
json='{"result": {"0":'"$(cat)"'}}'
|
||||
UPDATE="$(${JSONSHFILE} -b -n <<<"${json}")"
|
||||
UPDATE="$(${JSONSHFILE} -b -n <<<"${json}" 2>/dev/null)"
|
||||
|
||||
# assign to bashbot ARRAY
|
||||
Json2Array 'UPD' <<<"${UPDATE}"
|
||||
|
@ -1222,6 +1222,84 @@ https://linuxhint.com/associative_array_bash/
|
||||
https://linuxconfig.org/how-to-use-arrays-in-bash-script
|
||||
|
||||
|
||||
----
|
||||
|
||||
### Manage Webhooks
|
||||
Bashbot default mode is to poll Telegram server for updates. Telegram offers the more efficient webhook method to deliver updates.
|
||||
I recommend to use webhook with `bin/any_command.sh` to test and setup functionality, see also [webhook example](../example/webhook)
|
||||
|
||||
##### get_webhook_info
|
||||
`get_webhook_info` get current webhook status for your bot, e.g. url, waiting updates, last error.
|
||||
|
||||
*usage:* get_webhook_info
|
||||
|
||||
*example:*
|
||||
```bash
|
||||
bin/any_command.sh get_webhook_info
|
||||
|
||||
["URL"] ""
|
||||
["OK"] "true"
|
||||
["LASTERR"] ""
|
||||
["COUNT"] "0"
|
||||
["CERT"] "false"
|
||||
["result","pending_update_count"] "0"
|
||||
["ok"] "true"
|
||||
["result","has_custom_certificate"] "false"
|
||||
```
|
||||
|
||||
|
||||
##### delete_webhook
|
||||
`delete_webhook` deletes current set webhook, deletes outstanding updates if second arg is `true`
|
||||
|
||||
*usage:* delete_webhook [true|false]
|
||||
|
||||
*example:*
|
||||
|
||||
```bash
|
||||
bin/any_command.sh delete_webhook false
|
||||
|
||||
["RESULT"] "true"
|
||||
["OK"] "true"
|
||||
["result"] "true"
|
||||
["ok"] "true"
|
||||
["description"] "Webhook was deleted"
|
||||
```
|
||||
|
||||
|
||||
##### set_webhook
|
||||
`set_webhook` deletes current set webhook, deletes outstanding updates if second arg is `true`
|
||||
|
||||
*usage:* set_webhook "https://host.dom[:port][/path]" [max_conn]
|
||||
|
||||
First arg is URL to send updates to, port and path are optional. If port is given itmust be on of 443, 80, 88 or 8443.
|
||||
For security reasons your TOKEN will be added to URL, e.g. https://myhost.com -> https://myhost.com/12345678:azndfhbgdfbbbdsfg
|
||||
Second arg is max connection rate in the range 1-100, bashbot default is 1.
|
||||
|
||||
*example:*
|
||||
|
||||
```bash
|
||||
bin/any_command.sh set_webhook https://myhost.com/telegram 2
|
||||
|
||||
["OK"] "true"
|
||||
["RESULT"] "true"
|
||||
["ok"] "true"
|
||||
["result"] "true"
|
||||
["description"] "Webhook is set"
|
||||
|
||||
bin/any_command.sh get_webhook_info
|
||||
|
||||
["OK"] "true"
|
||||
["URL"] "https://myhost.com/telegram/12345678:AABBCCDDEE...aabbccee124567890/"
|
||||
["COUNT"] "0"
|
||||
["CERT"] "false"
|
||||
["ok"] "true"
|
||||
["result","ip_address"] "1.2.3.4"
|
||||
["result","url"] "https://myhost.com/telegram/12345678:AABBCCDDEE...aabbccee124567890/"
|
||||
["result","pending_update_count"] "0"
|
||||
["result","max_connections"] "2"
|
||||
["result","has_custom_certificate"] "false"
|
||||
```
|
||||
|
||||
----
|
||||
|
||||
### Aliases - shortcuts for often used functions
|
||||
@ -1493,5 +1571,5 @@ The name of your bot is available as bash variable "$ME", there is no need to ca
|
||||
#### [Prev Best Practice](5_practice.md)
|
||||
#### [Next Notes for Developers](7_develop.md)
|
||||
|
||||
#### $$VERSION$$ v1.40-dev-1-g41e2d09
|
||||
#### $$VERSION$$ v1.40-dev-13-g2a3663a
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
* @license http://www.wtfpl.net/txt/copying/ WTFPLv2
|
||||
* @since 30.01.2021 20:24
|
||||
*
|
||||
#### $$VERSION$$ v1.40-dev-12-ga289cb8
|
||||
#### $$VERSION$$ v1.40-dev-13-g2a3663a
|
||||
***********************************************************/
|
||||
|
||||
// bashbot home dir
|
||||
@ -15,17 +15,25 @@
|
||||
// webhook endpoint
|
||||
$cmd=$BASHBOT_HOME.'/bin/process_update.sh';
|
||||
|
||||
// read request data
|
||||
// prepeare read, e.g. run from CLI
|
||||
$data='';
|
||||
$input="php://input";
|
||||
if (php_sapi_name() == "cli") { $input="php://stdin"; }
|
||||
$json_file="json.txt";
|
||||
if (php_sapi_name() == "cli") {
|
||||
if(is_readable($json_file)) {
|
||||
$input=$json_file;
|
||||
} else {
|
||||
$input="php://stdin";
|
||||
}
|
||||
}
|
||||
// read request data
|
||||
if($json = file_get_contents($input)) {
|
||||
$data = $json;
|
||||
} else {
|
||||
$data = implode(" ",$_POST);
|
||||
}
|
||||
// file_put_contents('server.txt', print_r($_SERVER, TRUE));
|
||||
// file_put_contents('json.txt', $data);
|
||||
// file_put_contents($json_file, $data);
|
||||
|
||||
// process telegram update
|
||||
if ($data == '') {
|
||||
@ -55,6 +63,6 @@
|
||||
$protocol = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0';
|
||||
header($protocol.' '.$code.' '.$msg);
|
||||
}
|
||||
exit('Error '.$code.': '.$msg."\n");
|
||||
exit('Error '.$code.': '.$msg);
|
||||
}
|
||||
?>
|
||||
|
Loading…
Reference in New Issue
Block a user