Feature: Implement multi-stage Conversation Flow Engine with TestFlow
This commit is contained in:
38
backend/app/Core/Flows/TestFlow.php
Normal file
38
backend/app/Core/Flows/TestFlow.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Core\Flows;
|
||||
|
||||
/**
|
||||
* TestFlow
|
||||
* A basic interactive flow for testing the multi-stage system.
|
||||
*/
|
||||
class TestFlow extends BaseFlow
|
||||
{
|
||||
public function handleStep(string $step, array $messageData, array &$context): FlowResult
|
||||
{
|
||||
$text = isset($messageData['body']) ? trim($messageData['body']) : '';
|
||||
|
||||
switch ($step) {
|
||||
case 'start':
|
||||
// Initiate step
|
||||
return new FlowResult("أهلاً بك في اختبار المسار التفاعلي! ما هو اسمك الكريم؟", "ask_name");
|
||||
|
||||
case 'ask_name':
|
||||
if (empty($text)) {
|
||||
return new FlowResult("يرجى إدخال اسمك للاستمرار:", "ask_name");
|
||||
}
|
||||
$context['name'] = $text;
|
||||
return new FlowResult("تشرفنا بك يا {$text}! من فضلك قم بتقييم خدمتنا من 1 إلى 5:", "ask_feedback");
|
||||
|
||||
case 'ask_feedback':
|
||||
if (!preg_match('/^[1-5]$/', $text)) {
|
||||
return new FlowResult("الرجاء إدخال رقم من 1 إلى 5 فقط للتقييم:", "ask_feedback");
|
||||
}
|
||||
$context['rating'] = (int)$text;
|
||||
return new FlowResult("شكراً لك يا {$context['name']}! لقد تم تسجيل تقييمك ({$text}/5) بنجاح. يومك سعيد!", "finished", true);
|
||||
|
||||
default:
|
||||
return new FlowResult("خطأ في تحديد خطوة المسار.", "finished", true);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user