mirror of
https://github.com/42wim/matterbridge.git
synced 2024-11-15 08:29:25 +01:00
Support threading from other bridges to msteams
This commit is contained in:
parent
8eb6ed5639
commit
a65a81610b
@ -2,6 +2,7 @@ package bmsteams
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
@ -9,6 +10,8 @@ import (
|
|||||||
|
|
||||||
"github.com/42wim/matterbridge/bridge"
|
"github.com/42wim/matterbridge/bridge"
|
||||||
"github.com/42wim/matterbridge/bridge/config"
|
"github.com/42wim/matterbridge/bridge/config"
|
||||||
|
|
||||||
|
// "github.com/davecgh/go-spew/spew"
|
||||||
"github.com/mattn/godown"
|
"github.com/mattn/godown"
|
||||||
msgraph "github.com/yaegashi/msgraph.go/beta"
|
msgraph "github.com/yaegashi/msgraph.go/beta"
|
||||||
"github.com/yaegashi/msgraph.go/msauth"
|
"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) {
|
func (b *Bmsteams) Send(msg config.Message) (string, error) {
|
||||||
b.Log.Debugf("=> Receiving %#v", msg)
|
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()
|
ct := b.gc.Teams().ID(b.GetString("TeamID")).Channels().ID(msg.Channel).Messages().Request()
|
||||||
text := msg.Username + msg.Text
|
text := msg.Username + msg.Text
|
||||||
content := &msgraph.ItemBody{Content: &text}
|
content := &msgraph.ItemBody{Content: &text}
|
||||||
@ -86,6 +96,20 @@ func (b *Bmsteams) Send(msg config.Message) (string, error) {
|
|||||||
return *res.ID, nil
|
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) {
|
func (b *Bmsteams) getMessages(channel string) ([]msgraph.ChatMessage, error) {
|
||||||
ct := b.gc.Teams().ID(b.GetString("TeamID")).Channels().ID(channel).Messages().Request()
|
ct := b.gc.Teams().ID(b.GetString("TeamID")).Channels().ID(channel).Messages().Request()
|
||||||
rct, err := ct.Get(b.ctx)
|
rct, err := ct.Get(b.ctx)
|
||||||
|
Loading…
Reference in New Issue
Block a user