From 5d505d8e7fee7ae6ae0b8eda6b38c0096b6b87e0 Mon Sep 17 00:00:00 2001 From: Fausto Date: Fri, 6 Mar 2020 15:09:20 +0100 Subject: [PATCH] little touch-up for telegram-bot-daemon.sh (#1306) * little touch-up for telegram-bot-daemon.sh My bot sometimes receives a non-message json (spam I think) like this: {"ok":true,"result":[{"update_id":271754855, "channel_post":{"message_id":73,"chat" ...... in that case updateId has a value and chatId is empty so the markAsRead is never performed. In order to avoid that some non-message confusing the bot I propose insert an additional check. * Update telegram-bot-daemon.sh --- firmware_mod/scripts/telegram-bot-daemon.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/firmware_mod/scripts/telegram-bot-daemon.sh b/firmware_mod/scripts/telegram-bot-daemon.sh index 8e079c6..86c704b 100755 --- a/firmware_mod/scripts/telegram-bot-daemon.sh +++ b/firmware_mod/scripts/telegram-bot-daemon.sh @@ -84,12 +84,17 @@ main() { messageAttr="message" messageVal=$(echo "$json" | $JQ -r '.result[0].message // ""') [ -z "$messageVal" ] && messageAttr="edited_message" - chatId=$(echo "$json" | $JQ -r ".result[0].$messageAttr.chat.id // \"\"") + updateId=$(echo "$json" | $JQ -r '.result[0].update_id // ""') + if [ "$updateId" != "" ] && [ -z "$chatId" ]; then + markAsRead $updateId + return 0 + fi; + [ -z "$chatId" ] && return 0 # no new messages cmd=$(echo "$json" | $JQ -r ".result[0].$messageAttr.text // \"\"") - updateId=$(echo "$json" | $JQ -r '.result[0].update_id // ""') + if [ "$chatId" != "$userChatId" ]; then username=$(echo "$json" | $JQ -r ".result[0].$messageAttr.from.username // \"\"")