【问题标题】:Botman not replying博特曼没有回复
【发布时间】:2018-10-05 15:34:08
【问题描述】:

Botman 没有回复下面是我的代码

所有文件都是通过composer下载的

PHP 7.0 版

Codeigniter 版本 3

控制器:-

require __DIR__ . '/vendor/autoload.php';

use BotMan\BotMan\BotMan;
use BotMan\BotMan\Drivers\DriverManager;
use BotMan\BotMan\BotManFactory;
use BotMan\BotMan\Cache\CodeIgniterCache;

defined('BASEPATH') OR exit('No direct script access allowed');

class Home extends CI_Controller {

public function __construct() {
    parent::__construct();
    $this->load->model('healthcare_model');
    $config = [
        'botman' => [
            'conversation_cache_time' => 30
        ],
    ];

// Load the driver(s) you want to use

// Create an instance

    $this->load->driver('cache');

    $this->botman = BotManFactory::create($config, new CodeIgniterCache($this->cache->file));
}

public function chat() {

    $this->load->view('home/chat', $data);
}

public function chat_reply() {
    $this->botman->hears('hello', function($bot) {
        $bot->reply('bye~');
    });
    // Listen
    $this->botman->listen();
}

查看:

<!doctype html>
<html>
 <head>
    <title>BotMan Widget</title>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/botman-web-widget@0/build/assets/css/chat.min.css">
</head>
<body>
    <script id="botmanWidget" src='https://cdn.jsdelivr.net/npm/botman-web-widget@0/build/js/chat.js'></script>
</body>
<script>
    var botmanWidget = {
        frameEndpoint: '/home/chat',
        chatServer: '/home/chat_reply'
    };
</script>
<script src='https://cdn.jsdelivr.net/npm/botman-web-widget@0/build/js/widget.js'></script>

我无法找到问题,因为它没有显示任何问题但没有回复。

请帮忙!!! 提前致谢。

【问题讨论】:

  • 我有同样的错误,我尝试按照指南进行操作,但仍然无法正常工作,您有解决方案吗?
  • 嗨@Sukhwinder Sodhi,是否需要在 Codeigniter 上设置缓存才能使僵尸程序正常工作?
  • 我不知道我没有找到解决方案,所以我停止了工作。

标签: php codeigniter-3 chatbot botman


【解决方案1】:

你没有提到机器人版本。 botman 2.0版的以下解决方案

您需要相同或更高版本的 php7.1.3。 因为在聊天机器人中,他们使用了 PHP 7.1.3 版中添加的一些附加功能 代替 list($array1,$array2)=$data[0] 现在添加了新功能 [$array1,$array2]=$data[0] 作为 list($array1,$array2) 以及在 7.1.3 版本中完成的更多更改,因此您必须将 PHP 版本从 7.0 升级到 7.1.3 或更高版本。

之后使用 composer 安装 botman webwidget 驱动程序。 现在尝试使用以下代码更新您的代码。

use BotMan\BotMan\BotMan;
use BotMan\BotMan\Drivers\DriverManager;
use BotMan\BotMan\BotManFactory;
use BotMan\BotMan\Cache\CodeIgniterCache;
use BotMan\BotMan\Messages\Incoming\Answer;
use BotMan\BotMan\Messages\Conversations\Conversation;
use BotMan\BotMan\Messages\Outgoing\Question;
use BotMan\BotMan\Messages\Outgoing\Actions\Button;
use BotMan\BotMan\Messages\Attachments\Image;
use BotMan\BotMan\Messages\Outgoing\OutgoingMessage;

    public function chat_reply() {
            $config = [];
            $this->load->driver('cache', array('adapter' => 'apc', 'backup' => 'file'));
            DriverManager::loadDriver(\BotMan\Drivers\Web\WebDriver::class);
            $botman = BotManFactory::create($config, new CodeIgniterCache($this->cache->file));
            $botman->hears("Hi", function (BotMan $bot) {
                    $bot->reply('bye~');
            });
    }

【讨论】:

    猜你喜欢
    • 2017-07-12
    • 1970-01-01
    • 2023-03-23
    • 1970-01-01
    • 2019-08-04
    • 1970-01-01
    • 2013-05-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多