Skip to content

Add support for Stoat bridge #2

@sh4sh

Description

@sh4sh

It'd be nice to add an integration for Stoat since it's had a surge in popularity lately.
I am sorta brain/research dumping this and I am very far from an expert. You are encouraged to comment, criticize, tell me it's all wrong.

Helpful:

  • Many resources and most of the API still refer to Stoat's former name, Revolt. They might still be compatible.
  • Stoat's API looks somewhat similar to Discord, and RevoltGo uses webhooks like Discord's bridge does, so we can probably maybe loosely follow the Discord bridge design
  • Stoat Github organization, links to project repos docs
  • Stoat Developer docs
  • Awesome Stoat, list of community libraries bots etc.
  • sentinelb51/revoltgo, seems like the best maintained Go wrapper.

Things we will for sure need to add:

  1. gateway/bridgemap/bstoat.go to register with matterbridge's Gateway
  2. RevoltGo dependency in go.mod
  3. the actual bridge at bridge/stoat/stoat.go

What do we put in bridge/stoat/stoat.go?

Listed in order of connection flow (kinda):

  • BStoat struct, Discord example. Ours will ofc look different. we for sure need a *revoltgo.Session, also userID, and channel ID/name (to match channels.go i think?)
    We will prob need to find a way to map Channel IDs to human-readable channel names since revoltgo doesn't seem to do it for us?

  • New(), Discord example creates the initial bridge instance when Gateway calls it, initialize struct, maps, config flags. no actual network calls.
    -- initialize cache here, if needed! revoltgo has its own cache, so we should check if the thing we need is already stored there. If not, we can just add cache here (or modify revoltgo I guess)

  • Connect(), Discord example. actual first network calls!
    -- read token from config (required)
    -- read server from config if set, call revoltgo.SetBaseURL() from endpoints.go
    -- create session with revoltgo.New(token) from session.go
    -- add event handlers using AddHandler() from session.go, we can add the events we want from events.go (like EventMessage, EventMessageUpdate, EventMessageDelete). Probably looks similar to Discord's handlers.go
    -- finally we can call Open() from session.go to establish our connection
    -- Discord seems to do some stuff with channel lists here, maybe we need as well?

  • JoinChannel(), Discord example. I don't fully understand what we want here.
    -- do we also have to resolve any ID<->Name things here?
    -- i haven't looked too closely at how to resolve channel names but maybe useful: revoltgo caches channel info in state.go

  • Send(), Discord example. This is the outbound message function! Gateway calls it and passes config.Message
    -- do we also have to resolve any ID<->Name things here?
    -- plug in event handlers for events that occur when we send a message, again from revoltgo's events.go. Since Gateway is calling this, do we have to store it in config.Message first?
    -- events we probably want to support: EventMessage, EventMessageUpdate, EventMessageDelete
    -- attachments/file uploads? do they go here? check AttachmentUpload() in session.go, guessing from the function you'll also need file.go
    -- Do we need other stuff in here
    -- We probably do but I need to take a break for now

  • Disconnect() using Close() in session.go, short and sweet. Discord example.

Do we need anything else? Am I missing something, or a lot of things? Lemme knowww

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions