Many websites uses automatic bot reply to user query. The Bot automatically reply general queries to user inquiry. This will reduce work for customer executives.
In this article, I will show you how to create Botman chat application using Botman 2.0 package. There are also third party integration available, but you cal also do it yourself.
Follow these steps to create Botman chat application.
First of all we need to install Laravel application using bellow command, So open your terminal or CMD and run bellow command:
composer create-project laravel/laravel botman
In this step, we will install botman package using composer. We will also need to install botman web driver. so we need to run following command to install botman.
Install Botman package:
composer require botman/botman
Install Botman driver:
composer require botman/driver-web
In this step, we will create controller. Run the below command to create controller.
php artisan make:controlle BotmanController
We need some conversion reply, though you can write your own conversion. Create below methods into controller.
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use BotMan\BotMan\BotMan;
use BotMan\BotMan\Messages\Incoming\Answer;
class BotmanController extends Controller
{
/**
* Place your BotMan converison.
*/
public function enterRequest()
{
$botman = app('botman');
$botman->hears('{message}', function($botman, $message) {
if ($message == 'Hi! i need your help') {
$this->askName($botman);
} else {
$botman->reply("Hello! how can i Help you...?");
}
});
$botman->listen();
}
/**
* Place your BotMan converison.
*/
public function askReply($botman)
{
$botman->ask('Hello! What is your Name?', function(Answer $answer) {
$name = $answer->getText();
$this->say('Nice to meet you '.$name);
});
}
}
Step 4: Create route
Now we need to create two routes into routes/web.php file. Open file and add the below two routes into it.
<?php
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\BotmanController;
Route::match(['get', 'post'], '/chatbox', [ChatBoxController::class.'enterRequest']);
You already have welcome.blade.php file at resources/views folder. We will use this blade for chatbox. So update that file as below:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Botchatbox Chat Application</title>
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/[email protected]/build/assets/css/chat.min.css">
<script src='https://cdn.jsdelivr.net/npm/[email protected]/build/js/widget.js'></script>
<style>
html, body {
background-color: #fff;
color: #636b6h;
font-weight: 100;
height: 100px;
margin: 10px;
}
</style>
<script type="text/javascript">
var botmanWidget = {
aboutText: 'Hello there',
introMessage: "I am Botman, Happy to talk with you!"
};
</script>
</head>
<body>
</body>
</html>
Now your application is ready. Run laravel server php artisan serve
and open http://localhost:8000/
into browser.
I hope it will help you.
Hi, My name is Harsukh Makwana. i have been work with many programming language like php, python, javascript, node, react, anguler, etc.. since last 5 year. if you have any issue or want me hire then contact me on [email protected]
How to use the PHP Ternary Operator
If else condition is used to execute the...Angular 9 - CRUD Example with PHP and MySql
In this tutorial, you'll learn to en...How to install elastic search in local system and live server
Laravelcode write one of the very helpfu...GEO Location Track In Google Map With JavaScript
Today, Laravelcode share with you how to...Laravel7 and Angular Token-Based Authentication using JWT
Implement Laravel Authentication JSON We...