-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest_functionality.html
More file actions
269 lines (246 loc) Β· 10 KB
/
Copy pathtest_functionality.html
File metadata and controls
269 lines (246 loc) Β· 10 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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Bot Control System Test</title>
<style>
body {
font-family: Arial, sans-serif;
max-width: 1200px;
margin: 0 auto;
padding: 20px;
background-color: #f5f5f5;
}
.container {
display: flex;
gap: 20px;
}
.panel {
flex: 1;
background: white;
padding: 20px;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.button {
background-color: #007bff;
color: white;
border: none;
padding: 10px 20px;
border-radius: 4px;
cursor: pointer;
margin: 5px;
}
.button:hover {
background-color: #0056b3;
}
.status {
padding: 10px;
margin: 10px 0;
border-radius: 4px;
font-weight: bold;
}
.status.enabled {
background-color: #d4edda;
color: #155724;
border: 1px solid #c3e6cb;
}
.status.disabled {
background-color: #f8d7da;
color: #721c24;
border: 1px solid #f5c6cb;
}
.log {
background-color: #f8f9fa;
border: 1px solid #dee2e6;
padding: 10px;
margin: 10px 0;
border-radius: 4px;
height: 200px;
overflow-y: auto;
font-family: monospace;
font-size: 12px;
}
h2 {
color: #333;
border-bottom: 2px solid #007bff;
padding-bottom: 10px;
}
.agent-requested {
animation: pulse 2s infinite;
border: 3px solid #ff6b6b !important;
background-color: #fff5f5 !important;
}
@keyframes pulse {
0% { border-color: #ff6b6b; }
50% { border-color: #ff0000; }
100% { border-color: #ff6b6b; }
}
</style>
</head>
<body>
<h1>π€ Bot Control System Test Dashboard</h1>
<div class="container">
<!-- Customer Chat Simulation -->
<div class="panel">
<h2>π± Customer Chat Simulation</h2>
<div id="botStatus" class="status enabled">π’ Bot Enabled</div>
<button class="button" onclick="callAgent()">π Call Agent (Disable Bot)</button>
<button class="button" onclick="sendCustomerMessage()">π¬ Send Customer Message</button>
<h3>Chat Messages:</h3>
<div id="chatMessages" class="log"></div>
</div>
<!-- Admin Panel Simulation -->
<div class="panel">
<h2>π¨βπΌ Admin Panel Simulation</h2>
<div id="adminStatus" class="status enabled">π’ Bot Active</div>
<button class="button" onclick="useAIRecommendation()">π€ Use AI Recommendation (Re-enable Bot)</button>
<button class="button" onclick="sendAgentMessage()">π Send Agent Message</button>
<h3>Active Chats:</h3>
<div id="activeChatCard" class="panel" style="margin: 10px 0; border: 2px solid #dee2e6;">
<div id="chatCardContent">
<strong>Customer: customer_test_123</strong><br>
<span id="cardStatus">Status: active</span><br>
<small id="cardTimestamp">Last activity: Just now</small>
</div>
</div>
</div>
</div>
<!-- System Logs -->
<div class="panel" style="margin-top: 20px;">
<h2>π System Activity Log</h2>
<div id="systemLog" class="log"></div>
<button class="button" onclick="clearLog()">ποΈ Clear Log</button>
</div>
<script>
const customerId = 'customer_test_123';
let botEnabled = true;
let agentRequested = false;
function log(message) {
const timestamp = new Date().toLocaleTimeString();
const logDiv = document.getElementById('systemLog');
logDiv.innerHTML += `[${timestamp}] ${message}<br>`;
logDiv.scrollTop = logDiv.scrollHeight;
}
function updateBotStatus(enabled) {
botEnabled = enabled;
const statusDiv = document.getElementById('botStatus');
const adminStatusDiv = document.getElementById('adminStatus');
if (enabled) {
statusDiv.className = 'status enabled';
statusDiv.innerHTML = 'π’ Bot Enabled';
adminStatusDiv.className = 'status enabled';
adminStatusDiv.innerHTML = 'π’ Bot Active';
log('β
Bot has been ENABLED');
} else {
statusDiv.className = 'status disabled';
statusDiv.innerHTML = 'π΄ Bot Disabled (Agent Mode)';
adminStatusDiv.className = 'status disabled';
adminStatusDiv.innerHTML = 'π΄ Bot Disabled (Agent Handling)';
log('β Bot has been DISABLED - Agent requested');
}
}
function updateChatCard(agentRequestedStatus) {
const cardDiv = document.getElementById('activeChatCard');
const statusSpan = document.getElementById('cardStatus');
if (agentRequestedStatus) {
cardDiv.className = 'panel agent-requested';
statusSpan.innerHTML = 'π¨ Status: AGENT REQUESTED';
log('π¨ Chat card is now HIGHLIGHTED - Agent needed!');
} else {
cardDiv.className = 'panel';
statusSpan.innerHTML = 'Status: active';
log('π¬ Chat card returned to normal status');
}
}
async function callAgent() {
try {
log('π Customer clicked "Call Agent" button');
// Simulate the API call to disable bot
const response = await fetch(`http://localhost:8000/chat/status/${customerId}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
status: 'agent_requested',
bot_enabled: false
})
});
if (response.ok) {
updateBotStatus(false);
agentRequested = true;
updateChatCard(true);
// Add message to chat
addChatMessage('system', 'π¨ Agent has been requested. Bot responses are now disabled.');
log('β
Agent request successful - Bot disabled, admin notified');
} else {
log('β Failed to request agent');
}
} catch (error) {
log(`β Error requesting agent: ${error.message}`);
}
}
async function useAIRecommendation() {
try {
log('π€ Admin clicked "Use AI Recommendation" button');
// Simulate using an AI recommendation which re-enables bot
const response = await fetch(`http://localhost:8000/chat/status/${customerId}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
status: 'active',
bot_enabled: true
})
});
if (response.ok) {
updateBotStatus(true);
agentRequested = false;
updateChatCard(false);
log('β
AI recommendation used - Bot re-enabled automatically');
} else {
log('β Failed to use AI recommendation');
}
} catch (error) {
log(`β Error using AI recommendation: ${error.message}`);
}
}
function addChatMessage(sender, message) {
const chatDiv = document.getElementById('chatMessages');
const timestamp = new Date().toLocaleTimeString();
const senderIcon = sender === 'customer' ? 'π€' : sender === 'bot' ? 'π€' : 'β οΈ';
chatDiv.innerHTML += `[${timestamp}] ${senderIcon} ${sender}: ${message}<br>`;
chatDiv.scrollTop = chatDiv.scrollHeight;
}
async function sendCustomerMessage() {
const message = prompt('Enter customer message:') || 'Hello, I need help with my account';
addChatMessage('customer', message);
log(`π¨ Customer sent message: "${message}"`);
// Only respond with bot if bot is enabled
if (botEnabled && !agentRequested) {
setTimeout(() => {
addChatMessage('bot', 'π€ Thank you for your message. How can I assist you today?');
log('π€ Bot responded automatically');
}, 1000);
} else {
log('π« Bot did not respond (disabled due to agent request)');
}
}
function sendAgentMessage() {
const message = prompt('Enter agent message:') || 'Hello! I\'m here to help you personally.';
addChatMessage('agent', `π¨βπΌ ${message}`);
log(`π¨βπΌ Agent sent message: "${message}"`);
}
function clearLog() {
document.getElementById('systemLog').innerHTML = '';
document.getElementById('chatMessages').innerHTML = '';
}
// Initialize
log('π Bot Control System Test Dashboard initialized');
log('π Test the workflow: 1) Send customer message (bot responds), 2) Call agent (bot stops), 3) Use AI recommendation (bot re-enables)');
</script>
</body>
</html>