sgomez / botman-bundle
BotMan integration for Symfony
Installs: 304
Dependents: 0
Suggesters: 0
Security: 0
Stars: 12
Watchers: 2
Forks: 9
Open Issues: 2
Type:symfony-bundle
Requires
- php: ^7.2
- ext-curl: *
- ext-json: *
- botman/botman: ^2.4
- php-http/client-common: ^1.7
- php-http/client-implementation: ^1.0
- symfony/cache: ^3.4|^4.0
- symfony/config: ^3.4|^4.0
- symfony/console: ^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
- symfony/routing: ^3.4|^4.0
- tightenco/collect: ^5.6
Requires (Dev)
- botman/driver-amazon-alexa: ^1.0
- botman/driver-botframework: ^1.0
- botman/driver-cisco-spark: ^1.0
- botman/driver-facebook: ^1.0
- botman/driver-hangouts: ^1.0
- botman/driver-hipchat: ^1.0
- botman/driver-kik: ^1.0
- botman/driver-nexmo: ^1.0
- botman/driver-slack: ^2.0
- botman/driver-telegram: ^1.0
- botman/driver-twilio: ^1.0
- botman/driver-twitter: ^1.0
- botman/driver-wechat: ^1.0
- illuminate/support: ^5.6
- matthiasnoback/symfony-config-test: ^4.0
- matthiasnoback/symfony-dependency-injection-test: ^3.0
- php-http/guzzle6-adapter: ^1.1
- php-http/httplug-bundle: ^1.11
- phpstan/phpstan: ^0.10.3
- phpstan/phpstan-phpunit: ^0.10.0
- phpstan/phpstan-symfony: ^0.10.1
- phpunit/phpunit: ^7.3
- symplify/easy-coding-standard: ^4.6
Suggests
- botman/driver-telegram: ^1.5
- php-http/httplug-bundle: ^1.11
This package is auto-updated.
Last update: 2024-11-27 20:26:00 UTC
README
BotMan integration for Symfony
This is a bundle to use BotMan framework in Symfony.
Supported drivers
Only the marked drivers are supported. See the official driver documentation to have more information:
- Amazon Alexa
- Cisco Spark
- Facebook Messenger
- Hangouts Chat
- HipChat
- Microsoft Bot Framework
- Nexmo
- Slack
- Telegram
- Twilio
- Web
Installation
Step 1: Download the bundle
Install the library via Composer by running the following command:
composer require sgomez/botman-bundle
Step 2: Enable the bundle
You can skip this step if you are using Symfony Flex.
Enable the bundle in your app/AppKernel.php
file:
<?php // app/AppKernel.php public function registerBundles() { $bundles = array( // ... new Sgomez\Bundle\BotmanBundle\BotmanBundle(), // ... ); }
Step 3: Configure the bundle
You can see a template of config file by running console config:dump-reference botman
.
botman: drivers: telegram: parameters: token: ~ facebook: parameters: token: ~ app_secret: ~ verification: ~ start_button_payload: ~ # Optional greeting: # Optional # Array of - locale: ~ # Required text: ~ # Required whitelisted_domains: [] # Optional
You only must add the drivers than you want to use.
Step 4: Configure the webhook
Add the router configuration for the webhook in your routing.yaml:
BotmanBundle: resource: . type: extra
The webhook path is /botman
by default, but we recommend to change it by security issues.
botman: path: /botman57637357-65ce-4faf-a9d9-ee2c13011d87
Now, you must create the webhook controller class. By default is configured as App\Controller\WebhookController
:
<?php // file: src/Controller/WebhookController.php declare(strict_types=1); namespace App\Controller; use BotMan\BotMan\BotMan; use Symfony\Component\HttpFoundation\Response; class WebhookController { public function __invoke(BotMan $bot): Response { // Add your logic here // Echo bot example $bot->fallback(function (BotMan $bot): void { $bot->reply($bot->getMessage()->getText()); }); // Stop touching $bot->listen(); return new Response('', Response::HTTP_OK); } }
If you want to change the controller class or you are not using Symfony Flex, you will need to specify the controller class in the config file:
botman: controller: AppBundle\Controller\WebhookController
To know more about how to listen or send messages read the official documentation.
Services
This bundle configure the Symfony container in the BotMan instance. So, you can inject dependencies via constructor in Conversations classes.
In you want to use BotMan instance in your services, you can inject BotMan\BotMan\BotMan
class or botman
alias.
Drivers command
Some driver will have commands to help to configure it:
The next commands are available:
Telegram
Contributing
Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.
Versioning
We use SemVer for versioning. For the versions available, see the tags on this repository. However, this project is in very alpha status and config file format can change very quickly.
License
This project is licensed under the MIT License - see the LICENSE.md file for details