From 1569456e6c5d1cff95228b77cf14ba14f76652d6 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Sun, 25 Aug 2024 13:08:17 +0300 Subject: [PATCH] Add support for mautrix-gvoice --- api/gitlab/build.go | 4 ++-- bridgeconfig/bridgeconfig.go | 3 +++ bridgeconfig/bridgev2.tpl.yaml | 4 ++-- bridgeconfig/gvoice.tpl.yaml | 15 +++++++++++++++ cmd/bbctl/bridgeutil.go | 2 ++ cmd/bbctl/config.go | 3 ++- cmd/bbctl/run.go | 2 +- 7 files changed, 27 insertions(+), 6 deletions(-) create mode 100644 bridgeconfig/gvoice.tpl.yaml diff --git a/api/gitlab/build.go b/api/gitlab/build.go index 137d873..68b0d77 100644 --- a/api/gitlab/build.go +++ b/api/gitlab/build.go @@ -70,7 +70,7 @@ func getRefFromBridge(bridge string) (string, error) { switch bridge { case "imessage": return "master", nil - case "whatsapp", "discord", "slack", "gmessages", "signal", "imessagego", "meta": + case "whatsapp", "discord", "slack", "gmessages", "gvoice", "signal", "imessagego", "meta": return "main", nil default: return "", fmt.Errorf("unknown bridge %s", bridge) @@ -165,7 +165,7 @@ func downloadFile(ctx context.Context, artifactURL, path string) error { func needsLibolmDylib(bridge string) bool { switch bridge { - case "imessage", "whatsapp", "discord", "slack", "gmessages", "signal", "imessagego", "meta": + case "imessage", "whatsapp", "discord", "slack", "gmessages", "gvoice", "signal", "imessagego", "meta": return runtime.GOOS == "darwin" default: return false diff --git a/bridgeconfig/bridgeconfig.go b/bridgeconfig/bridgeconfig.go index 643c981..a3be67a 100644 --- a/bridgeconfig/bridgeconfig.go +++ b/bridgeconfig/bridgeconfig.go @@ -16,6 +16,9 @@ type BridgeV2Name struct { BridgeTypeName string BridgeTypeIcon string DefaultPickleKey string + + MaxInitialMessages int + MaxBackwardMessages int } type Params struct { diff --git a/bridgeconfig/bridgev2.tpl.yaml b/bridgeconfig/bridgev2.tpl.yaml index fc06104..28500a2 100644 --- a/bridgeconfig/bridgev2.tpl.yaml +++ b/bridgeconfig/bridgev2.tpl.yaml @@ -221,7 +221,7 @@ backfill: # Whether to do backfilling at all. enabled: true # Maximum number of messages to backfill in empty rooms. - max_initial_messages: 50 + max_initial_messages: {{ or .MaxInitialMessages 50 }} # Maximum number of missed messages to backfill after bridge restarts. max_catchup_messages: 500 # If a backfilled chat is older than this number of hours, @@ -237,7 +237,7 @@ backfill: # Should the backfill queue be enabled? enabled: true # Number of messages to backfill in one batch. - batch_size: 50 + batch_size: {{ or .MaxBackwardMessages 50 }} # Delay between batches in seconds. batch_delay: 20 # Maximum number of batches to backfill per portal. diff --git a/bridgeconfig/gvoice.tpl.yaml b/bridgeconfig/gvoice.tpl.yaml new file mode 100644 index 0000000..861f4a5 --- /dev/null +++ b/bridgeconfig/gvoice.tpl.yaml @@ -0,0 +1,15 @@ +# Network-specific config options +network: + # Displayname template for SMS users. Available variables: + # .Name (same as phone number in most cases) + # .PhoneNumber + displayname_template: {{ `"{{.Name}}"` }} + +{{ setfield . "CommandPrefix" "!gv" -}} +{{ setfield . "DatabaseFileName" "mautrix-gvoice" -}} +{{ setfield . "BridgeTypeName" "Google Voice" -}} +{{ setfield . "BridgeTypeIcon" "mxc://maunium.net/VOPtYGBzHLRfPTEzGgNMpeKo" -}} +{{ setfield . "DefaultPickleKey" "go.mau.fi/mautrix-gvoice" -}} +{{ setfield . "MaxInitialMessages" 10 -}} +{{ setfield . "MaxBackwardMessages" 100 -}} +{{ template "bridgev2.tpl.yaml" . }} diff --git a/cmd/bbctl/bridgeutil.go b/cmd/bbctl/bridgeutil.go index db64252..a1cd14d 100644 --- a/cmd/bbctl/bridgeutil.go +++ b/cmd/bbctl/bridgeutil.go @@ -34,6 +34,7 @@ var officialBridges = []bridgeTypeToNames{ {"whatsapp", []string{"whatsapp"}}, {"heisenbridge", []string{"irc", "heisenbridge"}}, {"gmessages", []string{"gmessages", "googlemessages", "rcs", "sms"}}, + {"gvoice", []string{"gvoice", "googlevoice"}}, } var websocketBridges = map[string]bool{ @@ -41,6 +42,7 @@ var websocketBridges = map[string]bool{ "slack": true, "whatsapp": true, "gmessages": true, + "gvoice": true, "heisenbridge": true, "imessage": true, "imessagego": true, diff --git a/cmd/bbctl/config.go b/cmd/bbctl/config.go index 79d6c3e..c96f672 100644 --- a/cmd/bbctl/config.go +++ b/cmd/bbctl/config.go @@ -217,6 +217,7 @@ var bridgeIPSuffix = map[string]string{ "slack": "35", "gmessages": "36", "imessagego": "37", + "gvoice": "38", } func doGenerateBridgeConfig(ctx *cli.Context, bridge string) (*generatedBridgeConfig, error) { @@ -343,7 +344,7 @@ func generateBridgeConfig(ctx *cli.Context) error { } var startupCommand, installInstructions string switch cfg.BridgeType { - case "imessage", "whatsapp", "discord", "slack", "gmessages", "signal", "meta": + case "imessage", "whatsapp", "discord", "slack", "gmessages", "gvoice", "signal", "meta": startupCommand = fmt.Sprintf("mautrix-%s", cfg.BridgeType) if outputPath != "config.yaml" && outputPath != "" { startupCommand += " -c " + outputPath diff --git a/cmd/bbctl/run.go b/cmd/bbctl/run.go index fb92648..4e49970 100644 --- a/cmd/bbctl/run.go +++ b/cmd/bbctl/run.go @@ -317,7 +317,7 @@ func runBridge(ctx *cli.Context) error { var bridgeArgs []string var needsWebsocketProxy bool switch cfg.BridgeType { - case "imessage", "imessagego", "whatsapp", "discord", "slack", "gmessages", "signal", "meta": + case "imessage", "imessagego", "whatsapp", "discord", "slack", "gmessages", "gvoice", "signal", "meta": binaryName := fmt.Sprintf("mautrix-%s", cfg.BridgeType) ciV2 := false switch cfg.BridgeType {