From 927f03d357725ed98c47b50f123f838dc3862eeb Mon Sep 17 00:00:00 2001 From: BuzzT <53114007+B-u-z-z-T@users.noreply.github.com> Date: Wed, 4 Sep 2024 18:14:07 +0200 Subject: [PATCH 1/2] added silent messaging to sendMessage() --- src/UniversalTelegramBot.cpp | 5 ++++- src/UniversalTelegramBot.h | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/UniversalTelegramBot.cpp b/src/UniversalTelegramBot.cpp index 86cd747..88b62a0 100644 --- a/src/UniversalTelegramBot.cpp +++ b/src/UniversalTelegramBot.cpp @@ -560,7 +560,7 @@ bool UniversalTelegramBot::sendSimpleMessage(const String& chat_id, const String } bool UniversalTelegramBot::sendMessage(const String& chat_id, const String& text, - const String& parse_mode, int message_id) { // added message_id + const String& parse_mode, int message_id, bool silent) { // added message_id DynamicJsonDocument payload(maxMessageLength); payload["chat_id"] = chat_id; @@ -572,6 +572,9 @@ bool UniversalTelegramBot::sendMessage(const String& chat_id, const String& text if (parse_mode != "") payload["parse_mode"] = parse_mode; + if (silent) // if the message should be sent silently (no ringtone) - default is not silent + payload["disable_notification"] = silent; + return sendPostMessage(payload.as(), message_id); // if message id == 0 then edit is false, else edit is true } diff --git a/src/UniversalTelegramBot.h b/src/UniversalTelegramBot.h index 5fc97ee..554c1bf 100644 --- a/src/UniversalTelegramBot.h +++ b/src/UniversalTelegramBot.h @@ -85,7 +85,7 @@ class UniversalTelegramBot { bool getMe(); bool sendSimpleMessage(const String& chat_id, const String& text, const String& parse_mode); - bool sendMessage(const String& chat_id, const String& text, const String& parse_mode = "", int message_id = 0); + bool sendMessage(const String& chat_id, const String& text, const String& parse_mode = "", int message_id = 0, bool silent=false); bool sendMessageWithReplyKeyboard(const String& chat_id, const String& text, const String& parse_mode, const String& keyboard, bool resize = false, bool oneTime = false, From bee89a29190d7137254b7f302751a4cb7bd95a3a Mon Sep 17 00:00:00 2001 From: B-u-z-z-T <53114007+B-u-z-z-T@users.noreply.github.com> Date: Wed, 4 Sep 2024 18:56:52 +0200 Subject: [PATCH 2/2] tiny error - fixed --- src/UniversalTelegramBot.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/UniversalTelegramBot.cpp b/src/UniversalTelegramBot.cpp index 88b62a0..af01734 100644 --- a/src/UniversalTelegramBot.cpp +++ b/src/UniversalTelegramBot.cpp @@ -573,7 +573,7 @@ bool UniversalTelegramBot::sendMessage(const String& chat_id, const String& text payload["parse_mode"] = parse_mode; if (silent) // if the message should be sent silently (no ringtone) - default is not silent - payload["disable_notification"] = silent; + payload["disable_notification"] = true; return sendPostMessage(payload.as(), message_id); // if message id == 0 then edit is false, else edit is true }