curl --request POST \
--url https://api.example.com/api/simulate-flow.php \
--header 'Content-Type: application/json' \
--data '
{
"message": "<string>",
"reset": true
}
'{
"success": true,
"type": "<string>",
"response": "<string>",
"reset": true
}Test conversation flows in a simulated environment
curl --request POST \
--url https://api.example.com/api/simulate-flow.php \
--header 'Content-Type: application/json' \
--data '
{
"message": "<string>",
"reset": true
}
'{
"success": true,
"type": "<string>",
"response": "<string>",
"reset": true
}true to clear the simulation session and start overcurl -X POST https://your-domain.com/api/simulate-flow.php \
-H "Content-Type: application/json" \
-d '{
"message": "Hello"
}'
"message" - Bot sent a text message"menu" - Bot presented a menu with options"question" - Bot asked a question"end" - Conversation ended"error" - Invalid input or flow errortrue){
"message": "Hi"
}
{
"reset": true
}
{
"success": true,
"reset": true
}
{
"message": ""
}
{
"success": false,
"error": "Campo \"message\" requerido"
}
| Status Code | Description |
|---|---|
| 200 | Simulation processed successfully |
| 400 | Missing or invalid message field |
| 405 | Method not allowed (only POST accepted) |
| 500 | Internal server error |
SIM_{md5_of_session_id}
classic_flow_sessions table:
message field (unless resetting)ClassicBotService->processMessage() for normal messagesapi/simulate-flow.php:11-46
class FlowSimulator {
async send(message) {
const response = await fetch('/api/simulate-flow.php', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ message })
});
return response.json();
}
async reset() {
await fetch('/api/simulate-flow.php', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ reset: true })
});
}
}
// Usage
const sim = new FlowSimulator();
const response1 = await sim.send('Hello');
console.log(response1.response);
await sim.reset();
const response2 = await sim.send('Hello'); // Starts over
async function testFlow(steps) {
const sim = new FlowSimulator();
await sim.reset();
const results = [];
for (const step of steps) {
const response = await sim.send(step.input);
results.push({
input: step.input,
expected: step.expected,
actual: response.response,
passed: response.response.includes(step.expected)
});
}
return results;
}
// Test case
const testResults = await testFlow([
{ input: 'Hi', expected: 'Bienvenido' },
{ input: 'continue', expected: 'elige una opción' },
{ input: '1', expected: 'nombre completo' }
]);