Skip to content

Commit

Permalink
feat - adding reply on send image
Browse files Browse the repository at this point in the history
  • Loading branch information
jjpaulo2 committed Oct 4, 2024
1 parent 4d06bc0 commit 4c7a343
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
8 changes: 2 additions & 6 deletions function/telegram/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ def __init__(self, message: Message):

@cached_property
def _album_images(self) -> list[str]:
if len(self.message.images) > 1:
return self.message.images[1 : TELEGRAM_MAX_ALBUM_QUANTITY + 1]
return []
return self.message.images[1 : TELEGRAM_MAX_ALBUM_QUANTITY + 1]

@cached_property
def _album_caption(self) -> str:
Expand Down Expand Up @@ -87,9 +85,7 @@ def chat_id(self) -> str:

@cached_property
def image(self) -> str | None:
if len(self.message.images) == 1:
return self.message.images[0]
return None
return self.message.images[0]

@cached_property
def album(self) -> list[InputMediaPhoto]:
Expand Down
11 changes: 8 additions & 3 deletions function/telegram/sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,16 @@ async def _send_message(
reply_markup=message.buttons,
)

async def _send_image(self, client: Client, message: TelegramMessage):
async def _send_image(
self, client: Client, message: TelegramMessage, reply_to: int | None = None
):
try:
await client.send_photo(
chat_id=message.chat_id,
photo=message.image, # type: ignore
caption=message.content,
parse_mode=ParseMode.MARKDOWN,
reply_to_message_id=reply_to, # type: ignore
reply_markup=message.buttons,
)

Expand All @@ -82,7 +85,7 @@ async def _send_image(self, client: Client, message: TelegramMessage):

except BadRequest as exc:
self.logger.warning(str(exc))
await self._send_message(client, message)
await self._send_message(client, message, reply_to)

async def _send_album(self, client: Client, message: TelegramMessage) -> int:
sent_messages = await client.send_media_group(
Expand All @@ -100,7 +103,9 @@ async def send(self, message: TelegramMessage):
reply_to = await self._token_rotation(self._send_album, message=message)

if message.image:
await self._token_rotation(self._send_image, message=message)
await self._token_rotation(
self._send_image, message=message, reply_to=reply_to
)

else:
await self._token_rotation(
Expand Down

0 comments on commit 4c7a343

Please sign in to comment.