42wim / matterbridge

bridge between mattermost, IRC, gitter, xmpp, slack, discord, telegram, rocketchat, twitch, ssh-chat, zulip, whatsapp, keybase, matrix, microsoft teams, nextcloud, mumble, vk and more with REST API (mattermost not required!)
Apache License 2.0
6.64k stars 617 forks source link

discord: Add forum channel support #1908

Open tomabrafix opened 2 years ago

tomabrafix commented 2 years ago

Discord released new "forum channel" with multiple "forums" last month. The matterbridge sadly does not support bridging to these. The forum channel has two IDs: the channel ID (the same for all forums in a forum channel) and a thread ID (different for each forum/thread). Using the forum/thread ID as channel ID in the matterbridge does not work (Unknown Channel). Manually creating and using the webhook via WebhookURL does not work either, because the discordgo library appends ?wait=true (see below).

Webhook documentation with parameter thread_id: https://discord.com/developers/docs/resources/webhook#execute-webhook

Environment

Version: 1.25.2

Operating system: Debian 10

Please describe the expected behavior.

Working bridge to discord forum channel.

Please describe the actual behavior.

SendMessage failed: execute failed: HTTP 400 Bad Request, {"code": 50035, "errors": {"thread_id": {"_errors": [{"code": "NUMBER_TYPE_COERCE", "message": "Value \"2222222222?wait=true\" is not snowflake."}]}}

Any steps to reproduce the behavior?

Try bridging to a new discord forum channel.

Example configuration file

[[gateway]]
name="example"
enable=true
    [[gateway.inout]]
    account="irc.net"
    channel="#game"
    [[gateway.inout]]
    account="discord.game"
    channel="ID:2222222222"
        [gateway.inout.options]
        WebhookURL="https://discord.com/api/webhooks/1111111111/s3cr3t-token?thread_id=2222222222"
tomabrafix commented 2 years ago

I have implemented forum channel support. In contrast to my first post, this would be the according working config:

[[gateway]]
name="example"
enable=true
    [[gateway.inout]]
    account="irc.net"
    channel="#game"
    [[gateway.inout]]
    account="discord.game"
    channel="ID:2222222222"
        [gateway.inout.options]
        ForumID="1111111111"

I am not a main Go developer, so I would appreciate any feedback or suggestions for improvement.