I assume that you use the Botman web widget to render the chat box.
You need three routes and three controller functions:
here is a basic example:
<?php
namespace AppBundle\Controller;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use BotMan\BotMan\BotMan;
use BotMan\BotMan\BotManFactory;
use BotMan\BotMan\Drivers\DriverManager;
class BobotController extends Controller{
/**
* @Route("/message", name="message")
*/
function messageAction(Request $request)
{
DriverManager::loadDriver(\BotMan\Drivers\Web\WebDriver::class);
// Configuration for the BotMan WebDriver
$config = [];
// Create BotMan instance
$botman = BotManFactory::create($config);
// Give the bot some things to listen for.
$botman->hears('(hello|hi|hey)', function (BotMan $bot) {
$bot->reply('Hello!');
});
// Set a fallback
$botman->fallback(function (BotMan $bot) {
$bot->reply('Sorry, I did not understand.');
});
// Start listening
$botman->listen();
return new Response();
}
/**
* @Route("/", name="homepage")
*/
public function indexAction(Request $request)
{
return $this->render('DoctixFrontBundle:Chat:homepage.html.twig');
}
/**
* @Route("/chatframe", name="chatframe")
*/
public function chatframeAction(Request $request)
{
return $this->render('DoctixFrontBundle:Chat:chat_frame.html.twig');
}
}
And you need two views, first the chat framechat_frame.html.twig
(a simple copy-paste of the one provided in Botman web widget's documentation):
<!DOCTYPE html>
<html lang="en">
<head>
<title>BotMan Widget</title>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/botman-web-widget@0/build/assets/css/chat.min.css">
</head>
<body>
<script id="botmanWidget" src='https://cdn.jsdelivr.net/npm/botman-web-widget@0/build/js/chat.js'></script>
</body>
</html>
And the page that will contain the chat widget in its bottom right cornerhomepage.html.twig
:
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Hello World!</title>
</head>
<body>
<h1>Hello!</h1>
<p>Click on the chat button.</p>
<script>
var botmanWidget = {
frameEndpoint: '{{ path("chatframe") }}',
chatServer: '{{ path("message") }}',
introMessage: 'Hello, I am a Chatbot',
title: 'My Chatbot',
mainColor: '#456765',
bubbleBackground: '#ff76f4',
aboutText: ''
};
</script>
<script src='https://cdn.jsdelivr.net/npm/botman-web-widget@0/build/js/widget.js'></script>
</body>
</html>
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.
PHP (from the English Hypertext Preprocessor - hypertext preprocessor) is a scripting programming language for developing web applications. Supported by most hosting providers, it is one of the most popular tools for creating dynamic websites.
The PHP scripting language has gained wide popularity due to its processing speed, simplicity, cross-platform, functionality and distribution of source codes under its own license.
https://www.php.net/
Symfony compares favorably with other PHP frameworks in terms of reliability and maturity. This framework appeared a long time ago, in 2005, that is, it has existed much longer than most of the other tools we are considering. It is popular for its web standards compliance and PHP design patterns.
https://symfony.com/
CSS (Cascading Style Sheets) is a formal language for describing the appearance of a document written using a markup language.
It is mainly used as a means of describing, decorating the appearance of web pages written using HTML and XHTML markup languages, but can also be applied to any XML documents, such as SVG or XUL.
https://www.w3.org/TR/CSS/#css
Foundation, similar to Bootstrap, has become very popular as a more complex framework with some advanced but easy-to-implement CSS components. It is built with Sass, so just like Bootstrap, it is customizable. In addition to this, it also boasts some features that help make the design mobile responsive.
https://get.foundation/
HTML (English "hyper text markup language" - hypertext markup language) is a special markup language that is used to create sites on the Internet.
Browsers understand html perfectly and can interpret it in an understandable way. In general, any page on the site is html-code, which the browser translates into a user-friendly form. By the way, the code of any page is available to everyone.
https://www.w3.org/html/
Welcome to the Q&A site for web developers. Here you can ask a question about the problem you are facing and get answers from other experts. We have created a user-friendly interface so that you can quickly and free of charge ask a question about a web programming problem. We also invite other experts to join our community and help other members who ask questions. In addition, you can use our search for questions with a solution.
Ask about the real problem you are facing. Describe in detail what you are doing and what you want to achieve.
Our goal is to create a strong community in which everyone will support each other. If you find a question and know the answer to it, help others with your knowledge.