Skip to content

Commit

Permalink
Merge pull request #159 from iKonoTelecomunicaciones/158-support-base…
Browse files Browse the repository at this point in the history
…64-format-in-send-media-node

feat: ✨ Added support for base64 format in media node
  • Loading branch information
egalvis39 authored Oct 8, 2024
2 parents 8560277 + 5a8fb5a commit e03ad7a
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions menuflow/nodes/media.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import base64
import mimetypes
from io import BytesIO
from typing import Dict
Expand Down Expand Up @@ -70,9 +71,16 @@ async def load_media(self) -> MediaMessageEventContent:
"""
resp = await self.session.get(self.url)
data = await resp.read()
media_info = self.info
if resp.headers.get("Content-Type") == "application/json":
try:
data = base64.b64decode(await resp.text())
except Exception as e:
self.log.exception(f"error {e}")
return
else:
data = await resp.read()

media_info = self.info
if media_info is None:
return

Expand Down Expand Up @@ -131,6 +139,7 @@ async def run(self):
node_id=o_connection,
state=RouteState.END if not o_connection else None,
)
return
self.media_cache[self.url] = media_message

await self.send_message(room_id=self.room.room_id, content=media_message)
Expand Down

0 comments on commit e03ad7a

Please sign in to comment.