Commit d83f6892 authored by Your Name's avatar Your Name
Browse files

Fix: Ensure registration.yaml sender_localpart is always whatsappbot and...

Fix: Ensure registration.yaml sender_localpart is always whatsappbot and update Makefile for build service
parent 8aa64ef5
Loading
Loading
Loading
Loading
+11 −15
Original line number Diff line number Diff line
.PHONY: build clean package
.PHONY: clean package dev-install dev-update publish

# Repository details - change as needed
CLOUDRON_APP_ID = dev.maunium.whatsapp.cloudronapp
CLOUDRON_IMAGE_REPO = andreasdueren/mautrix-whatsapp-cloudron
CLOUDRON_TOKEN ?=
BUILD_SERVICE_TOKEN = e3265de06b1d0e7bb38400539012a8433a74c2c96a17955e

# For development, we'll use the current git commit as the version
GIT_COMMIT = $(shell git rev-parse --short HEAD 2>/dev/null || echo "dev")
VERSION ?= dev-$(GIT_COMMIT)

# Docker image for cloudron package building
CLOUDRON_BUILDER_IMAGE = cloudron/package-builder:5.0.0

all: build

build:
	docker build -t $(CLOUDRON_APP_ID) -f Dockerfile.cloudron .
all: package

# Clean build artifacts
clean:
	rm -rf build.log latest.tgz

# Package for Cloudron in a consistent environment
# Package for Cloudron using the build service
package:
	@mkdir -p build
	docker run --rm -v "$(PWD):/app" $(CLOUDRON_BUILDER_IMAGE) build --set-version $(VERSION)
	cloudron build --set-build-service builder.docker.due.ren --build-service-token $(BUILD_SERVICE_TOKEN) --set-repository $(CLOUDRON_IMAGE_REPO) --tag $(VERSION)

# For development - install directly in a test Cloudron
dev-install: package
	cloudron install --image $(CLOUDRON_APP_ID) --location whatsapp.example.com
	cloudron uninstall --app whatsapp.matrix.due.ren || true
	cloudron install --location whatsapp.matrix.due.ren --image $(CLOUDRON_IMAGE_REPO):$(VERSION)

# Update the app in a dev Cloudron
dev-update:
	cloudron update --app whatsapp.example.com --image $(CLOUDRON_APP_ID)
dev-update: package
	cloudron update --app whatsapp.matrix.due.ren --image $(CLOUDRON_IMAGE_REPO):$(VERSION)

# Publish to a Cloudron app store (requires token)
publish:
+4 −0
Original line number Diff line number Diff line
@@ -58,6 +58,7 @@ if [ ! -f "$CONFIG_PATH" ]; then
            yq -i -y '.appservice.public_address = "https://'"$CLOUDRON_APP_DOMAIN"'"' "$CONFIG_PATH" || echo "=> ERROR: Could not configure appservice public_address"
            yq -i -y '.appservice.hostname = "0.0.0.0"' "$CONFIG_PATH" || echo "=> ERROR: Could not configure appservice hostname"
            yq -i -y '.appservice.port = 29318' "$CONFIG_PATH" || echo "=> ERROR: Could not configure appservice port"
            yq -i -y '.appservice.bot_username = "whatsappbot"' "$CONFIG_PATH" || echo "=> ERROR: Could not configure appservice bot_username"
            
            # Configure permissions for base domain users
            yq -i -y '.bridge.permissions."'"$BASE_DOMAIN"'" = "user"' "$CONFIG_PATH" || echo "=> ERROR: Could not configure permissions"
@@ -105,6 +106,7 @@ if [ ! -f "$CONFIG_PATH" ]; then
            # Fix user regex patterns to use base domain instead of matrix subdomain
            yq -i -y '.namespaces.users[0].regex = "^@whatsappbot:'"$BASE_DOMAIN"'$"' "$REGISTRATION_PATH" || echo "=> ERROR: Could not fix whatsappbot regex"
            yq -i -y '.namespaces.users[1].regex = "^@whatsapp_.*:'"$BASE_DOMAIN"'$"' "$REGISTRATION_PATH" || echo "=> ERROR: Could not fix whatsapp_.* regex"
            yq -i -y '.sender_localpart = "whatsappbot"' "$REGISTRATION_PATH" || echo "=> ERROR: Could not fix sender_localpart"
        fi
        
        chown cloudron:cloudron "$CONFIG_PATH" "$REGISTRATION_PATH" 2>/dev/null || true
@@ -154,6 +156,7 @@ else
                yq -i -y '.appservice.public_address = "https://'"$CLOUDRON_APP_DOMAIN"'"' "$CONFIG_PATH" || echo "=> ERROR: Could not update appservice public_address"
                yq -i -y '.appservice.hostname = "0.0.0.0"' "$CONFIG_PATH" || echo "=> ERROR: Could not update appservice hostname"
                yq -i -y '.appservice.port = 29318' "$CONFIG_PATH" || echo "=> ERROR: Could not update appservice port"
                yq -i -y '.appservice.bot_username = "whatsappbot"' "$CONFIG_PATH" || echo "=> ERROR: Could not update appservice bot_username"
                
                # Configure permissions for base domain users
                yq -i -y '.bridge.permissions."'"$BASE_DOMAIN"'" = "user"' "$CONFIG_PATH" || echo "=> ERROR: Could not update permissions"
@@ -226,6 +229,7 @@ else
            # Fix user regex patterns to use base domain instead of matrix subdomain
            yq -i -y '.namespaces.users[0].regex = "^@whatsappbot:'"$BASE_DOMAIN"'$"' "$REGISTRATION_PATH" || echo "=> ERROR: Could not fix whatsappbot regex"
            yq -i -y '.namespaces.users[1].regex = "^@whatsapp_.*:'"$BASE_DOMAIN"'$"' "$REGISTRATION_PATH" || echo "=> ERROR: Could not fix whatsapp_.* regex"
            yq -i -y '.sender_localpart = "whatsappbot"' "$REGISTRATION_PATH" || echo "=> ERROR: Could not fix sender_localpart"
        fi
        
        # Let the bridge handle token generation automatically - remove any placeholder tokens