Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Messages from Discord to Slack duplicated on Discord side #1039

Closed
qaisjp opened this issue Mar 17, 2020 · 7 comments · Fixed by #1046 or FOSSRIT/infrastructure#79
Closed

Messages from Discord to Slack duplicated on Discord side #1039

qaisjp opened this issue Mar 17, 2020 · 7 comments · Fixed by #1046 or FOSSRIT/infrastructure#79
Assignees
Labels
Milestone

Comments

@qaisjp
Copy link
Collaborator

qaisjp commented Mar 17, 2020

Describe the bug
Message is duplicated in Discord because of bot message in Slack

To Reproduce

  1. Set up simple test discord <-> slack bridge
  2. Send message in Discord
  3. Message is bridged to Slack, which is bridged back to Discord
  4. The message you sent in Discord is duplicated in Discord

Expected behavior

Message should not be duplicated.

Screenshots/debug logs
If applicable, add screenshots to help explain your problem.
Use logs from running matterbridge -debug if possible.

Discord

image

Slack

Appears as expected on Slack (with my photo and name).

Logs

click here
➜ ./matterbridge -debug
[0000]  INFO main:         Enabling debug logging.
[0000]  INFO main:         Running version 1.16.6-dev
[0000]  INFO main:         WARNING: THIS IS A DEVELOPMENT VERSION. Things may break.
[0000] DEBUG discord:      Configuring Discord Incoming Webhook
[0000]  INFO router:       Parsing gateway mta.test
[0000]  INFO router:       Starting bridge: slack.mta
[0000]  INFO slack:        Connecting using token
[0000]  INFO slack:        slack.mta: joining test (ID: testslack.mta)
[0000] DEBUG slack:        Choosing token based receiving
[0000] DEBUG slack:        == Receiving event &slack.ConnectingEvent{Attempt:1, ConnectionCount:0}
[0000] DEBUG slack:        Unhandled incoming event: *slack.ConnectingEvent
[0000]  INFO router:       Starting bridge: discord.mta
[0000]  INFO discord:      Connecting
[0000]  INFO discord:      Connecting using webhookurl (for posting) and token
[0000]  INFO discord:      Connection succeeded
[0000] DEBUG slack:        == Receiving event &slack.ConnectedEvent{ConnectionCount:0, Info:(*slack.Info)(0xc00040a000)}
[0001] DEBUG slack:        Start listening for Slack messages
[0001] DEBUG discord:      Verifying PermissionManageWebhooks for testdiscord.mta with ID 590172620440469505
[0001]  INFO discord:      Can manage webhooks; will edit channel for global webhook on send
[0001] DEBUG slack:        getting 33 users
[0002]  INFO discord:      discord.mta: joining test (ID: testdiscord.mta)
[0002]  INFO main:         Gateway(s) started succesfully. Now relaying messages
[0002] DEBUG discord:      == Receiving event &discordgo.Message{ID:"689415941343150083", ChannelID:"590172620440469505", GuildID:"278474088903606273", Content:"PLEASE FVV", Timestamp:"2020-03-17T10:12:49.145000+00:00", EditedTimestamp:"", MentionRoles:[]string{}, Tts:false, MentionEveryone:false, Author:(*discordgo.User)(0xc000574a80), Attachments:[]*discordgo.MessageAttachment{}, Embeds:[]*discordgo.MessageEmbed{}, Mentions:[]*discordgo.User{}, Reactions:[]*discordgo.MessageReactions(nil), Pinned:false, Type:0, WebhookID:"", Member:(*discordgo.Member)(0xc000576460), MentionChannels:[]*discordgo.Channel(nil), Activity:(*discordgo.MessageActivity)(nil), Application:(*discordgo.MessageApplication)(nil), MessageReference:(*discordgo.MessageReference)(nil), Flags:0}
[0002] DEBUG discord:      <= Sending message from qaisjp on discord.mta to gateway
[0002] DEBUG discord:      <= Message is config.Message{Text:"PLEASE FVV", Channel:"test", Username:"qaisjp", UserID:"83386293446246400", Avatar:"https://cdn.discordapp.com/avatars/83386293446246400/a525dac41568459ca38bafd903af8548.jpg", Account:"discord.mta", Event:"", Protocol:"", Gateway:"", ParentID:"", Timestamp:time.Time{wall:0x0, ext:0, loc:(*time.Location)(nil)}, ID:"689415941343150083", Extra:map[string][]interface {}(nil)}
[0002] DEBUG gateway:      => Sending config.Message{Text:"PLEASE FVV", Channel:"test", Username:"qaisjp", UserID:"83386293446246400", Avatar:"https://cdn.discordapp.com/avatars/83386293446246400/a525dac41568459ca38bafd903af8548.jpg", Account:"discord.mta", Event:"", Protocol:"discord", Gateway:"mta.test", ParentID:"", Timestamp:time.Time{wall:0xbf9446885119f1e8, ext:2615190372, loc:(*time.Location)(0x3c76020)}, ID:"689415941343150083", Extra:map[string][]interface {}(nil)} from discord.mta (test) to slack.mta (test)
[0002] DEBUG slack:        => Receiving config.Message{Text:"PLEASE FVV", Channel:"test", Username:"qaisjp", UserID:"83386293446246400", Avatar:"https://cdn.discordapp.com/avatars/83386293446246400/a525dac41568459ca38bafd903af8548.jpg", Account:"discord.mta", Event:"", Protocol:"discord", Gateway:"mta.test", ParentID:"", Timestamp:time.Time{wall:0xbf9446885119f1e8, ext:2615190372, loc:(*time.Location)(0x3c76020)}, ID:"", Extra:map[string][]interface {}(nil)}
[0002] DEBUG slack:        == Receiving event &slack.MessageEvent{Msg:slack.Msg{ClientMsgID:"", Type:"message", Channel:"C4Z7JEUC8", User:"", Text:"PLEASE FVV", Timestamp:"1584439969.005400", ThreadTimestamp:"", IsStarred:false, PinnedTo:[]string(nil), Attachments:[]slack.Attachment(nil), Edited:(*slack.Edited)(nil), LastRead:"", Subscribed:false, UnreadCount:0, SubType:"bot_message", Hidden:false, DeletedTimestamp:"", EventTimestamp:"1584439969.005400", BotID:"BF5S2HSTG", Username:"qaisjp", Icons:(*slack.Icon)(0xc0003e7880), Inviter:"", Topic:"", Purpose:"", Name:"", OldName:"", Members:[]string(nil), ReplyCount:0, Replies:[]slack.Reply(nil), ParentUserId:"", Files:[]slack.File(nil), Upload:false, Comment:(*slack.Comment)(nil), ItemType:"", ReplyTo:0, Team:"T216B1U03", Reactions:[]slack.ItemReaction(nil), ResponseType:"", ReplaceOriginal:false, DeleteOriginal:false, Blocks:slack.Blocks{BlockSet:[]slack.Block(nil)}}, SubMessage:(*slack.Msg)(nil), PreviousMessage:(*slack.Msg)(nil)}
[0002] DEBUG gateway:      mID slack.mta: 1584439969.005400
[0002] DEBUG slack:        Found bot &slack.Bot{ID:"BF5S2HSTG", Name:"Chat Bridge", Deleted:false, UserID:"UF3N0SGJU", AppID:"AF3RWLXBK", Updated:1546356234, Icons:slack.Icons{Image36:"https://a.slack-edge.com/80588/img/plugins/app/bot_36.png", Image48:"https://a.slack-edge.com/80588/img/plugins/app/bot_48.png", Image72:"https://a.slack-edge.com/80588/img/plugins/app/service_72.png"}}
[0002] DEBUG slack:        <= Sending message from qaisjp on slack.mta to gateway
[0002] DEBUG slack:        GetUserInfo failed for BF5S2HSTG: user_not_found
[0002] DEBUG slack:        <= Message is &config.Message{Text:"PLEASE FVV", Channel:"test", Username:"qaisjp", UserID:"BF5S2HSTG", Avatar:"", Account:"slack.mta", Event:"", Protocol:"slack", Gateway:"", ParentID:"", Timestamp:time.Time{wall:0x0, ext:0, loc:(*time.Location)(nil)}, ID:"1584439969.005400", Extra:map[string][]interface {}{}}
[0002] DEBUG gateway:      => Sending config.Message{Text:"PLEASE FVV", Channel:"test", Username:"qaisjp", UserID:"BF5S2HSTG", Avatar:"", Account:"slack.mta", Event:"", Protocol:"slack", Gateway:"mta.test", ParentID:"", Timestamp:time.Time{wall:0xbf94468866708f98, ext:2973192208, loc:(*time.Location)(0x3c76020)}, ID:"1584439969.005400", Extra:map[string][]interface {}{}} from slack.mta (test) to discord.mta (test)
[0002] DEBUG discord:      => Receiving config.Message{Text:"PLEASE FVV", Channel:"test", Username:"qaisjp", UserID:"BF5S2HSTG", Avatar:"", Account:"slack.mta", Event:"", Protocol:"slack", Gateway:"mta.test", ParentID:"", Timestamp:time.Time{wall:0xbf94468866708f98, ext:2973192208, loc:(*time.Location)(0x3c76020)}, ID:"", Extra:map[string][]interface {}{}}
[0002] DEBUG discord:      Broadcasting using Webhook
[0002] DEBUG discord:      Setting webhook channel to "test"
[0003] DEBUG discord:      Processing webhook sending for message config.Message{Text:"PLEASE FVV", Channel:"test", Username:"qaisjp", UserID:"BF5S2HSTG", Avatar:"", Account:"slack.mta", Event:"", Protocol:"slack", Gateway:"mta.test", ParentID:"", Timestamp:time.Time{wall:0xbf94468866708f98, ext:2973192208, loc:(*time.Location)(0x3c76020)}, ID:"", Extra:map[string][]interface {}{}}
[0003] DEBUG gateway:      mID discord.mta: 689415944501461043

