forked from GenSkytech1/GenLabV2.0
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug_messages.php
More file actions
84 lines (66 loc) · 2.25 KB
/
debug_messages.php
File metadata and controls
84 lines (66 loc) · 2.25 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
<?php
// Debug script for message endpoints
$baseUrl = 'http://127.0.0.1:8000/api';
function makeApiCall($url, $method = 'GET', $data = null, $headers = []) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
if ($data) {
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
}
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return [
'status' => $httpCode,
'data' => json_decode($response, true),
'raw' => $response
];
}
echo "=== DEBUGGING MESSAGE ENDPOINTS ===\n";
// 1. Login as user
$loginData = [
'user_code' => 'test123',
'password' => 'password123'
];
$loginResult = makeApiCall("$baseUrl/user/login", 'POST', $loginData, [
'Content-Type: application/json'
]);
if ($loginResult['status'] != 200) {
echo "❌ Login failed: " . $loginResult['raw'] . "\n";
exit;
}
$token = $loginResult['data']['access_token'];
$headers = [
'Content-Type: application/json',
'Authorization: Bearer ' . $token
];
echo "✅ Login successful\n";
// 2. Get existing groups
echo "\n=== GETTING GROUPS ===\n";
$groupsResult = makeApiCall("$baseUrl/chat/groups", 'GET', null, $headers);
if ($groupsResult['status'] != 200 || empty($groupsResult['data']['data'])) {
echo "❌ No groups available\n";
exit;
}
$groupId = $groupsResult['data']['data'][0]['id'];
echo "Using group ID: $groupId\n";
// 3. Test getting messages
echo "\n=== TESTING GET MESSAGES ===\n";
$messagesUrl = "$baseUrl/chat/messages?group_id=$groupId";
echo "URL: $messagesUrl\n";
$messagesResult = makeApiCall($messagesUrl, 'GET', null, $headers);
echo "Status: " . $messagesResult['status'] . "\n";
echo "Response: " . $messagesResult['raw'] . "\n";
// 4. Test sending message
echo "\n=== TESTING SEND MESSAGE ===\n";
$messageData = [
'group_id' => $groupId,
'type' => 'text',
'content' => 'Debug test message'
];
$sendResult = makeApiCall("$baseUrl/chat/messages", 'POST', $messageData, $headers);
echo "Status: " . $sendResult['status'] . "\n";
echo "Response: " . $sendResult['raw'] . "\n";