Skip to content

Commit

Permalink
added support for bot to send mentions
Browse files Browse the repository at this point in the history
  • Loading branch information
RWayne93 authored Aug 21, 2023
1 parent 33d0f31 commit 9882dcf
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
9 changes: 8 additions & 1 deletion signalbot/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
Expand Down
10 changes: 7 additions & 3 deletions signalbot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -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())
Expand Down
5 changes: 3 additions & 2 deletions signalbot/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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())

0 comments on commit 9882dcf

Please sign in to comment.