Environment (please complete the following information):

  • OS: [e.g. linux]
  • Matterbridge version: output of matterbridge -version
  • If self compiled: output of git rev-parse HEAD

Problem happens on my test instance

6b4b191 + #1036 (needed to make it compile), macOS

Does not happen on my production instance

c0be3e5 + few tiny patches, Linux

Additional context
Please add your configuration file (be sure to exclude or anonymize private data (tokens/passwords))

Related to #219

[discord]

[discord.mta]
Token="bot-token"
Server="278474088903606273"
RemoteNickFormat="{NICK}"
WebhookURL="https://discordapp.com/api/webhooks/684875846770753568/token"

[slack]
[slack.mta]
Token="xoxb-xxxxx-yyyy-zzzz"
RemoteNickFormat="{NICK}"


[[gateway]]
name="mta.test"
enable=true

[[gateway.inout]]
account="slack.mta"
channel="test"

[[gateway.inout]]
account="discord.mta"
channel="test"
@qaisjp qaisjp added the bug label Mar 17, 2020
@qaisjp
Copy link
Collaborator Author

qaisjp commented Mar 17, 2020

Could be related to #1018. Doing some debugging...

With this patch on this file

diff --git a/bridge/slack/handlers.go b/bridge/slack/handlers.go
index 10ed0ae5..04d30fed 100644
--- a/bridge/slack/handlers.go
+++ b/bridge/slack/handlers.go
@@ -125,6 +125,10 @@ func (b *Bslack) skipMessageEvent(ev *slack.MessageEvent) bool {
        }

        // Skip any messages that we made ourselves or from 'slackbot' (see #527).
