-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-voice-api.js
More file actions
110 lines (97 loc) · 3.26 KB
/
test-voice-api.js
File metadata and controls
110 lines (97 loc) · 3.26 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
const axios = require('axios');
const BASE_URL = 'http://localhost:3000';
// Test conversation endpoint with voice-like queries
const voiceTestCases = [
{
query: "check my account balance",
description: "Voice command for balance inquiry"
},
{
query: "I want to recharge my phone",
description: "Voice command for recharge"
},
{
query: "show me my last transaction",
description: "Voice command for transaction history"
},
{
query: "tell me about my loan",
description: "Voice command for loan information"
},
{
query: "I need to talk to an agent",
description: "Voice command for agent support"
},
{
query: "I want to update my details",
description: "Voice command for updating details"
},
{
query: "cancel everything",
description: "Voice command for cancellation"
},
{
query: "what's the weather like today",
description: "Unknown voice command (should be handled gracefully)"
}
];
async function testVoiceConversationAPI() {
console.log('🎤 === TESTING VOICE CONVERSATION API ===\n');
for (const testCase of voiceTestCases) {
try {
console.log(`🗣️ Testing: "${testCase.query}"`);
console.log(`📝 Description: ${testCase.description}`);
const response = await axios.post(`${BASE_URL}/conversation/process`, {
sessionId: `voice-test-${Date.now()}`,
query: testCase.query
});
console.log(`✅ Intent: ${response.data.intent}`);
console.log(`🎯 Confidence: ${response.data.confidence}`);
console.log(`📋 Response: ${response.data.response}`);
console.log('─'.repeat(60));
} catch (error) {
console.log(`❌ Error testing "${testCase.query}":`);
if (error.response) {
console.log(` Status: ${error.response.status}`);
console.log(` Error: ${error.response.data.error || error.response.data}`);
} else {
console.log(` Network Error: ${error.message}`);
}
console.log('─'.repeat(60));
}
}
}
// Check if server is running first
async function checkServer() {
try {
await axios.get(`${BASE_URL}/`);
return true;
} catch (error) {
return false;
}
}
async function runTests() {
const serverRunning = await checkServer();
if (!serverRunning) {
console.log('❌ Server is not running at http://localhost:3000');
console.log('Please start the server first: node index.js');
return;
}
console.log('✅ Server is running at http://localhost:3000\n');
await testVoiceConversationAPI();
console.log('\n🎯 === VOICE FRONTEND INSTRUCTIONS ===');
console.log('1. Open http://localhost:3000 in Chrome or Edge');
console.log('2. Click the green 🎤 Voice Command button');
console.log('3. Speak one of the test phrases above');
console.log('4. Wait 4 seconds for processing');
console.log('5. See the result displayed on screen');
console.log('\n📱 Voice commands work best with:');
console.log('- "Check my balance"');
console.log('- "Recharge my account"');
console.log('- "Show last transaction"');
console.log('- "Tell me about loan"');
console.log('- "I need an agent"');
console.log('- "Update my details"');
console.log('- "Cancel everything"');
}
runTests().catch(console.error);