ChatBot Integration
This commit is contained in:
57
app/Http/Controllers/BotManController.php
Normal file
57
app/Http/Controllers/BotManController.php
Normal file
@ -0,0 +1,57 @@
|
||||
<?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);
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Mail\Testing;
|
||||
use App\Models\User;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
@ -12,6 +13,8 @@ use App\Models\Order;
|
||||
use App\Models\OrderItem;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
||||
|
||||
class MainController extends Controller
|
||||
{
|
||||
@ -188,34 +191,22 @@ class MainController extends Controller
|
||||
|
||||
public function myOrders()
|
||||
{
|
||||
$customerId = auth()->id(); // Assuming you are using authentication
|
||||
$orders = Order::where('customerId', session()->get('id'))->get();
|
||||
if (session()->has('id')) {
|
||||
$orders = Order::where('customerId', session()->get('id'))->get();
|
||||
$items = DB::table('products')
|
||||
|
||||
$items = DB::table('products')
|
||||
->join('order_items', 'order_items.productId', '=', 'products.id')
|
||||
->select('products.name', 'products.picture', 'products.price', 'order_items.quantity', 'order_items.orderId as order_id')
|
||||
->whereIn('order_items.orderId', $orders->pluck('id'))
|
||||
->get();
|
||||
|
||||
return view('orders', compact('orders', 'items'));
|
||||
->join('order_items', 'order_items.productId', '=', 'products.id')
|
||||
->select('products.name', 'products.picture', 'products.*')
|
||||
->get();
|
||||
|
||||
return view('orders', compact('orders', 'items'));
|
||||
}
|
||||
|
||||
return view('login');
|
||||
}
|
||||
|
||||
|
||||
// public function myOrders()
|
||||
// {
|
||||
// $customerId = auth()->id(); // Assuming you are using authentication
|
||||
// $orders = Order::where('customerId', session()->get('id'))->get();
|
||||
|
||||
// $items = DB::table('products')
|
||||
// ->join('order_items', 'order_items.productId', '=', 'products.id')
|
||||
// ->select('products.name', 'products.picture', 'products.price', 'order_items.quantity', 'order_items.orderId as order_id')
|
||||
// ->whereIn('order_items.orderId', $orders->pluck('id'))
|
||||
// ->get();
|
||||
|
||||
// return view('orders', compact('orders', 'items'));
|
||||
// }
|
||||
|
||||
|
||||
public function profile()
|
||||
{
|
||||
if (session()->has('id')) {
|
||||
@ -283,6 +274,15 @@ class MainController extends Controller
|
||||
return view('checkout');
|
||||
}
|
||||
|
||||
public function testMail()
|
||||
{
|
||||
$details = [
|
||||
'title' => 'Mail from Uron Shrestha',
|
||||
'message' => 'This is for testing mail using smtp in Laravel!'
|
||||
];
|
||||
Mail::to("yuron.stha57@gmail.com")->send(new Testing($details));
|
||||
return redirect('/');
|
||||
}
|
||||
|
||||
|
||||
public function shop()
|
||||
|
Reference in New Issue
Block a user