ChatBot Integration

This commit is contained in:
UronShrestha
2024-07-10 13:46:42 +05:45
parent f4aab0bed3
commit c566bf9c27
15 changed files with 986 additions and 27 deletions

View 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);
});
}
});
});
});
});
}
}

View File

@ -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()

54
app/Mail/Testing.php Normal file
View File

@ -0,0 +1,54 @@
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;
class Testing extends Mailable
{
use Queueable, SerializesModels;
/**
* Create a new message instance.
*/
public $details;
public function __construct($details)
{
$this->details = $details;
}
/**
* Get the message envelope.
*/
public function envelope(): Envelope
{
return new Envelope(
subject: 'Testing',
);
}
/**
* Get the message content definition.
*/
public function content(): Content
{
return new Content(
view: 'Mails.testing',
);
}
/**
* Get the attachments for the message.
*
* @return array<int, \Illuminate\Mail\Mailables\Attachment>
*/
public function attachments(): array
{
return [];
}
}

11
app/Models/UserChat.php Normal file
View File

@ -0,0 +1,11 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class UserChat extends Model
{
use HasFactory;
}