up
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
require_once '../config/config.php';
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
requireAuthentication();
|
||||
|
||||
try {
|
||||
$input = json_decode(file_get_contents('php://input'), true) ?: $_POST;
|
||||
$userId = isset($input['user_id']) ? intval($input['user_id']) : 0;
|
||||
if (!$userId) {
|
||||
http_response_code(400);
|
||||
echo json_encode(['success' => false, 'error' => 'user_id required']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$db = Database::getInstance();
|
||||
$user = $db->fetch('SELECT phone_number FROM users WHERE id = :id', ['id' => $userId]);
|
||||
if (!$user) {
|
||||
http_response_code(404);
|
||||
echo json_encode(['success' => false, 'error' => 'User not found']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$operator = $_SESSION['admin_user'] ?? null;
|
||||
$operatorId = $operator['id'] ?? null;
|
||||
|
||||
try {
|
||||
require_once __DIR__ . '/../services/BotService.php';
|
||||
$bot = new BotService();
|
||||
$bot->attendConversation($user['phone_number'], $operatorId);
|
||||
echo json_encode(['success' => true]);
|
||||
} catch (Exception $e) {
|
||||
// Fallback: apply updates directly and log activity
|
||||
$now = date('Y-m-d H:i:s');
|
||||
$db->update('users', ['in_service' => 1, 'in_service_by' => $operatorId, 'in_service_at' => $now, 'advisor_requested' => 0], 'id = :id', ['id' => $userId]);
|
||||
$db->insert('operator_activity', ['user_id' => $userId, 'operator_id' => $operatorId, 'action' => 'attend', 'details' => 'Marked in_service via fallback', 'created_at' => $now]);
|
||||
echo json_encode(['success' => true, 'warning' => 'BotService failed, fallback applied']);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
http_response_code(500);
|
||||
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
|
||||
}
|
||||
@@ -23,6 +23,10 @@ try {
|
||||
u.avatar_url,
|
||||
u.bot_enabled,
|
||||
u.on_hold,
|
||||
u.advisor_requested,
|
||||
u.in_service,
|
||||
u.in_service_by,
|
||||
u.in_service_at,
|
||||
lm.message_id AS last_message_id,
|
||||
lm.content AS last_message,
|
||||
lm.direction AS direction,
|
||||
@@ -60,7 +64,11 @@ try {
|
||||
'message_type' => $conv['message_type'] ?? 'text',
|
||||
'unread_count' => intval($conv['unread_count'] ?? 0),
|
||||
'bot_enabled' => isset($conv['bot_enabled']) ? (bool)$conv['bot_enabled'] : true,
|
||||
'on_hold' => isset($conv['on_hold']) ? (bool)$conv['on_hold'] : false
|
||||
'on_hold' => isset($conv['on_hold']) ? (bool)$conv['on_hold'] : false,
|
||||
'advisor_requested' => isset($conv['advisor_requested']) ? (bool)$conv['advisor_requested'] : false,
|
||||
'in_service' => isset($conv['in_service']) ? (bool)$conv['in_service'] : false,
|
||||
'in_service_by' => isset($conv['in_service_by']) ? intval($conv['in_service_by']) : null,
|
||||
'in_service_at' => $conv['in_service_at'] ?? null
|
||||
];
|
||||
}, $conversations);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user