Use this bundle if you want to integrate BotMan in your Symfony (>=3.4 <5.0) projects.
Currently it is very basic bundle but this is an ongoing work so stay tuned!
It is inspired by Sergio Gomez BotMan symfony bundle since it uses the idea of configuring Symfony's services container in the BotMan instance. All the rest is different.
Using Composer
Run the following command:
composer require gasciences/botman-bundle
Enable the bundle in your app/AppKernel.php
:
<?php
// app/AppKernel.php
public function registerBundles()
{
$bundles = [
// ...
new GAS\BotmanBundle\GASBotmanBundle(),
];
}
Usage is similar to what you can read in BotMan official doc except that you do not have to instantiate a BotMan object since you can get it from Symfony's services container as in the following Controller example:
<?php
// src/Controller/BotController.php
namespace App\Controller;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use BotMan\BotMan\BotMan;
class BotController extends AbstractController{
/**
* @Route("/chatbot", name="chatbot")
*/
function chatbotAction(Request $request)
{
// get a BotMan instance from Symfony's service container
$botman = $this->container->get('gas_botman.botman');
//your logic here, for e.g the following statements
$botman->hears('(hello|hi|hey)', function (BotMan $bot) {
$bot->reply('Hello');
});
$botman->fallback(function (BotMan $bot) {
$bot->typesAndWaits(2);
$bot->reply("Sorry I dd not understand your request");
});
$botman->listen();
return new Response();
}
}
The MIT License (MIT).