mirror of
https://github.com/cwinfo/matterbridge.git
synced 2024-12-25 07:15:43 +00:00
Support sending file URLs (nctalk) (#1489)
* nctalk: support sending file URLs Signed-off-by: Gary Kim <gary@garykim.dev> * nctalk: reduce nesting Co-authored-by: Wim <wim@42.be> Signed-off-by: Gary Kim <gary@garykim.dev> Co-authored-by: Wim <wim@42.be>
This commit is contained in:
parent
4fcad8e04b
commit
efec01a92f
@ -135,9 +135,19 @@ func (b *Btalk) Send(msg config.Message) (string, error) {
|
||||
if msg.Event != "" {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
// Handle sending files if they are included
|
||||
err := b.handleSendingFile(&msg, r)
|
||||
if err != nil {
|
||||
b.Log.Errorf("Could not send files in message to room %v from %v: %v", msg.Channel, msg.Username, err)
|
||||
|
||||
return "", nil
|
||||
}
|
||||
|
||||
sentMessage, err := r.room.SendMessage(msg.Username + msg.Text)
|
||||
if err != nil {
|
||||
b.Log.Errorf("Could not send message to room %v from %v: %v", msg.Channel, msg.Username, err)
|
||||
|
||||
return "", nil
|
||||
}
|
||||
return strconv.Itoa(sentMessage.ID), nil
|
||||
@ -177,6 +187,27 @@ func (b *Btalk) handleFiles(mmsg *config.Message, message *ocs.TalkRoomMessageDa
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *Btalk) handleSendingFile(msg *config.Message, r *Broom) error {
|
||||
for _, f := range msg.Extra["file"] {
|
||||
fi := f.(config.FileInfo)
|
||||
if fi.URL == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
message := msg.Username
|
||||
if fi.Comment != "" {
|
||||
message += fi.Comment + " "
|
||||
}
|
||||
message += fi.URL
|
||||
_, err := r.room.SendMessage(message)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Spec: https://github.com/nextcloud/server/issues/1706#issue-182308785
|
||||
func formatRichObjectString(message string, parameters map[string]ocs.RichObjectString) string {
|
||||
for id, parameter := range parameters {
|
||||
|
Loading…
Reference in New Issue
Block a user