I'm newbie with Symfony. I created a Symfony App and I have a BotMan folder inside my Symfony root directory, so I want to integrate that bot in my App. My directory structure goes like this:
my_symfony_project/
bin/
config/
migrations/
...
my_botman_project/
So how can I "include" BotMan classes inside my Symfony project to be able to use them as any other Symfony class? Do I need to change my services.yaml file? How? I know maybe it's a silly question but I don't understand yet how it works. Thanks in advance.
Edit: Made some changes...
I installed BotMan again but as a standalone composer dependency, and now I have my "botman" folder inside vendor. After that, I created a twig template with the web widget and a method with the route "/botman/chat". The widget shows up but I don't know how to get the chat inside of it. A little more detail with code:
My template (mybot/index.html.twig):
<script src='https://cdn.jsdelivr.net/npm/botman-web-widget@0/build/js/widget.js'></script>
HomeController.php (only botman method)
/**
* @Route("/botman/chat", name="mybot")
*/
public function botman(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("hi");
return $this->render('mybot/index.html.twig', [
]);
}
Edit #2: Finally I've found the answer...
In order to be able to use the bot, you need to return an empty response because headers have been already sent by Botman. After that, if you only include the widget in your template...
<script src='https://cdn.jsdelivr.net/npm/botman-web-widget@0/build/js/widget.js'></script>
You'll notice that the widget is empty and only contains response in JSON. So I decided to write my template using Pete Lawrence's chatbot as a guidance and I don't use prebuilt widget. Link to the GitHub closed issue that helped me to solve this.