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

Bridging Discord and Matrtix w. Pantalaimon fails due to avatar URLs #2136

Open
christianlupus opened this issue Apr 25, 2024 · 0 comments
Open
Labels

Comments

@christianlupus
Copy link

Describe the bug
In a gateway that holds both a Discord as well as a Pantalaimon-enabled Matrix channel, sending messages from Matrix to Discord is not possible. There is nothing visible neither on the Discord channel nor the Matrix room.

Digging deeper, the Matterbridge puts some logs out that the avatar URL seems to be wrong. It has the original Pantalaimon URL embedded (at least in the logs) that is obviously not reachable from the internet. The discord part (or the server) rejects therefore the complete message.

To Reproduce

I have Matterbridge installed in a docker-compose environment. The corresponding configuration file looks like this.

The docker-compose.yml file:

version: '3.7'

volumes:
  config:
  pantalaimon-data:

services:
# Self-built image to enable WhatsApp in Matterbridge
#  app:
#    build: ./app
#    restart: unless-stopped
#    volumes:
#      - config:/config
#      - ./matterbridge.toml:/config/matterbridge.toml:ro
#    command: ["matterbridge", "-debug"]
  
  app:
    image: 42wim/matterbrigde:stable
    restart: unless-stopped
    volumes:
      - ./matterbridge.toml:/etc/matterbridge/matterbridge.toml:ro
    command: "-debug"

  pantalaimon:
    image: matrixdotorg/pantalaimon
    restart: unless-stopped
    volumes:
      - pantalaimon-data:/data
      - ./pantalaimon.conf:/data/pantalaimon.conf:ro

In the same folder, a matterbridge.toml for Matterbridge is needed:

[discord]
    [discord.rur]
        Token="XXXXX"
        Server="ZZZ"
        AutoWebhooks=true
        RemoteNickFormat="[{NICK}@{PROTOCOL}] "
        # Map threads from other bridges on discord replies
        PreserveThreading=true

[matrix]
    [matrix.matrixorg]
        # Matterbridge does not support encrypted rooms in matrix.
        # Do a MITM attack against the protocol using pantalaimon
        Server = "http://pantalaimon:8008"

        Login="username"
        Password="XXX"
        
        RemoteNickFormat="[{NICK}:{PROTOCOL}] "
        #Whether to send the homeserver suffix. eg ":matrix.org" in @username:matrix.org
        #to other bridges, or only send "username".(true only sends username)
        NoHomeServerSuffix=false

[[gateway]]

    name = "Test Bridge"
    enable = true
    [[gateway.inout]]
        account = "discord.rur"
        channel = "ID:123"
    [[gateway.inout]]
        account = "matrix.matrixorg"
        channel = "#my-room:matrix.org"

The file pantalaimon.conf is rather simple:

[Default]
LogLevel = Debug
SSL = True

[local-matrix]
Homeserver = https://matrix.org
ListenAddress = 0.0.0.0
ListenPort = 8008
SSL = False
UseKeyring = False
IgnoreVerification = True

The app/Dockerfile is necessary as I need Whatsapp support as well (not part of the bug report). Just posted here for completeness as it might be a problem in the latest built version.

FROM alpinelinux/golang AS builder
RUN go install -tags nomsteams,whatsappmulti github.com/42wim/matterbridge@master

FROM alpine
COPY --from=builder /home/build/go/bin/matterbridge /usr/bin
RUN mkdir /config
VOLUME /config
WORKDIR /config
CMD ["/usr/bin/matterbridge"]
  1. Setup a docker-compose file with local pantalaimon daemon
  2. Configure Matterbridge with discord bot and Matrix user
  3. Connect one channel on discord as well as one private, encrypted room on the Matrix network.
  4. Send a message on Discord using a test user. You will see that it passes and you just verified that the credentials work.
  5. Send a message from Matrix. Nothing is reported on any Channel. (*)

(*) I had WhatsApp in the gateway as well. The message was successfully forwarded to Whatsapp but not Discord. So only a problem in the Matrix/Discord communication.

Expected behavior
The messages from Matrix should be forwarded to the Discord channel.

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

