From 9882dcf473e608d9c8d2177e68ca1e7a0e4d6cdc Mon Sep 17 00:00:00 2001 From: RWayne93 Date: Sun, 20 Aug 2023 22:27:54 -1000 Subject: [PATCH] added support for bot to send mentions --- signalbot/api.py | 9 ++++++++- signalbot/bot.py | 10 +++++++--- signalbot/context.py | 5 +++-- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/signalbot/api.py b/signalbot/api.py index 56939d1..21709e8 100644 --- a/signalbot/api.py +++ b/signalbot/api.py @@ -25,7 +25,11 @@ async def receive(self): raise ReceiveMessagesError(e) async def send( - self, receiver: str, message: str, base64_attachments: list = None + self, + receiver: str, + message: str, + base64_attachments: list = None, + mentions: list = None # Added this line ) -> aiohttp.ClientResponse: uri = self._send_rest_uri() if base64_attachments is None: @@ -36,6 +40,9 @@ async def send( "number": self.phone_number, "recipients": [receiver], } + if mentions: # Add mentions to the payload if they exist + payload["mentions"] = mentions + try: async with aiohttp.ClientSession() as session: resp = await session.post(uri, json=payload) diff --git a/signalbot/bot.py b/signalbot/bot.py index e601084..29b8c88 100644 --- a/signalbot/bot.py +++ b/signalbot/bot.py @@ -159,10 +159,11 @@ async def send( text: str, base64_attachments: list = None, listen: bool = False, + mentions: list = None # Added this line ) -> int: resolved_receiver = self._resolve_receiver(receiver) resp = await self._signal.send( - resolved_receiver, text, base64_attachments=base64_attachments + resolved_receiver, text, base64_attachments=base64_attachments, mentions=mentions # Added mentions here ) resp_payload = await resp.json() timestamp = resp_payload["timestamp"] @@ -171,26 +172,29 @@ async def send( if listen: if self._is_phone_number(receiver): sent_message = Message( - source=receiver, # otherwise we can't respond in the right chat + source=receiver, timestamp=timestamp, type=MessageType.SYNC_MESSAGE, text=text, base64_attachments=base64_attachments, group=None, + mentions=mentions # Added mentions here ) else: sent_message = Message( - source=self._phone_number, # no need to pretend + source=self._phone_number, timestamp=timestamp, type=MessageType.SYNC_MESSAGE, text=text, base64_attachments=base64_attachments, group=receiver, + mentions=mentions # Added mentions here ) await self._ask_commands_to_handle(sent_message) return timestamp + async def react(self, message: Message, emoji: str): # TODO: check that emoji is really an emoji recipient = self._resolve_receiver(message.recipient()) diff --git a/signalbot/context.py b/signalbot/context.py index 181c83d..a8ac119 100644 --- a/signalbot/context.py +++ b/signalbot/context.py @@ -8,13 +8,14 @@ def __init__(self, bot, message: Message): self.message = message async def send( - self, text: str, base64_attachments: list = None, listen: bool = False + self, text: str, base64_attachments: list = None, listen: bool = False, mentions: list = None ): await self.bot.send( self.message.recipient(), text, base64_attachments=base64_attachments, listen=listen, + mentions=mentions # Pass mentions to bot's send ) async def react(self, emoji: str): @@ -24,4 +25,4 @@ async def start_typing(self): await self.bot.start_typing(self.message.recipient()) async def stop_typing(self): - await self.bot.stop_typing(self.message.recipient()) + await self.bot.stop_typing(self.message.recipient()) \ No newline at end of file