Commit e2353799 authored by Tulir Asokan's avatar Tulir Asokan 🐈

Fix media bridging and some other stuff

parent 8525bd37
# Homeserver details
homeserver:
# The address that this appservice can use to connect to the homeserver.
address: https://matrix.example.com
address: http://localhost:8008
# The address that Twilio can use to download media from the homeserver.
public_address: https://matrix.example.com
# The domain of the homeserver (for MXIDs, etc).
domain: example.com
# Whether or not to verify the SSL certificate of the homeserver.
......
......@@ -25,6 +25,8 @@ class Config(BaseBridgeConfig):
copy, copy_dict = helper.copy, helper.copy_dict
copy("homeserver.public_address")
copy("appservice.community_id")
copy("bridge.username_template")
......
......@@ -148,7 +148,7 @@ class Portal(BasePortal):
ext = mimetypes.guess_extension(mime)
content = MediaMessageEventContent(body=f"{message.id}{ext}", msgtype=msgtype, url=mxc,
info=FileInfo(size=len(data), mimetype=mime))
await self.main_intent.send_message(self.mxid, content)
mxid = await self.main_intent.send_message(self.mxid, content)
if message.body:
mxid = await self.main_intent.send_text(self.mxid, message.body)
......@@ -170,6 +170,8 @@ class Portal(BasePortal):
await self.main_intent.mark_read(self.mxid, msg.mxid)
elif status.status == TwilioMessageStatus.UNDELIVERED:
await self.az.intent.react(self.mxid, msg.mxid, "\u274c")
elif status.status == TwilioMessageStatus.FAILED:
await self.az.intent.react(self.mxid, msg.mxid, "\u274c")
async def handle_matrix_message(self, sender: 'u.User', message: MessageEventContent,
event_id: EventID) -> None:
......@@ -178,7 +180,8 @@ class Portal(BasePortal):
resp = await self.twc.send_message(self.twid, message.body)
elif message.msgtype in (MessageType.AUDIO, MessageType.VIDEO, MessageType.IMAGE,
MessageType.FILE):
url = self.main_intent.api.get_download_url(message.url)
url = (f"{config['homeserver.public_address']}/_matrix/media/r0/download/"
f"{message.url[6:]}")
resp = await self.twc.send_message(self.twid, media=url)
else:
self.log.debug(f"Ignoring unknown message {message}")
......
......@@ -110,7 +110,10 @@ class Puppet(BasePuppet):
@classmethod
def get_twid_from_mxid(cls, mxid: UserID) -> Optional[TwilioUserID]:
return cls.mxid_template.parse(mxid)
parsed = cls.mxid_template.parse(mxid)
if parsed:
return TwilioUserID(cls.twid_template.format_full(parsed))
return None
@classmethod
def get_mxid_from_twid(cls, twid: TwilioUserID) -> UserID:
......
......@@ -41,7 +41,6 @@ class TwilioClient:
data = {
"From": self.sender_id,
"To": receiver,
"Body": body,
}
if body:
data["Body"] = body
......
......@@ -37,6 +37,7 @@ class TwilioMessageStatus(SerializableEnum):
READ = "read"
RECEIVED = "received"
UNDELIVERED = "undelivered"
FAILED = "failed"
@dataclass
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment