1

我想将聊天机器人(BotMan 2.0 版)集成到现有的 OctoberCMS 项目中,这是我到目前为止所做的:

1-我使用以下命令将 BotMan 添加到项目中:

composer require botman/botman

2-我在与routes.php文件相同的目录中创建了一个plugin.php文件

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

我的问题是:

1-我必须添加 BotManController.php 文件

2-我尝试将 BotManController.php 添加到与 routes.php 文件相同的目录中,但出现以下错误:

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

(那是因为它是一个 OctoberCMS 项目而不是 Laravel 项目......我没有 App 目录)

任何人都可以为我提供一个解决方案或其他方式将 Botman 集成到 OctoberCMS 中!

4

1 回答 1

0

首先,阅读https://luketowers.ca/blog/how-to-use-laravel-packages-in-october-cms-plugins/以及https://octobercms.com/docs/plugin/composer

其次,只要您了解 PHP 命名空间以及如何在您想要的位置正确引用它,您就可以将 BotManController 文件放在您想要的插件中的任何位置。我可能会建议将它放在插件文件夹下的 /classes/ 目录中,然后将App\Http\Controllers\Controller引用更改为引用基Illuminate\Routing\Controller类。您也可以将其放在 /controllers/ 目录中,但在 OctoberCMS 中通常为您的后端控制器保留,因此我不建议将两者混合使用。

于 2018-11-24T16:56:41.207 回答