简体   繁体   中英

OctoberCMS and BotMan

I want to integrate a chatbot (BotMan version 2.0 ) into an existing OctoberCMS project , here is what I did till now :

1- I added BotMan to the projct using the following command :

composer require botman/botman

2- I created a routes.php file in the same directory as the plugin.php file

<?php

use BotMan\BotMan\BotMan;
use BotMan\BotMan\BotManFactory;
use BotMan\BotMan\Drivers\DriverManager;



//Route::match(['get', 'post'], '/botman', 'BotManController@handle');
//Route::get('/botman/tinker', 'October\Demo\BotManController@tinker');
// Create an instance
$botman = BotManFactory::create($config);

// Give the bot something to listen for.
$botman->hears('hello', function (BotMan $bot) {
    $bot->reply('Hello yourself.');
});

// Start listening
$botman->listen();

My questions are :

1- Where I have to add the BotManController.php file

2- I tried to add BotManController.php in the same directory as the routes.php file but I get the following error :

 Class 'App\Http\Controllers\Controller' not found

( and thats because its an OctoberCMS project not Laravel project ... I dont have the App directory )

Can anyone please provide me a solution to that or another way to integrate Botman into OctoberCMS !

First off, read https://luketowers.ca/blog/how-to-use-laravel-packages-in-october-cms-plugins/ as well as https://octobercms.com/docs/plugin/composer .

Secondly, you can put the BotManController file anywhere in your plugin you want as long as you understand PHP namespaces and how to properly reference it where you want to. I would probably recommend putting it in a /classes/ directory under your plugin folder, and then changing the App\\Http\\Controllers\\Controller reference to instead reference the base Illuminate\\Routing\\Controller class. You could also put it in a /controllers/ directory, but in OctoberCMS that is typically reserved for your backend controllers so I wouldn't recommend mixing the two.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM