Giter Club home page Giter Club logo

botmanbundle's Introduction

BotManBundle

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.

Installation

Step 1: Download BotManBundle

Using Composer

Run the following command:

composer require gasciences/botman-bundle

Step 2: Enable the bundle (only if you do not use Flex)

Enable the bundle in your app/AppKernel.php:

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = [
        // ...
        new GAS\BotmanBundle\GASBotmanBundle(),
    ];
}

Usage

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();
    }
}

License

The MIT License (MIT).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.