mirror of
https://github.com/octoleo/telegram-bot-bash.git
synced 2024-11-25 08:47:34 +00:00
modules: processUpdates: start experimental webhooks support
This commit is contained in:
parent
c9daa822bb
commit
08b7b85d03
@ -4,9 +4,38 @@
|
|||||||
# File: processUpdates.sh
|
# File: processUpdates.sh
|
||||||
# Note: DO NOT EDIT! this file will be overwritten on update
|
# Note: DO NOT EDIT! this file will be overwritten on update
|
||||||
#
|
#
|
||||||
#### $$VERSION$$ v1.40-dev-3-g7c74824
|
#### $$VERSION$$ v1.40-dev-5-gc9daa82
|
||||||
##################################################################
|
##################################################################
|
||||||
|
|
||||||
|
##############
|
||||||
|
# manage webhooks
|
||||||
|
|
||||||
|
# $1 URL to sed updates to: https://host.dom[:port][/path], port and path are optional
|
||||||
|
# port must be 443, 80, 88 8443, TOKEN will be added to URL for security
|
||||||
|
# e.g. https://myhost.com -> https://myhost.com/12345678:azndfhbgdfbbbdsfg
|
||||||
|
# $2 max connections 1-100 default 1 (because of bash ;-)
|
||||||
|
set_webhook() {
|
||||||
|
local url='"url": "'"$1/${TOKEN}"'"'max=',"max_connections": 1'
|
||||||
|
[[ "$2" =~ ^[0-9]+$ ]] && max=',"max_connections": '"$2"''
|
||||||
|
# shellcheck disable=SC2153
|
||||||
|
sendJson "" "${url}${max}" "${URL}/setWebhook"
|
||||||
|
}
|
||||||
|
|
||||||
|
get_webhook_info() {
|
||||||
|
sendJson "" "" "${URL}/getWebhookInfo"
|
||||||
|
if [ "${BOTSENT[OK]}" = "true" ]; then
|
||||||
|
BOTSENT[URL]="${UPD[result,url]}"
|
||||||
|
BOTSENT[COUNT]="${UPD[result,getWebhookInfo]}"
|
||||||
|
BOTSENT[LASTERR]="${UPD[result,last_error_message]}"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# $1 drop pending updates true/false, default false
|
||||||
|
delete_webhook() {
|
||||||
|
local drop; [ "$1" = "true" ] && drop='"drop_pending_updates": true'
|
||||||
|
sendJson "" "${drop}" "${URL}/deleteWebhook"
|
||||||
|
}
|
||||||
|
|
||||||
################
|
################
|
||||||
# processing of updates starts here
|
# processing of updates starts here
|
||||||
process_updates() {
|
process_updates() {
|
||||||
@ -292,6 +321,11 @@ start_bot() {
|
|||||||
send_normal_message "$(getConfigKey "botadmin")" "Bot $(getConfigKey "botname") started ..." &
|
send_normal_message "$(getConfigKey "botadmin")" "Bot $(getConfigKey "botname") started ..." &
|
||||||
##########
|
##########
|
||||||
# bot is ready, start processing updates ...
|
# bot is ready, start processing updates ...
|
||||||
|
get_updates
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
get_updates(){
|
||||||
while true; do
|
while true; do
|
||||||
# adaptive sleep in ms rounded to next 0.1 s
|
# adaptive sleep in ms rounded to next 0.1 s
|
||||||
sleep "$(_round_float "${nextsleep}e-3" "1")"
|
sleep "$(_round_float "${nextsleep}e-3" "1")"
|
||||||
|
Loading…
Reference in New Issue
Block a user