-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdiagnose.sh
More file actions
155 lines (139 loc) · 4.23 KB
/
diagnose.sh
File metadata and controls
155 lines (139 loc) · 4.23 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/bin/bash
# Bot Diagnostics Script
# Usage: ./diagnose.sh https://your-worker.workers.dev
if [ -z "$1" ]; then
echo "Usage: ./diagnose.sh <worker-url>"
echo "Example: ./diagnose.sh https://matrix-chatgpt-bot.facilis-velox.workers.dev"
exit 1
fi
BOT_URL="$1"
echo "=========================================="
echo " Matrix Bot Diagnostics"
echo "=========================================="
echo ""
echo "Bot URL: $BOT_URL"
echo ""
# Test 1: Health check
echo "1️⃣ Testing health endpoint..."
HEALTH=$(curl -s "$BOT_URL/health" 2>&1)
if echo "$HEALTH" | grep -q "ok"; then
echo "✅ Health check passed"
echo "$HEALTH" | head -5
else
echo "❌ Health check failed"
echo "$HEALTH"
fi
echo ""
# Test 2: Check if logged in
echo "2️⃣ Checking authentication status..."
STATUS=$(curl -s "$BOT_URL/status" 2>&1)
if echo "$STATUS" | grep -q "error"; then
echo "⚠️ Not authenticated or error occurred"
echo "$STATUS"
echo ""
echo "Attempting to login..."
LOGIN=$(curl -s -X POST "$BOT_URL/login" 2>&1)
echo "$LOGIN"
if echo "$LOGIN" | grep -q "error"; then
echo ""
echo "❌ Login failed!"
echo "Please check:"
echo " - MATRIX_USER_ID is set correctly (e.g., @botuser:matrix.org)"
echo " - MATRIX_PASSWORD is correct"
echo " - MATRIX_HOMESERVER matches your user ID domain"
echo ""
echo "Check secrets with: wrangler secret list"
exit 1
else
echo "✅ Login successful"
sleep 2
fi
else
echo "✅ Bot is authenticated"
fi
echo ""
# Test 3: Check sync status
echo "3️⃣ Checking sync status..."
STATUS=$(curl -s "$BOT_URL/status" 2>&1)
echo "$STATUS"
if echo "$STATUS" | grep -q '"running":true'; then
echo "✅ Sync is running"
elif echo "$STATUS" | grep -q '"running":false'; then
echo "⚠️ Sync is not running"
echo ""
echo "Starting sync..."
START=$(curl -s "$BOT_URL/start" 2>&1)
echo "$START"
if echo "$START" | grep -q "started"; then
echo "✅ Sync started successfully"
else
echo "❌ Failed to start sync"
exit 1
fi
else
echo "⚠️ Cannot determine sync status"
fi
echo ""
# Test 4: Check for errors
echo "4️⃣ Checking for errors..."
if echo "$STATUS" | grep -q "error"; then
echo "❌ Errors detected:"
echo "$STATUS" | grep "error"
else
echo "✅ No errors detected"
fi
echo ""
# Test 5: Configuration summary
echo "=========================================="
echo " Configuration Checklist"
echo "=========================================="
echo ""
echo "Make sure you have completed these steps:"
echo ""
echo "✓ Secrets configured (run: wrangler secret list)"
echo " - MATRIX_USER_ID"
echo " - MATRIX_PASSWORD"
echo " - OPENAI_API_KEY"
echo " - OPENAI_BASE_URL (optional)"
echo ""
echo "✓ Bot invited to Matrix room"
echo " - Invite bot: /invite @yourbotuser:matrix.org"
echo " - Bot should accept invite automatically"
echo ""
echo "✓ Message format to trigger bot:"
echo " - Direct: @yourbotuser:matrix.org hello"
echo " - Or in invited room: just type your message"
echo ""
# Test 6: Final status check
echo "=========================================="
echo " Final Status Check"
echo "=========================================="
echo ""
FINAL_STATUS=$(curl -s "$BOT_URL/status" 2>&1)
if echo "$FINAL_STATUS" | grep -q '"running":true'; then
echo "✅ Bot is running and ready!"
echo ""
echo "Next steps:"
echo "1. Go to your Matrix client"
echo "2. Invite bot: /invite @yourbotuser:matrix.org"
echo "3. Send a message: @yourbotuser:matrix.org hello"
echo ""
echo "If bot still doesn't respond:"
echo "- Check Cloudflare Workers logs in dashboard"
echo "- Verify bot accepted room invite"
echo "- Make sure cron trigger is enabled (runs every 2 minutes)"
else
echo "⚠️ Bot may not be fully operational"
echo ""
echo "Current status:"
echo "$FINAL_STATUS"
echo ""
echo "Try these commands manually:"
echo " curl -X POST $BOT_URL/login"
echo " curl $BOT_URL/start"
echo " curl $BOT_URL/status"
fi
echo ""
echo "=========================================="
echo "Diagnostics Complete"
echo "=========================================="