gasciences / botman-bundle
BotMan Symfony 扩展包
dev-master
2020-06-23 20:49 UTC
Requires
- php: >=7.1
- botman/botman: ^2.6
- botman/driver-web: ^1.5
- symfony/cache: ^3.4|^4.0
- symfony/config: ^3.4|^4.0
- symfony/dependency-injection: ^3.4|^4.0
- symfony/http-foundation: ^3.4|^4.0
- symfony/http-kernel: ^3.4|^4.0
This package is auto-updated.
Last update: 2024-09-24 06:16:24 UTC
README
如果您想在您的 Symfony (>=3.4 <5.0) 项目中集成 BotMan,请使用此扩展包。
目前它是一个非常基础的扩展包,但这是一个持续的工作,请保持关注!
它受到了 Sergio Gomez BotMan symfony 扩展包 的启发,因为它采用了在 BotMan 实例中配置 Symfony 的服务容器的想法。其余的部分都是不同的。
安装
步骤 1:下载 BotManBundle
使用 Composer
运行以下命令
composer require gasciences/botman-bundle
步骤 2:启用扩展包(仅当您不使用 Flex 时)
在您的 app/AppKernel.php
中启用扩展包
<?php // app/AppKernel.php public function registerBundles() { $bundles = [ // ... new GAS\BotmanBundle\GASBotmanBundle(), ]; }
使用方法
使用方法与您可以在 BotMan 官方文档 中阅读到的类似,但您不需要实例化一个 BotMan 对象,因为您可以从 Symfony 的服务容器中获取它,如下面的控制器示例所示
<?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(); } }
许可证
MIT 许可证 (MIT)。