78 lines
2.6 KiB
PHP
78 lines
2.6 KiB
PHP
<?php
|
|
|
|
// namespace App\Conversations;
|
|
namespace App\Controllers\Chatbot;
|
|
|
|
use BotMan\BotMan\Messages\Conversations\Conversation;
|
|
use BotMan\BotMan\Messages\Outgoing\Question;
|
|
use BotMan\BotMan\Messages\Outgoing\Actions\Button;
|
|
|
|
use App\Helpers\ChatbotHelper;
|
|
|
|
class commonPolicyOptionConversations extends Conversation
|
|
{
|
|
protected $buttonsData = [
|
|
"upload_vehicle_details" => ["response_text" => "🔹 Upload Vehicle Details"],
|
|
"service_executive" => ["response_text" => "🔹 Talk to our Service Executive"],
|
|
"go_back" => ["response_text" => "◀️ Go Back"],
|
|
];
|
|
|
|
public function run()
|
|
{
|
|
$this->policyOptions();
|
|
}
|
|
|
|
protected function policyOptions()
|
|
{
|
|
$buttons = [];
|
|
foreach ($this->buttonsData as $key => $data) {
|
|
$buttons[] = Button::create($data['response_text'])->value($key);
|
|
}
|
|
// $this->bot->userStorage()->save([
|
|
// 'path' => []
|
|
// ]);
|
|
$question = Question::create("Please choose an option:")->addButtons($buttons);
|
|
$temp = $this->buttonsData;
|
|
$this->bot->ask($question, function ($answer) use( $temp ){
|
|
$user_reponse = $answer->getValue();
|
|
if (isset($temp[$user_reponse])) {
|
|
$message = "You've chosen " . $temp[$user_reponse]['response_text'];
|
|
// $this->bot->say($message,,WebDriver::class);
|
|
$this->bot->reply($message);
|
|
}
|
|
|
|
if (!$answer->isInteractiveMessageReply()) {
|
|
$user_reponse = null;
|
|
}
|
|
$path = $this->bot->userStorage()->get('path');
|
|
array_push($path,
|
|
$answer->getValue()
|
|
);
|
|
$this->bot->userStorage()->save([
|
|
'path' => $path
|
|
]);
|
|
$path = $this->bot->userStorage()->get('path');
|
|
// $this->say(json_encode($path));
|
|
switch ($user_reponse) {
|
|
case "upload_vehicle_details":
|
|
// $cityName = $response->getText();
|
|
$this->bot->startConversation(new vehicleFormConversation());
|
|
break;
|
|
case "service_executive":
|
|
$this->bot->startConversation(new serviceExecutiveConversation());
|
|
break;
|
|
case "go_back":
|
|
$this->bot->startConversation(new MainMenuConversation());
|
|
break;
|
|
default:
|
|
$this->say("Invalid selection. Please choose an option.");
|
|
$this->policyOptions();
|
|
break;
|
|
}
|
|
});
|
|
}
|
|
|
|
}
|
|
|
|
|