From 08b7b85d03e336def22b03a2fc69af82e1507150 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sat, 30 Jan 2021 11:38:30 +0100 Subject: [PATCH] modules: processUpdates: start experimental webhooks support --- modules/processUpdates.sh | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/modules/processUpdates.sh b/modules/processUpdates.sh index 52afda4..2e64965 100644 --- a/modules/processUpdates.sh +++ b/modules/processUpdates.sh @@ -4,9 +4,38 @@ # File: processUpdates.sh # 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 process_updates() { @@ -292,6 +321,11 @@ start_bot() { send_normal_message "$(getConfigKey "botadmin")" "Bot $(getConfigKey "botname") started ..." & ########## # bot is ready, start processing updates ... + get_updates +} + + +get_updates(){ while true; do # adaptive sleep in ms rounded to next 0.1 s sleep "$(_round_float "${nextsleep}e-3" "1")"