42wim / matterbridge

bridge between mattermost, IRC, gitter, xmpp, slack, discord, telegram, rocketchat, twitch, ssh-chat, zulip, whatsapp, keybase, matrix, microsoft teams, nextcloud, mumble, vk and more with REST API (mattermost not required!)
Apache License 2.0
6.6k stars 615 forks source link

XMPP media is presented as link #1381

Open allilengyi opened 3 years ago

allilengyi commented 3 years ago

Describe the bug When sending an image from protocol A to xmpp then one receives a clickable link but there is no media offered to download in the client. Sure, when clicking on the link, I can view the image in the browser.

Expected behavior I expect a file offered to download in xmpp clients

Screenshots/debug logs Screenshot from XMPP client Dino Bildschirmfoto vom 2021-01-30 23-18-19

Relevant part from the matterbridge log

[0911] DEBUG xmpp:         [handleXMPP:bridge/xmpp/xmpp.go:237] == Receiving xmpp.Chat{Remote:"xr_berlin_events@conference.jabber.systemli.org/XR Berlin Events", Type:"groupchat", Text:"https://xmpp-media.extinctionrebellion.de/xrberlinevents/afe34065/file_10.jpg", Subject:"", Thread:"", Ooburl:"", Oobdesc:"", ID:"0a0484bdf90bd9c5", ReplaceID:"", Roster:xmpp.Roster(nil), Other:[]string{}, OtherElem:[]xmpp.XMLElement(nil), Stamp:time.Time{wall:0x0, ext:0, loc:(*time.Location)(nil)}}

Environment (please complete the following information):

Additional context Might this be an issue with the apache config? Permissions? ports? I checked that file sending/receiving works with the xmpp server that is used to bridge. Matterbridge config file.

[general]
#IgnoreFailureOnStart=true
MediaDownloadPath="/var/www/matterbridge/xrberlinevents"
MediaServerDownload="https://xmpp-media.extinctionrebellion.de/xrberlinevents"
MediaDownloadSize=5000000

[xmpp.xr_berlin_events]
Server="jabber.systemli.org:5222"
#Jid your userid
Jid="xr_berlin@jabber.systemli.org"
Password=""
Muc="conference.jabber.systemli.org"
Nick="XR Berlin Events"
RemoteNickFormat=""

[telegram.tgbot]
#See https://core.telegram.org/bots#6-botfather 
#and https://www.linkedin.com/pulse/telegram-bots-beginners-marco-frau
Token=""
RemoteNickFormat=""
MessageFormat="HTMLNick"

# gateway.out = nachrichten werden von der bridge in diesen Kanal gesendet. *Kein* Traffic aus dem Kanal
[[gateway]]
name="XR_Berlin_Events"
enable=true

[[gateway.out]]
account="xmpp.xr_berlin_events"
channel="xr_berlin_events"

[[gateway.in]]
account="telegram.tgbot"
channel="-100xxx"
42wim commented 3 years ago

Isn't this normal for images? You can always right-click and choose save link as ..

mwild1 commented 3 years ago

To indicate that the link is a media share, the following should be included in the message:

  <x xmlns='jabber:x:oob'>
    <url>https://...</url>
  </x>

The URL in this fragment should match the URL provided in the <body> of the message. So a full message for the file https://example.com/cat.jpg would be:

<message from='sender@xmpp.example' to='recipient@xmpp.example'>
  <body>https://example.com/cat.jpg</body>
  <x xmlns='jabber:x:oob'>
    <url>https://example.com/cat.jpg</url>
  </x>
</message>

This will trigger inline display in modern XMPP clients.

For more information see Modern XMPP: File transfer -> HTTP upload.

allilengyi commented 3 years ago

So I guess this issue is then a feature request to support HTTP Upload

mwild1 commented 3 years ago

Well it seems there is already a URL for the file, so there is no need to "upload". Just include the metadata I mentioned if you know that the URL is meant to be an inline share/attachment.

allilengyi commented 3 years ago

I am not a software developer. I am currently looking into the code, to see where things have to be changed.

allilengyi commented 3 years ago

I guess the problem is that Oobdesc is included into the message: https://github.com/42wim/matterbridge/blob/master/vendor/github.com/matterbridge/go-xmpp/xmpp.go#L878-L893

mwild1 commented 3 years ago

Ah, thanks for the link to the source. Oobdesc is something that's ignored by most clients these days (they will insist on the message body matching the URL for various reasons, including preventing the ability to spoof URLs).

So it looks like just Ooburl needs to be set when the message from the other protocol is a share/attachment, and the right metadata will be included :)

allilengyi commented 3 years ago

Ooburl ist set https://github.com/42wim/matterbridge/blob/master/bridge/xmpp/xmpp.go#L342-L378 however, SendOOB does not include the <body> tag. I will see if I can modify the code und build matterbridge on my own successfully.

sirdrakeistda commented 2 years ago

To solve this issue, this might be helpfull: https://salsa.debian.org/mdosch/go-sendxmpp/-/blob/master/httpupload.go It think it would be a good idea to implement native xmpp upload to fix this issue.