简体   繁体   中英

Botman not replying

Botman is not replying below is my code

All files are downloaded through composer

PHP version 7.0

Codeigniter version 3

Controller:-

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

View:

<!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>

I am not able to found the issue as it is not showing any issue but its not replying.

Please Help!!! Thanks in advance.

You didn't mention a botman version. following solution for botman version 2.0

You need an equal or higher version of php7.1.3. Because in chatbot they are using some additional features which added in PHP version 7.1.3 like instead of list($array1,$array2)=$data[0] now added new feature [$array1,$array2]=$data[0] which work as list($array1,$array2) and many more changes done in version 7.1.3 so you must have to upgrade your PHP version from 7.0 to 7.1.3 or higher.

After That install botman webwidget driver using composer. now try to update your code with following.

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~');
            });
    }

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