diff options
author | Wim <wim@42.be> | 2019-12-30 19:46:48 +0100 |
---|---|---|
committer | Wim <wim@42.be> | 2020-03-01 22:19:33 +0100 |
commit | a65a81610ba30c54bdf1f2045b56b89fe469a140 (patch) | |
tree | ecc740558dce4a2be6e48e9b4ea5f040b0ced88e /bridge/msteams/msteams.go | |
parent | 8eb6ed563995d48e9835693d7a0af3155571113b (diff) | |
download | matterbridge-msglm-a65a81610ba30c54bdf1f2045b56b89fe469a140.tar.gz matterbridge-msglm-a65a81610ba30c54bdf1f2045b56b89fe469a140.tar.bz2 matterbridge-msglm-a65a81610ba30c54bdf1f2045b56b89fe469a140.zip |
Support threading from other bridges to msteams
Diffstat (limited to 'bridge/msteams/msteams.go')
-rw-r--r-- | bridge/msteams/msteams.go | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/bridge/msteams/msteams.go b/bridge/msteams/msteams.go index 4f72bd29..8c9fa265 100644 --- a/bridge/msteams/msteams.go +++ b/bridge/msteams/msteams.go @@ -2,6 +2,7 @@ package bmsteams import ( "context" + "fmt" "os" "regexp" "strings" @@ -9,6 +10,8 @@ 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" @@ -75,6 +78,13 @@ 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} @@ -86,6 +96,20 @@ 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) |