From 9024f14f40061bdead43ab9eb037fcdff450574a Mon Sep 17 00:00:00 2001 From: hkc Date: Fri, 26 Aug 2022 21:24:36 +0300 Subject: [PATCH] Added silent notification option (Closes #9) --- config.ini | 4 ++++ mastoposter/integrations/telegram.py | 12 ++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/config.ini b/config.ini index 553c45c..3c84a7d 100644 --- a/config.ini +++ b/config.ini @@ -54,6 +54,10 @@ show-post-link = yes ; Should we show link to original author before post content? show-boost-from = yes +; Should we make posts silent? +; https://core.telegram.org/bots/api#sendmessage `disable_notification` +silent = true + ; Discord integration [module/discord] type = discord diff --git a/mastoposter/integrations/telegram.py b/mastoposter/integrations/telegram.py index 1d91c3d..f53fc0f 100644 --- a/mastoposter/integrations/telegram.py +++ b/mastoposter/integrations/telegram.py @@ -42,11 +42,13 @@ class TelegramIntegration(BaseIntegration): chat_id: Union[str, int], show_post_link: bool = True, show_boost_from: bool = True, + silent: bool = True, ): self.token = token self.chat_id = chat_id self.show_post_link = show_post_link self.show_boost_from = show_boost_from + self.silent = silent async def _tg_request(self, method: str, **kwargs) -> TGResponse: url = self.API_URL.format(self.token, method) @@ -59,7 +61,7 @@ class TelegramIntegration(BaseIntegration): return await self._tg_request( "sendMessage", parse_mode="HTML", - disable_notification=True, + disable_notification=self.silent, disable_web_page_preview=True, chat_id=self.chat_id, text=text, @@ -73,7 +75,7 @@ class TelegramIntegration(BaseIntegration): return await self._tg_request( "send%s" % self.MEDIA_MAPPING[media.type].title(), parse_mode="HTML", - disable_notification=True, + disable_notification=self.silent, disable_web_page_preview=True, chat_id=self.chat_id, caption=text, @@ -105,7 +107,7 @@ class TelegramIntegration(BaseIntegration): return await self._tg_request( "sendMediaGroup", - disable_notification=True, + disable_notification=self.silent, disable_web_page_preview=True, chat_id=self.chat_id, media=media_list, @@ -116,7 +118,7 @@ class TelegramIntegration(BaseIntegration): ) -> TGResponse: return await self._tg_request( "sendPoll", - disable_notification=True, + disable_notification=self.silent, disable_web_page_preview=True, chat_id=self.chat_id, question=f"Poll:{poll.id}", @@ -196,8 +198,10 @@ class TelegramIntegration(BaseIntegration): "chat_id={chat!r} " "show_post_link={show_post_link!r} " "show_boost_from={show_boost_from!r} " + "silent={silent!r}>" ).format( chat=self.chat_id, show_post_link=self.show_post_link, show_boost_from=self.show_boost_from, + silent=self.silent )