+       fmt.Printf("Comparing ev.Username[%#v] == sSlackBotUser[%#v]\n", ev.Username, sSlackBotUser)
+       fmt.Printf("Comparing (b.rtm!=nil)[%#v] && ev.Username[%#v] == b.si.User.Name[%#v]\n", b.rtm != nil, ev.Username, b.si.User.Name)
+       fmt.Printf("Comparing attachment stuff. Result %#v\n", (len(ev.Attachments) > 0 && ev.Attachments[0].CallbackID == "matterbridge_"+b.uuid))
+       fmt.Printf("Slack event: %#v\n", ev)
        if ev.Username == sSlackBotUser ||
                (b.rtm != nil && ev.Username == b.si.User.Name) ||
                (len(ev.Attachments) > 0 && ev.Attachments[0].CallbackID == "matterbridge_"+b.uuid) {

This output is given:

➜ ./matterbridge
[2020-03-17T10:52:27Z]  INFO main:         Running version 1.16.6-dev
[2020-03-17T10:52:27Z]  INFO main:         WARNING: THIS IS A DEVELOPMENT VERSION. Things may break.
[2020-03-17T10:52:27Z]  INFO router:       Parsing gateway mta.test
[2020-03-17T10:52:27Z]  INFO router:       Starting bridge: discord.mta
[2020-03-17T10:52:27Z]  INFO discord:      Connecting
[2020-03-17T10:52:27Z]  INFO discord:      Connecting using webhookurl (for posting) and token
[2020-03-17T10:52:27Z]  INFO discord:      Connection succeeded
[2020-03-17T10:52:28Z]  INFO discord:      Can manage webhooks; will edit channel for global webhook on send
[2020-03-17T10:52:29Z]  INFO discord:      discord.mta: joining test (ID: testdiscord.mta)
[2020-03-17T10:52:29Z]  INFO router:       Starting bridge: slack.mta
[2020-03-17T10:52:29Z]  INFO slack:        Connecting using token
[2020-03-17T10:52:29Z]  INFO slack:        slack.mta: joining test (ID: testslack.mta)
[2020-03-17T10:52:29Z]  INFO main:         Gateway(s) started succesfully. Now relaying messages
Comparing ev.Username["qaisjp"] == sSlackBotUser["slackbot"]
Comparing (b.rtm!=nil)[true] && ev.Username["qaisjp"] == b.si.User.Name["chat-bridge"]
Comparing attachment stuff. Result false
Slack event: &slack.MessageEvent{Msg:slack.Msg{ClientMsgID:"", Type:"message", Channel:"C4Z7JEUC8", User:"", Text:"yes", Timestamp:"1584442356.006000", ThreadTimestamp:"", IsStarred:false, PinnedTo:[]string(nil), Attachments:[]slack.Attachment(nil), Edited:(*slack.Edited)(nil), LastRead:"", Subscribed:false, UnreadCount:0, SubType:"bot_message", Hidden:false, DeletedTimestamp:"", EventTimestamp:"1584442356.006000", BotID:"BF5S2HSTG", Username:"qaisjp", Icons:(*slack.Icon)(0xc000475420), Inviter:"", Topic:"", Purpose:"", Name:"", OldName:"", Members:[]string(nil), ReplyCount:0, Replies:[]slack.Reply(nil), ParentUserId:"", Files:[]slack.File(nil), Upload:false, Comment:(*slack.Comment)(nil), ItemType:"", ReplyTo:0, Team:"T216B1U03", Reactions:[]slack.ItemReaction(nil), ResponseType:"", ReplaceOriginal:false, DeleteOriginal:false, Blocks:slack.Blocks{BlockSet:[]slack.Block(nil)}}, SubMessage:(*slack.Msg)(nil), PreviousMessage:(*slack.Msg)(nil)}

And

return false is reached at the bottom of the function

@qaisjp
Copy link
Collaborator Author

qaisjp commented Mar 17, 2020

More context.

Running the following code (using the bot token)

func main() {
	api := slack.New("xoxb-xxxx-yyyy-zzzz")
	api.SendMessage("C4Z7JEUC8", slack.MsgOptionText("kek", true))
}

Sends this message:

image

Probably because

Logs this:

Comparing (b.rtm!=nil)[true] && ev.Username["Chat Bridge"] == b.si.User.Name["chat-bridge"]

slack b.si.User.ID "UF3N0SGJU" and ev.BotID "BF5S2HSTG" and ev.User ""

Slack event: &slack.MessageEvent{Msg:slack.Msg{ClientMsgID:"", Type:"message", Channel:"C4Z7JEUC8", User:"", Text:"kek", Timestamp:"1584446901.006900", ThreadTimestamp:"", IsStarred:false, PinnedTo:[]string(nil), Attachments:[]slack.Attachment(nil), Edited:(*slack.Edited)(nil), LastRead:"", Subscribed:false, UnreadCount:0, SubType:"bot_message", Hidden:false, DeletedTimestamp:"", EventTimestamp:"1584446901.006900", BotID:"BF5S2HSTG", Username:"Chat Bridge", Icons:(*slack.Icon)(nil), Inviter:"", Topic:"", Purpose:"", Name:"", OldName:"", Members:[]string(nil), ReplyCount:0, Replies:[]slack.Reply(nil), ParentUserId:"", Files:[]slack.File(nil), Upload:false, Comment:(*slack.Comment)(nil), ItemType:"", ReplyTo:0, Team:"T216B1U03", Reactions:[]slack.ItemReaction(nil), ResponseType:"", ReplaceOriginal:false, DeleteOriginal:false, Blocks:slack.Blocks{BlockSet:[]slack.Block(nil)}}, SubMessage:(*slack.Msg)(nil), PreviousMessage:(*slack.Msg)(nil)}

(edit later: this is because b.si.User.Name is the username set in the developer dashboard, and b.si is given on bot connection. ev.Username is the bot's display name set in the Integrations dashboard, which is contextual to the specific team.)

Click here for lots of screenshots — mainly about how I have two bot users for some reason. TLDR - reinstalling my app got rid of a ghost bot user, and it doesn't affect this issue at all

More interestingly, my app appears in the apps list, which I can PM:

image

The old version of the same app, also appears in the contact list:

image

Which is apparently a deactivated account:

image

And the app is apparently disabled:

image

Clicking "How does chat-bridge work?" shows this

image

Clicking "Settings" or "View in App Directory" will both link to https://multitheftauto.slack.com/apps/AF4ACB3V2-chat-bridge, which says "There's been a glitch":

image

On Slack, "Your Apps", my Chat Bridge app (at https://api.slack.com/apps/AF3RWLXBK/app-home) shows this:

image

Observe "legacy Bot User", which is possibly why I am running into issues.

Note that inviting the bridge shows "Bridge" and not "chat-bridge". Originally (when I first set the bridge up) it would say @chat-bridge:

image

On another Slack workspace (with a different app so a different token, but the same configuration), @chat-bridge works fine - https://api.slack.com/apps/A9C11GZ7H/app-home?:

image

image

image

The buggy one:

image

On the OAuth & Permissions tab, both of them say this:

image


Do you think I should just delete the app and start over? Or should I keep this around so that we can be legacy bots work with matterbridge? Should we support legacy bots?

Maybe it's just an old bot that I forgot I created and is now just lying around dead, despite being deleted. Who knows.


Edit: okay so I reinstalled the app and the ghost @chat-bridge went away.

@qaisjp
Copy link
Collaborator Author

qaisjp commented Mar 17, 2020

I'll try and see if we can make this use the ID only, and not compare usernames.

It still won't explain why it works fine on Linux (with an older version of matterbridge, which has a different copy of the library). But /shrug, it should solve the issue.

qaisjp added a commit to qaisjp/matterbridge that referenced this issue Mar 17, 2020
qaisjp added a commit to qaisjp/matterbridge that referenced this issue Mar 17, 2020
@qaisjp qaisjp self-assigned this Mar 17, 2020
@qaisjp
Copy link
Collaborator Author

qaisjp commented Mar 17, 2020

image

I can confirm this happens on 6b4b191 on my production instance (just upgraded).

After cherry-picking #1042 the messages are no longer duplicated.

@The-Sorce
Copy link

I also experienced the same issue with a simple Slack<->Discord bridge setup.

Can confirm the issue but I have not tested the fix.

@qaisjp qaisjp added this to the 1.17.0 milestone Mar 18, 2020
@qaisjp
Copy link
Collaborator Author

qaisjp commented Mar 20, 2020

the core issue ALL ALONG is that something is wrong with attachments, lol

image

qaisjp added a commit to qaisjp/matterbridge that referenced this issue Mar 20, 2020
@qaisjp
Copy link
Collaborator Author

qaisjp commented Mar 20, 2020

The fix in #1042 went in a completely incorrect direction.

#1046 does it properly.

qaisjp added a commit to qaisjp/matterbridge that referenced this issue Mar 20, 2020
qaisjp added a commit to qaisjp/matterbridge that referenced this issue Mar 20, 2020
42wim pushed a commit that referenced this issue Mar 21, 2020
jwflory added a commit to FOSSRIT/infrastructure that referenced this issue Mar 27, 2020
Matterbridge upstream released a new minor feature release:

    https://github.com/42wim/matterbridge/releases/tag/v1.17.0

There are a good number of changes, including support for Microsoft
Teams. (What?!) But the relevant bits of the changelog for us are below:

* general: support JSON and YAML config formats
  (42wim/matterbridge#1045)
* irc: Be less lossy when throttling IRC messages
  (42wim/matterbridge#1004)
* slack: Use upstream slack-go/slack again (42wim/matterbridge#1018)
* slack: Ignore ConnectingEvent (42wim/matterbridge#1041)
* slack: use blocks not attachments (42wim/matterbridge#1048)
* slack: Fix 42wim/matterbridge#1039: messages sent to Slack being
  synced back (42wim/matterbridge#1046)

And a hat tip to our upstream devs who made this release possible:
@qaisjp, @jakubgs, @burner1024, @notpushkin, @MartijnBraam, and @42wim.

This upgrade is currently running in production without issue. This
commit brings the config management up to date with what is currently
running out in prod.

Signed-off-by: Justin W. Flory <git@jwf.io>
kennedy pushed a commit to FOSSRIT/infrastructure that referenced this issue Mar 29, 2020
Matterbridge upstream released a new minor feature release:

    https://github.com/42wim/matterbridge/releases/tag/v1.17.0

There are a good number of changes, including support for Microsoft
Teams. (What?!) But the relevant bits of the changelog for us are below:

* general: support JSON and YAML config formats
  (42wim/matterbridge#1045)
* irc: Be less lossy when throttling IRC messages
  (42wim/matterbridge#1004)
* slack: Use upstream slack-go/slack again (42wim/matterbridge#1018)
* slack: Ignore ConnectingEvent (42wim/matterbridge#1041)
* slack: use blocks not attachments (42wim/matterbridge#1048)
* slack: Fix 42wim/matterbridge#1039: messages sent to Slack being
  synced back (42wim/matterbridge#1046)

And a hat tip to our upstream devs who made this release possible:
@qaisjp, @jakubgs, @burner1024, @notpushkin, @MartijnBraam, and @42wim.

This upgrade is currently running in production without issue. This
commit brings the config management up to date with what is currently
running out in prod.

Signed-off-by: Justin W. Flory <git@jwf.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment