2
0
mirror of https://github.com/42wim/matterbridge synced 2024-11-03 15:40:24 +00:00

Add support for separate display name (nctalk) (#1506)

Signed-off-by: Gary Kim <gary@garykim.dev>
This commit is contained in:
Gary Kim 2021-06-19 15:45:19 -04:00 committed by GitHub
parent f36498421b
commit a79e632cdc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 45 additions and 12 deletions

View File

@ -85,7 +85,7 @@ func (b *Btalk) JoinChannel(channel config.ChannelInfo) error {
}
// Ignore messages that are from the bot user
if msg.ActorID == b.user.User {
if msg.ActorID == b.user.User || msg.ActorType == "bridged" {
continue
}
@ -123,7 +123,7 @@ func (b *Btalk) Send(msg config.Message) (string, error) {
return "", nil
}
sentMessage, err := r.room.SendMessage(msg.Username + msg.Text)
sentMessage, err := b.sendText(r, &msg, msg.Text)
if err != nil {
b.Log.Errorf("Could not send message to room %v from %v: %v", msg.Channel, msg.Username, err)
@ -158,6 +158,17 @@ func (b *Btalk) getRoom(token string) *Broom {
return nil
}
func (b *Btalk) sendText(r *Broom, msg *config.Message, text string) (*ocs.TalkRoomMessageData, error) {
messageToSend := &room.Message{Message: msg.Username + text}
if b.GetBool("SeparateDisplayName") {
messageToSend.Message = text
messageToSend.ActorDisplayName = msg.Username
}
return r.room.SendComplexMessage(messageToSend)
}
func (b *Btalk) handleFiles(mmsg *config.Message, message *ocs.TalkRoomMessageData) error {
for _, parameter := range message.MessageParameters {
if parameter.Type == ocs.ROSTypeFile {
@ -190,12 +201,12 @@ func (b *Btalk) handleSendingFile(msg *config.Message, r *Broom) error {
continue
}
message := msg.Username
message := ""
if fi.Comment != "" {
message += fi.Comment + " "
}
message += fi.URL
_, err := r.room.SendMessage(message)
_, err := b.sendText(r, msg, message)
if err != nil {
return err
}

2
go.mod
View File

@ -52,7 +52,7 @@ require (
github.com/zfjagann/golang-ring v0.0.0-20210116075443-7c86fdb43134
golang.org/x/image v0.0.0-20210607152325-775e3b0c77b9
golang.org/x/oauth2 v0.0.0-20210615190721-d04028783cf1
gomod.garykim.dev/nc-talk v0.2.2
gomod.garykim.dev/nc-talk v0.3.0
gopkg.in/olahol/melody.v1 v1.0.0-20170518105555-d52139073376
layeh.com/gumble v0.0.0-20200818122324-146f9205029b
)

2
go.sum
View File

@ -1319,6 +1319,8 @@ golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1N
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gomod.garykim.dev/nc-talk v0.2.2 h1:+U+daJFPPuwM7yRXYazeMHZgIBSGP6SeQURO0O5a32I=
gomod.garykim.dev/nc-talk v0.2.2/go.mod h1:q/Adot/H7iqi+H4lANopV7/xcMf+sX3AZXUXqiITwok=
gomod.garykim.dev/nc-talk v0.3.0 h1:MZxLc/gX2/+bdOw4xt6pi+qQFUQld1woGfw1hEJ0fbM=
gomod.garykim.dev/nc-talk v0.3.0/go.mod h1:q/Adot/H7iqi+H4lANopV7/xcMf+sX3AZXUXqiITwok=
google.golang.org/api v0.0.0-20180910000450-7ca32eb868bf/go.mod h1:4mhQ8q/RsB7i+udVvVy5NUi08OU8ZlA0gRVgrF7VFY0=
google.golang.org/api v0.0.0-20181030000543-1d582fd0359e/go.mod h1:4mhQ8q/RsB7i+udVvVy5NUi08OU8ZlA0gRVgrF7VFY0=
google.golang.org/api v0.0.0-20181220000619-583d854617af/go.mod h1:4mhQ8q/RsB7i+udVvVy5NUi08OU8ZlA0gRVgrF7VFY0=

View File

@ -1469,6 +1469,9 @@ Password = "talkuserpass"
# Suffix for Guest Users
GuestSuffix = " (Guest)"
# Separate display name (Note: needs to be configured from Nextcloud Talk to work)
SeparateDisplayName=false
###################################################################
# Mumble
###################################################################
@ -1883,7 +1886,7 @@ enable=true
# -------------------------------------------------------------------------------------------------------------------------------------
# telegram | chatid | -123456789 | A large negative number. see https://www.linkedin.com/pulse/telegram-bots-beginners-marco-frau
# -------------------------------------------------------------------------------------------------------------------------------------
# vk | peerid | 2000000002 | A number that starts form 2000000000. Use --debug and send any message in chat to get PeerID in the logs
# vk | peerid | 2000000002 | A number that starts form 2000000000. Use --debug and send any message in chat to get PeerID in the logs
# -------------------------------------------------------------------------------------------------------------------------------------
# whatsapp | group JID | 48111222333-123455678999@g.us | A unique group JID. If you specify an empty string, bridge will list all the possibilities
# | "Group Name" | "Family Chat" | if you specify a group name, the bridge will find hint the JID to specify. Names can change over time and are not stable.

View File

@ -56,6 +56,21 @@ type TalkRoom struct {
Token string
}
// Message represents a message to be sent
type Message struct {
Message string
ActorDisplayName string
ReplyTo int
}
func (t *Message) toParameters() map[string]string {
return map[string]string{
"message": t.Message,
"actorDisplayName": t.ActorDisplayName,
"replyTo": strconv.Itoa(t.ReplyTo),
}
}
// NewTalkRoom returns a new TalkRoom instance
// Token should be the Nextcloud Room Token (e.g. "d6zoa2zs" if the room URL is https://cloud.mydomain.me/call/d6zoa2zs)
func NewTalkRoom(tuser *user.TalkUser, token string) (*TalkRoom, error) {
@ -71,17 +86,19 @@ func NewTalkRoom(tuser *user.TalkUser, token string) (*TalkRoom, error) {
}, nil
}
// SendMessage sends a message in the Talk room
// SendMessage sends a string message in the Talk room
func (t *TalkRoom) SendMessage(msg string) (*ocs.TalkRoomMessageData, error) {
return t.SendComplexMessage(&Message{Message: msg})
}
// SendComplexMessage sends a Message type message in the talk room
func (t *TalkRoom) SendComplexMessage(msg *Message) (*ocs.TalkRoomMessageData, error) {
url := t.User.NextcloudURL + constants.BaseEndpoint + "chat/" + t.Token
requestParams := map[string]string{
"message": msg,
}
client := t.User.RequestClient(request.Client{
URL: url,
Method: "POST",
Params: requestParams,
Params: msg.toParameters(),
})
res, err := client.Do()
if err != nil {

2
vendor/modules.txt vendored
View File

@ -386,7 +386,7 @@ golang.org/x/text/unicode/norm
golang.org/x/text/width
# golang.org/x/time v0.0.0-20201208040808-7e3f01d25324
golang.org/x/time/rate
# gomod.garykim.dev/nc-talk v0.2.2
# gomod.garykim.dev/nc-talk v0.3.0
## explicit
gomod.garykim.dev/nc-talk/constants
gomod.garykim.dev/nc-talk/ocs