124-webapp/setup_matrix.py
2025-11-10 15:24:10 +01:00

62 lines
1.8 KiB
Python
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
"""
Setup script for Matrix: register user and create room
"""
import asyncio
import os
from nio import AsyncClient, RegisterResponse, RoomCreateResponse
async def setup_matrix():
homeserver = "http://124.local:8008"
username = "einszwovier"
password = "einszwo4"
client = AsyncClient(homeserver)
print("🔧 Setting up Matrix server...")
print(f" Homeserver: {homeserver}")
print(f" Username: {username}")
# Register the user
print("\n📝 Registering user...")
response = await client.register(
username=username,
password=password
)
if isinstance(response, RegisterResponse):
print(f" ✅ User registered: {response.user_id}")
user_id = response.user_id
else:
print(f" User might already exist, trying to login...")
# Try to login instead
response = await client.login(password)
if response.user_id:
print(f" ✅ Logged in as: {response.user_id}")
user_id = response.user_id
else:
print(f" ❌ Failed: {response}")
await client.close()
return
# Create a room
print("\n🏠 Creating print orders room...")
response = await client.room_create(
name="Print Orders",
topic="PDF print order submissions from the web app",
is_public=False
)
if isinstance(response, RoomCreateResponse):
print(f" ✅ Room created!")
print(f" Room ID: {response.room_id}")
print(f"\n✅ Setup complete!")
print(f"\n📋 Add this to your .env file:")
print(f"MATRIX_ROOM={response.room_id}")
else:
print(f" ❌ Failed to create room: {response}")
await client.close()
if __name__ == "__main__":
asyncio.run(setup_matrix())