laravelEcomm/app/Http/Controllers/BotManController.php
2024-07-10 13:46:42 +05:45

58 lines
2.1 KiB
PHP

<?php
namespace App\Http\Controllers;
use BotMan\BotMan\BotMan;
use BotMan\BotMan\Messages\Incoming\Answer;
use Illuminate\Http\Request;
class BotManController extends Controller
{
public function handle()
{
$botman = app('botman');
$botman->hears('{message}', function ($botman, $message) {
if ($message == 'hi' || $message == 'Hi' || $message == 'Hello' || $message == 'hello') {
$this->askName($botman);
} else {
$botman->reply("Start the conversation saying Hi.");
}
});
$botman->listen();
}
public function askName($botman)
{
$botman->ask('Hello! What is your name?', function (Answer $answer, $conversation) {
$name = $answer->getText();
$this->say("Nice to meet you " . $name);
$conversation->ask('Can you tell us your phone number?', function (Answer $answer, $conversation) {
$phoneNumber = $answer->getText();
$this->say("Your phone number is " . $phoneNumber);
$conversation->ask('Can you tell us your email?', function (Answer $answer, $conversation) {
$email = $answer->getText();
$this->say("Your email is " . $email);
$conversation->ask('Confirm your Email (Y/N):', function (Answer $answer, $conversation) {
$confirmEmail = $answer->getText();
if ($answer == 'Y' || $answer == "y") {
$this->say("we got your details");
} elseif ($answer == 'N' || $answer == "n") {
$this->say("Please confirm your email");
$conversation->ask('Write your email again.', function (Answer $answer, $conversation) {
$email = $answer->getText();
$this->say("Your email is " . $email);
});
}
});
});
});
});
}
}