studio icon indicating copy to clipboard operation
studio copied to clipboard

How do I add botman 2.0 in an existing laravel 5.6 project?

Open TeamTracer opened this issue 7 years ago • 15 comments
trafficstars

TeamTracer avatar Jun 30 '18 03:06 TeamTracer

Hey @TeamTracer ,

there is no official guide to do so. I would ask in the BotMan Slack channel, I am sure there are some people who already did that. If you need help you should also provide exact problems and errors, please!

Generally speaking, you need to:

  • require packages for BotMan and the driver you need
  • you need to add a route for GET / POST requests which calls a controller which is creating a botman object, BotMan listeners and calling the listen method. (The botman.php route file from BotMan Studio is only in the Studio version loaded automatically)
  • I guess the BotMan service provider should be automatically loaded when you require the BotMan project.

But I haven't done it myself yet.

christophrumpel avatar Jul 01 '18 07:07 christophrumpel

@christophrumpel, I tried to replicate botman studio, everything is working except the botman.php route. Codes written there doesn't seem to work. I also edited the app/providers/routeserviceprovider.php but it still doesn't work.

TeamTracer avatar Jul 03 '18 06:07 TeamTracer

Follow these steps:

  1. composer require botman/botman
  2. composer require botman/driver-facebook or driver you need
  3. Copy config files from botman studio config folder to your project folder. And set them properly.
  4. Then create a controller YourController with two methods. use following code:
<?php
namespace App\Http\Controllers;

//load BotMan
use BotMan\BotMan\BotMan;
use BotMan\BotMan\BotManFactory;
use BotMan\BotMan\Drivers\DriverManager;
class MessengerController extends Controller
{
//load facebook messenger driver, or driver you need
DriverManager::loadDriver(\BotMan\Drivers\Facebook\FacebookDriver::class);
        $cacheDriver = new \Doctrine\Common\Cache\PhpFileCache('cache');
        $botman = BotManFactory::create(config('botman', new DoctrineCache($cacheDriver)));
        $botman->hears('hi', function (BotMan $bot) {
            $bot->reply('Hello Yourself');
        });
}
?>
  1. In your routes/web.php file use: Route::match(['get', 'post'],'/webhook', 'MessengerController@webhook');

prdpspkt avatar Jul 20 '18 06:07 prdpspkt

@TeamTracer any updates here?

christophrumpel avatar Sep 10 '18 18:09 christophrumpel

@christophrumpel, I haven't found any solutions. Instead I installed laravel 5.6, added botman and then replicated the remaining files of a fresh copy of botman studio. I wrote all the codes in the controller not in botman.php route.

TeamTracer avatar Sep 11 '18 02:09 TeamTracer

show your code in controller

zenia9012 avatar Oct 30 '18 20:10 zenia9012

Is there no way to add conversations while using botman in an existing laravel project?

jnk2006 avatar Dec 09 '18 18:12 jnk2006

You can create folder named conversations in app directory and use them like in botman studio.

prdpspkt avatar Dec 09 '18 19:12 prdpspkt

it isn't working that way. already tried!

jnk2006 avatar Dec 09 '18 19:12 jnk2006

I am also somewhat frustrated in my attempt to add this to a Laravel 5.7 project. Would be great to see an official guide added to the docs.

startupengine avatar Dec 31 '18 04:12 startupengine

You’ve got to add the botman.php route in RouteServiceProvider.php

jnk2006 avatar Dec 31 '18 12:12 jnk2006

Any update on that? Official instructions would be great!

MeiRct avatar Aug 18 '19 10:08 MeiRct

https://course.buildachatbot.io/?utm_source=botman-docs&utm_medium=navigation&utm_campaign=video_course

I subscribed to the $25.00 pack and saw the videos. They had all the information for adding botman to existing project and even for starting-from-scratch project. I honestly forgot how I did it, but the I do remember that the video has the required information.

jnk2006 avatar Aug 19 '19 22:08 jnk2006

I know, the topic is now 3 years old. But there seems to be a solution with this video from the creators of "Botman".

https://beyondco.de/course/build-a-chatbot/getting-started/add-botman-to-your-laravel-app

PatrickSTM avatar Feb 16 '21 09:02 PatrickSTM

I found the most straightforward way was to copy the botman-related files from the BotMan Studio Laravel project.

ianmartorell avatar Apr 03 '21 22:04 ianmartorell