簡體   English   中英

十月CMS和BotMan

[英]OctoberCMS and BotMan

我想將聊天機器人(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 中!

首先,閱讀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 中,該目錄通常是為后端控制器保留的,因此我不建議將兩者混合使用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM