-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic_usage.py
More file actions
70 lines (57 loc) · 2.56 KB
/
Copy pathbasic_usage.py
File metadata and controls
70 lines (57 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python3
"""
Basic usage example for Entangle Matrix SDK.
"""
import asyncio
from entangle_matrix import EntangleMatrixClient, EntangleMatrixError
async def main():
"""Basic usage example."""
# Initialize client
async with EntangleMatrixClient(
base_url="http://localhost:8000",
api_key="your-api-key-here" # Optional if API doesn't require auth
) as client:
try:
# Check API health
print("🏥 Checking API health...")
health = await client.health_check()
print(f"✅ API Status: {health}")
# Send a simple text message
room_id = "!VJPkTyryZOraVzVUie:matrix.org" # Replace with your room ID
print(f"📤 Sending message to room {room_id}...")
message = await client.send_message(
room_id=room_id,
message="Hello from Entangle Matrix SDK! 🚀"
)
print(f"✅ Message sent! Event ID: {message.event_id}")
# Send an HTML formatted message
print("📤 Sending formatted message...")
formatted_message = await client.send_message(
room_id=room_id,
message="This is a formatted message",
formatted_body="<strong>This is a formatted message</strong> with <em>HTML</em>!",
format_type="org.matrix.custom.html"
)
print(f"✅ Formatted message sent! Event ID: {formatted_message.event_id}")
# List all rooms
print("📋 Getting room list...")
rooms = await client.list_rooms()
print(f"✅ Found {len(rooms)} rooms:")
for room in rooms:
print(f" - {room.name or 'Unnamed Room'} ({room.room_id}) - {room.member_count} members")
# Get detailed room info
if rooms:
print(f"🔍 Getting detailed info for room: {rooms[0].room_id}")
room_info = await client.get_room_info(rooms[0].room_id)
print(f"✅ Room Info:")
print(f" - Name: {room_info.name}")
print(f" - Topic: {room_info.topic}")
print(f" - Members: {room_info.member_count}")
print(f" - Encrypted: {room_info.is_encrypted}")
print(f" - Direct: {room_info.is_direct}")
except EntangleMatrixError as e:
print(f"❌ Matrix API Error: {e.message}")
except Exception as e:
print(f"❌ Unexpected error: {str(e)}")
if __name__ == "__main__":
asyncio.run(main())