level=debug msg="=> Send from matrix.matrixorg (#my-room:matrix.org) to whatsapp.privat (123456789@g.us) took 1.494707729s" func=func1 file="/home/build/go/pkg/mod/github.com/42wim/matterbridge@v1.26.1-0.20230805184319-56e7bd01ca09/gateway/gateway.go:508" prefix=gateway
level=debug msg="=> Sending config.Message{Text:"Test 2", Channel:"#my-room:matrix.org", Username:"christianlupus", UserID:"@christianlupus:matrix.org", Avatar:"http://pantalaimon:8008/_matrix/media/r0/thumbnail/matrix.org/abcdef?width=37&height=37&method=crop", Account:"matrix.matrixorg", Event:"", Protocol:"matrix", Gateway:"Test Bridge", ParentID:"", Timestamp:time.Date(2024, time.April, 23, 13, 58, 12, 4487880, time.Local), ID:"$xxz", Extra:map[string][]interface {}(nil)} from matrix.matrixorg (#my-room:matrix.org) to discord.rur (ID:123)" func=SendMessage file="/home/build/go/pkg/mod/github.com/42wim/matterbridge@v1.26.1-0.20230805184319-56e7bd01ca09/gateway/gateway.go:499" prefix=gateway
level=debug msg="=> Receiving config.Message{Text:"Test 2", Channel:"ID:123", Username:"[matrix] <christianlupus>: ", UserID:"@christianlupus:matrix.org", Avatar:"http://pantalaimon:8008/_matrix/media/r0/thumbnail/matrix.org/abcdef?width=37&height=37&method=crop", Account:"matrix.matrixorg", Event:"", Protocol:"matrix", Gateway:"Test Bridge", ParentID:"", Timestamp:time.Date(2024, time.April, 23, 13, 58, 12, 4487880, time.Local), ID:"", Extra:map[string][]interface {}(nil)}" func=Send file="/home/build/go/pkg/mod/github.com/42wim/matterbridge@v1.26.1-0.20230805184319-56e7bd01ca09/bridge/discord/discord.go:254" prefix=discord
level=debug msg="Processing webhook sending for message &config.Message{Text:"Test 2", Channel:"ID:123", Username:"[matrix] <christianlupus>: ", UserID:"@christianlupus:matrix.org", Avatar:"http://pantalaimon:8008/_matrix/media/r0/thumbnail/matrix.org/abcdef?width=37&height=37&method=crop", Account:"matrix.matrixorg", Event:"", Protocol:"matrix", Gateway:"Test Bridge", ParentID:"", Timestamp:time.Date(2024, time.April, 23, 13, 58, 12, 4487880, time.Local), ID:"", Extra:map[string][]interface {}(nil)}" func=handleEventWebhook file="/home/build/go/pkg/mod/github.com/42wim/matterbridge@v1.26.1-0.20230805184319-56e7bd01ca09/bridge/discord/webhook.go:143" prefix=discord
level=error msg="Could not send text (Test 2) for message &config.Message{Text:"Test 2", Channel:"ID:123", Username:"[matrix] <christianlupus>: ", UserID:"@christianlupus:matrix.org", Avatar:"http://pantalaimon:8008/_matrix/media/r0/thumbnail/matrix.org/abcdef?width=37&height=37&method=crop", Account:"matrix.matrixorg", Event:"", Protocol:"matrix", Gateway:"Test Bridge", ParentID:"", Timestamp:time.Date(2024, time.April, 23, 13, 58, 12, 4487880, time.Local), ID:"", Extra:map[string][]interface {}(nil)}: execute failed: HTTP 400 Bad Request, {"message": "Invalid Form Body", "code": 50035, "errors": {"avatar_url": {"_errors": [{"code": "URL_TYPE_INVALID_URL", "message": "Not a well formed URL."}]}}}" func=webhookSend file="/home/build/go/pkg/mod/github.com/42wim/matterbridge@v1.26.1-0.20230805184319-56e7bd01ca09/bridge/discord/webhook.go:74" prefix=discord
level=error msg="Could not broadcast via webhook for message &config.Message{Text:"Test 2", Channel:"ID:123", Username:"[matrix] <christianlupus>: ", UserID:"@christianlupus:matrix.org", Avatar:"http://pantalaimon:8008/_matrix/media/r0/thumbnail/matrix.org/abcdef?width=37&height=37&method=crop", Account:"matrix.matrixorg", Event:"", Protocol:"matrix", Gateway:"Test Bridge", ParentID:"", Timestamp:time.Date(2024, time.April, 23, 13, 58, 12, 4487880, time.Local), ID:"", Extra:map[string][]interface {}(nil)}: execute failed: HTTP 400 Bad Request, {"message": "Invalid Form Body", "code": 50035, "errors": {"avatar_url": {"_errors": [{"code": "URL_TYPE_INVALID_URL", "message": "Not a well formed URL."}]}}}" func=handleEventWebhook file="/home/build/go/pkg/mod/github.com/42wim/matterbridge@v1.26.1-0.20230805184319-56e7bd01ca09/bridge/discord/webhook.go:146" prefix=discord
level=debug msg="=> Send from matrix.matrixorg (#my-room:matrix.org) to discord.rur (ID:123) took 282.456569ms" func=func1 file="/home/build/go/pkg/mod/github.com/42wim/matterbridge@v1.26.1-0.20230805184319-56e7bd01ca09/gateway/gateway.go:508" prefix=gateway
level=error msg="SendMessage failed: execute failed: HTTP 400 Bad Request, {"message": "Invalid Form Body", "code": 50035, "errors": {"avatar_url": {"_errors": [{"code": "URL_TYPE_INVALID_URL", "message": "Not a well formed URL."}]}}}" func=handleMessage file="/home/build/go/pkg/mod/github.com/42wim/matterbridge@v1.26.1-0.20230805184319-56e7bd01ca09/gateway/handlers.go:228" prefix=gateway

Environment (please complete the following information):

  • OS: Archlinux running Docker
  • Matterbridge version: 1.26.1-dev
  • If self compiled: output of git rev-parse HEAD -> Not applicable as build by means of go install

Additional context
The configuration file is provided in the details of the steps to reproduce.

Note the part in the error message Avatar:"http://pantalaimon:8008/_matrix/media/r0/thumbnail/matrix.org/abcdef?width=37&height=37&method=crop". This URL is part of the local docker-compose network where the pantalaimon container has the hostname pantalaimon and listens (correctly) on port 8008. I suspect there is a mapping wrong but this is just a guess from the error message.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant