Make function SendOOB in vendor/github.com/matterbridge/go-xmpp/xmpp.go to send *with* actual body according to https://github.com/42wim/matterbridge/issues/1381#issuecomment-774032477
Remove the appendage ":" + fileInfo.URL in bridge/xmpp/xmpp.go. This will not modify the message so that the link to the file is not sent in the text message. Instead the media file is available as inline display in modern XMPP clients.
This commit is contained in:
@@ -6,14 +6,13 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/42wim/matterbridge/bridge"
|
||||
"github.com/42wim/matterbridge/bridge/config"
|
||||
"github.com/42wim/matterbridge/bridge/helper"
|
||||
"github.com/allilengyi/matterbridge/bridge"
|
||||
"github.com/allilengyi/matterbridge/bridge/config"
|
||||
"github.com/allilengyi/matterbridge/bridge/helper"
|
||||
"github.com/jpillora/backoff"
|
||||
"github.com/matterbridge/go-xmpp"
|
||||
"github.com/rs/xid"
|
||||
@@ -158,14 +157,9 @@ func (b *Bxmpp) postSlackCompatibleWebhook(msg config.Message) error {
|
||||
return err
|
||||
}
|
||||
|
||||
resp, err := http.Post(b.GetString("WebhookURL")+"/"+url.QueryEscape(msg.Channel), "application/json", bytes.NewReader(webhookBody))
|
||||
if err != nil {
|
||||
b.Log.Errorf("Failed to POST webhook: %s", err)
|
||||
return err
|
||||
}
|
||||
|
||||
resp, err := http.Post(b.GetString("WebhookURL")+"/"+msg.Channel, "application/json", bytes.NewReader(webhookBody))
|
||||
resp.Body.Close()
|
||||
return nil
|
||||
return err
|
||||
}
|
||||
|
||||
func (b *Bxmpp) createXMPP() error {
|
||||
@@ -352,24 +346,12 @@ func (b *Bxmpp) handleUploadFile(msg *config.Message) error {
|
||||
for _, file := range msg.Extra["file"] {
|
||||
fileInfo := file.(config.FileInfo)
|
||||
if fileInfo.Comment != "" {
|
||||
msg.Text += fileInfo.Comment + ": "
|
||||
msg.Text += fileInfo.Comment
|
||||
}
|
||||
if fileInfo.URL != "" {
|
||||
msg.Text = fileInfo.URL
|
||||
if fileInfo.Comment != "" {
|
||||
msg.Text = fileInfo.Comment + ": " + fileInfo.URL
|
||||
urlDesc = fileInfo.Comment
|
||||
}
|
||||
}
|
||||
if _, err := b.xc.Send(xmpp.Chat{
|
||||
Type: "groupchat",
|
||||
Remote: msg.Channel + "@" + b.GetString("Muc"),
|
||||
Text: msg.Username + msg.Text,
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if fileInfo.URL != "" {
|
||||
if _, err := b.xc.SendOOB(xmpp.Chat{
|
||||
Type: "groupchat",
|
||||
Remote: msg.Channel + "@" + b.GetString("Muc"),
|
||||
@@ -379,6 +361,13 @@ func (b *Bxmpp) handleUploadFile(msg *config.Message) error {
|
||||
b.Log.WithError(err).Warn("Failed to send share URL.")
|
||||
}
|
||||
}
|
||||
if _, err := b.xc.Send(xmpp.Chat{
|
||||
Type: "groupchat",
|
||||
Remote: msg.Channel + "@" + b.GetString("Muc"),
|
||||
Text: msg.Username + msg.Text,
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
8
vendor/github.com/matterbridge/go-xmpp/xmpp.go
generated
vendored
8
vendor/github.com/matterbridge/go-xmpp/xmpp.go
generated
vendored
@@ -875,7 +875,7 @@ func (c *Client) Send(chat Chat) (n int, err error) {
|
||||
return fmt.Fprintf(c.conn, stanza, xmlEscape(chat.Remote), xmlEscape(chat.Type), xmlEscape(chat.Text))
|
||||
}
|
||||
|
||||
// SendOOB sends OOB data wrapped inside an XMPP message stanza, without actual body.
|
||||
// SendOOB sends OOB data wrapped inside an XMPP message stanza, with actual body to trigger inline download for modern XMPP clients
|
||||
func (c *Client) SendOOB(chat Chat) (n int, err error) {
|
||||
var thdtext, oobtext string
|
||||
if chat.Thread != `` {
|
||||
@@ -888,8 +888,10 @@ func (c *Client) SendOOB(chat Chat) (n int, err error) {
|
||||
}
|
||||
oobtext += `</x>`
|
||||
}
|
||||
return fmt.Fprintf(c.conn, "<message to='%s' type='%s' id='%s' xml:lang='en'>"+oobtext+thdtext+"</message>",
|
||||
xmlEscape(chat.Remote), xmlEscape(chat.Type), cnonce())
|
||||
|
||||
stanza := "<message to='%s' type='%s' id='%s' xml:lang='en'> <body>"+xmlEscape(chat.Ooburl)+"</body>" + oobtext + thdtext + "</message>"
|
||||
|
||||
return fmt.Fprintf(c.conn, stanza, xmlEscape(chat.Remote), xmlEscape(chat.Type),cnonce())
|
||||
}
|
||||
|
||||
// SendOrg sends the original text without being wrapped in an XMPP message stanza.
|
||||
|
||||
Reference in New Issue
Block a user