Skip to content

Commit

Permalink
fix(tg): file_name is optional (fixes #83)
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Kryukov committed Jan 8, 2024
1 parent 3d23313 commit 336c9dc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
Binary file added example/plugins/assets/video.mp4
Binary file not shown.
10 changes: 10 additions & 0 deletions example/plugins/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ async def _(msg, ctx):

await ctx.reply("Document", attachments=[doc])

# Video
with open(get_path(__file__, "assets/video.mp4"), "rb") as fh:
video = Attachment(
kind=AttachmentKind.VIDEO,
content=("beach.mp4", fh.read()),
title="Beach",
)

await ctx.reply("Video", attachments=[video])

# Audio message
with open(get_path(__file__, "assets/audio.ogg"), "rb") as fh:
audio_message = Attachment(
Expand Down
4 changes: 2 additions & 2 deletions kutana/backends/telegram.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def _make_attachment(self, raw_attachment, raw_attachment_kind):
return Attachment(
id=raw_attachment["file_id"],
kind=AttachmentKind.DOCUMENT,
title=raw_attachment["file_name"],
title=raw_attachment.get("file_name"),
raw=raw_attachment,
get_file=partial(self._get_file, raw_attachment["file_id"]),
)
Expand All @@ -153,7 +153,7 @@ def _make_attachment(self, raw_attachment, raw_attachment_kind):
return Attachment(
id=raw_attachment["file_id"],
kind=AttachmentKind.VIDEO,
title=raw_attachment["file_name"],
title=raw_attachment.get("file_name"),
raw=raw_attachment,
get_file=partial(self._get_file, raw_attachment["file_id"]),
)
Expand Down

0 comments on commit 336c9dc

Please sign in to comment.