91 lines
3.4 KiB
PHP
91 lines
3.4 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 NetworkHospitalConversation extends Conversation
|
|
{
|
|
|
|
|
|
public function run()
|
|
{
|
|
$this->bot->types(); // Typing indicator for the first message
|
|
sleep(0.5); // Delay
|
|
$this->showHospitalMenu();
|
|
}
|
|
|
|
protected function showHospitalMenu()
|
|
{
|
|
$chat_session_info = get_chatbot_session_info();
|
|
$policy_list = ChatbotHelper::getListOfPolicies($chat_session_info);
|
|
$buttons = [];
|
|
$question = 'Choose Policy:';
|
|
if(is_array($policy_list) && count($policy_list))
|
|
{
|
|
foreach($policy_list as $policy)
|
|
{
|
|
// $question = Question::create("Choose Policy to Download Ecard:")
|
|
// ->addButtons([
|
|
// Button::create("🔹 $policy['policy_name']")->value("$policy['emp_policy_id']"),
|
|
// Button::create("◀️ Go Back")->value("go_back"),
|
|
// ]);
|
|
$buttons[] = Button::create("🔹 {$policy['policy_name']}")->value($policy['emp_policy_id'].'#'.$policy['rand_string']);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
$question = 'No policy found';
|
|
}
|
|
$buttons = array_merge($buttons,[Button::create("◀️ Go Back")->value("go_back")]);
|
|
$question = Question::create($question)
|
|
->addButtons($buttons);
|
|
|
|
// $this->bot->hears('.*', function ($bot) {
|
|
// $this->bot->types(); // Typing indicator for the first message
|
|
// sleep(0.5); // Delay
|
|
// });
|
|
|
|
$this->bot->ask($question, function ($answer) {
|
|
$path = $this->bot->userStorage()->get('path');
|
|
array_push($path,
|
|
$answer->getValue()
|
|
);
|
|
$this->bot->userStorage()->save([
|
|
'path' => $path
|
|
]);
|
|
switch ($answer->getValue()) {
|
|
case is_string($answer->getValue()) && is_array(explode('#',$answer->getValue())) && count((explode('#',$answer->getValue()))) == 2:
|
|
|
|
$client_poilicy_id = explode('#',$answer->getValue())[1];
|
|
$hospital_link = ChatbotHelper::getHospitalLink($client_poilicy_id);
|
|
|
|
if($hospital_link)
|
|
{
|
|
$this->say('<a href="' . $hospital_link['network_hospitals'] . '" target="_blank">Click here for hospital details</a>');
|
|
}
|
|
else
|
|
{
|
|
$this->say('No Data found, please contact support team');
|
|
}
|
|
|
|
$this->bot->startConversation(new doYouWantToContinueConversation());
|
|
break;
|
|
case "go_back":
|
|
$this->bot->startConversation(new MainMenuConversation());
|
|
break;
|
|
default:
|
|
$this->say("Invalid selection. Please choose an option.");
|
|
$this->bot->startConversation(new NetworkHospitalConversation());
|
|
break;
|
|
}
|
|
});
|
|
}
|
|
|
|
}
|