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

Support plumbing WA groups #512

Closed
wants to merge 31 commits into from
Closed

Conversation

AndrewFerr
Copy link

Fixes #202

Plumbing is available via the open command by specifying which room to bridge a given WA group into, instead of creating a new room. The room can be specified by its ID, alias, or --here (as a shortcut to refer to the current room).

The code & UX for this is based mautrix-telegram's plumbing support, though that bridge exposes plumbing via a standalone bridge command.

TODO:

  • Add more power level checks
  • Support via the provisioning API
  • Add a de-plumbing/unbridge command (unless delete-portal is good enough)
  • Perhaps add plumbing support to the join and pm commands

@AndrewFerr AndrewFerr marked this pull request as ready for review June 10, 2022 14:07
Comment on lines +1253 to +1259
"calling `$cmdprefix bridge` and this command.\n\n" +
"Please start over by calling the bridge command again.",
)
return
} else if ce.Args[0] != "continue" {
ce.Reply("Please use `$cmdprefix continue` to confirm the bridging or " +
"`$cmdprefix cancel` to cancel.",
Copy link

@jaller94 jaller94 Jun 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are the double spaces intended?
Do string templates ask for a space after a variable name?

Suggested change
"calling `$cmdprefix bridge` and this command.\n\n" +
"Please start over by calling the bridge command again.",
)
return
} else if ce.Args[0] != "continue" {
ce.Reply("Please use `$cmdprefix continue` to confirm the bridging or " +
"`$cmdprefix cancel` to cancel.",
"calling `$cmdprefix bridge` and this command.\n\n" +
"Please start over by calling the bridge command again.",
)
return
} else if ce.Args[0] != "continue" {
ce.Reply("Please use `$cmdprefix continue` to confirm the bridging or " +
"`$cmdprefix cancel` to cancel.",

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, because of a bug in mautrix-go. Without the spaces, the message is printed as !wacancel. I'll submit a fix there when I get a chance.

$cmdprefix+sp isn't supported either, sadly.

Also check for state event PLs for unbridging/deleting portals
While creating a new WA group for a Matrix room, wait until it's
finished before auto-creating new portal rooms for joined groups.
Also:
- Check for permissions when plumbing with `create`
- Add some more checks on command arguments
- Make some help message formatting more consistent
- Match on it case-insensitively
- Check against a const instead of a re-typed literal
Namely, avoid building the message string when it's unneeded
When setting a user/puppet's power level with the bridge bot, reduce the
power level to a value below the bot's own level.

Also don't try to change levels that are >= the bot's level, or when the
bot doesn't have permissions to edit power levels.
Before preparing a portal in an existing Matrix room, check that the
room's power levels allow bridging to work properly. If not, notify the
user of which permissions are missing.

Support this for both bot commands and the provisioning API.
- Allow specifying a target room
- Make `delete-all` check for unbridge permissions
- Fix the unbridge permission check to use the target room, not the
  current room
- Make provisioning API check for unbridge permissions before swapping
  portal rooms
@AndrewFerr
Copy link
Author

This is a doozy, so I'll break down the changes:

  • Many commands now support targeting a specified (existing) room, instead of only creating a new room / targeting the room in which the command was issued:
    • open
    • create
    • join
    • set-relay/unset-relay
    • invite-link
    • delete
  • New commands:
    • bridge: plumbs the current room to a given group
    • unbridge: like delete but doesn't kick non-puppet Matrix users
  • These commands now support the provisioning API, even with a room argument
  • A race condition in create has been fixed (see 59bee47)
  • Commands that bridge/unbridge a room now require either state level permissions, or permission for a custom bridge-specific state event type of fi.mau.whatsapp.*
    • Bridge admins (set in the config file) always have bridge/unbridge permissions
  • Bot commands that alter an existing room (i.e. plumbing or unbridging a room) now ask for interactive confirmation
    • This required implementing some missing parts of the "command state" feature of bot commands
  • Before plumbing a room, the bridge warns about missing required/optional power levels the bridge needs to function properly
    • Bot commands warn via messages, which can be verbose but are probably worth it to prevent accidentally not bridging state you care about
    • Provisioning API commands warn by returning an dictionary of all power levels that the bridge bot & puppets are missing
    • If a room's power levels make it impossible to bridge it properly, the bridge refuses to plumb it
  • For plumbed rooms where the bridge bot's power level is less than 100, the bot will scale down the power levels it gives to WhatsApp puppets
    • If the bridge bot doesn't have permission to set power levels at all, it warns about it, and leaves puppet's PLs at their default

Many of these features are based on what mautrix-telegram supports.

This rebases fairly cleanly onto the tip of master (e59c4e2 at the time of writing), with only one easily-resolvable conflict. If it's preferred to rebase this PR now, I'll do it. I've already made a branch for it here.

@rollingmoai
Copy link

Can this be translated to other python based bridges such as https://github.com/mautrix/facebook (mautrix/facebook#80)?

@AndrewFerr
Copy link
Author

Can this be translated to other python based bridges such as https://github.com/mautrix/facebook (mautrix/facebook#80)?

Yes, especially since much of this PR is based on Python code from mautrix-telegram.

@Gredin67
Copy link

Is there some more work required to merge this ?

@Gredin67
Copy link

@tulir any plan to release this sometime soon?
@AndrewFerr do you plan to release this in your repo? Is it still working?

@wehlutyk
Copy link

If I can reactivate @Gredin67's question, would this be mergeable soon?

@tulir tulir closed this Oct 1, 2024
@rollingmoai
Copy link

Closed?

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

Successfully merging this pull request may close these issues.

Allow plumbing an existing Matrix room to a WhatsApp group chat
6 participants