Thumbnail

rani/matterbridge.git

Clone URL: https://git.buni.party/rani/matterbridge.git

commit d766ec0d9733fa05795103d5b764418c0a223f2a Author: Wim <wim@42.be> Date: Mon Dec 30 19:46:48 2019 +0000 Support threading from other bridges to msteams diff --git a/bridge/msteams/msteams.go b/bridge/msteams/msteams.go index 4f72bd2..8c9fa26 100644 --- a/bridge/msteams/msteams.go +++ b/bridge/msteams/msteams.go @@ -26 +27 @@ package bmsteams    import (   "context" + "fmt"   "os"   "regexp"   "strings" @@ -96 +108 @@ import (     "github.com/42wim/matterbridge/bridge"   "github.com/42wim/matterbridge/bridge/config" + + // "github.com/davecgh/go-spew/spew"   "github.com/mattn/godown"   msgraph "github.com/yaegashi/msgraph.go/beta"   "github.com/yaegashi/msgraph.go/msauth" @@ -756 +7813 @@ func (b *Bmsteams) JoinChannel(channel config.ChannelInfo) error {    func (b *Bmsteams) Send(msg config.Message) (string, error) {   b.Log.Debugf("=> Receiving %#v", msg) + if msg.ParentID != "" && msg.ParentID != "msg-parent-not-found" { + return b.sendReply(msg) + } + if msg.ParentID == "msg-parent-not-found" { + msg.ParentID = "" + msg.Text = fmt.Sprintf("[thread]: %s", msg.Text) + }   ct := b.gc.Teams().ID(b.GetString("TeamID")).Channels().ID(msg.Channel).Messages().Request()   text := msg.Username + msg.Text   content := &msgraph.ItemBody{Content: &text} @@ -866 +9620 @@ func (b *Bmsteams) Send(msg config.Message) (string, error) {   return *res.ID, nil  }   +func (b *Bmsteams) sendReply(msg config.Message) (string, error) { + ct := b.gc.Teams().ID(b.GetString("TeamID")).Channels().ID(msg.Channel).Messages().ID(msg.ParentID).Replies().Request() + // Handle prefix hint for unthreaded messages. + + text := msg.Username + msg.Text + content := &msgraph.ItemBody{Content: &text} + rmsg := &msgraph.ChatMessage{Body: content} + res, err := ct.Add(b.ctx, rmsg) + if err != nil { + return "", err + } + return *res.ID, nil +} +  func (b *Bmsteams) getMessages(channel string) ([]msgraph.ChatMessage, error) {   ct := b.gc.Teams().ID(b.GetString("TeamID")).Channels().ID(channel).Messages().Request()   rct, err := ct.Get(b.ctx)