Php BotMan-Conversations方法未应答

Php BotMan-Conversations方法未应答,php,chatbot,messenger,botman,Php,Chatbot,Messenger,Botman,我正在facebook messenger机器人上工作。我使用的是Botman(Botman.io),没有Laravel或Botman工作室。PHP的版本是7.4 简单的倾听和回答方法很好,但对话回答方法不起作用 如果我尝试键入hi | hello或一些问候语,chatbot会回答我“hello!你的名字是什么?”,然后我写下我的名字,chatbot不会返回任何文本:-/ 你能帮帮我臭虫在哪里吗 有一个对话班: namespace LiborMatejka\Conversations; use

我正在facebook messenger机器人上工作。我使用的是Botman(Botman.io),没有Laravel或Botman工作室。PHP的版本是7.4

简单的倾听和回答方法很好,但对话回答方法不起作用

如果我尝试键入hi | hello或一些问候语,chatbot会回答我“hello!你的名字是什么?”,然后我写下我的名字,chatbot不会返回任何文本:-/

你能帮帮我臭虫在哪里吗

有一个对话班:

namespace LiborMatejka\Conversations;

use BotMan\BotMan\Messages\Conversations\Conversation;
use BotMan\BotMan\Messages\Incoming\Answer;

    class OnboardingConversation extends Conversation {

        protected $firstname;
        protected $email;

        function askFirstname() {

            $this->ask('Hello! What is your firstname?', function (Answer $answer) {

                // Save result
                $this->firstname = $answer->getText();

                $this->say('Nice to meet you ' . $this->firstname);

                $this->askEmail();

            });

        }

        public function askEmail() {

            $this->ask('One more thing - what is your email?', function (Answer $answer) {
                // Save result
                $this->email = $answer->getText();

                $this->say('Great - that is all we need, ' . $this->firstname);
            });

            //$this->bot->typesAndWaits(2);
        }

        public function run() {

            // This will be called immediately

            $this->askFirstname();

        }

    }
require_once "vendor/autoload.php";
require_once "class/onboardingConversation.php";

use BotMan\BotMan\BotMan;
use BotMan\BotMan\BotManFactory;
use BotMan\BotMan\Drivers\DriverManager;
use BotMan\Drivers\Facebook\FacebookDriver;
use LiborMatejka\Conversations\OnboardingConversation;

$config = [
    // Your driver-specific configuration
    'facebook' => [
        'token' => 'my_token',
        'app_secret' => 'my_secret_app_code',
        'verification' => 'verification_code',
    ],
    'botman' => [
        'conversation_cache_time' => 0,
    ],
];

// Load the driver(s) you want to use
DriverManager::loadDriver(\BotMan\Drivers\Facebook\FacebookDriver::class);

// Create an instance
$botman = BotManFactory::create($config);

$botman->hears('ahoj|hi|hello|cau|cus|zdar|zdarec|cago|hey|ciao', function (BotMan $bot) {
    $bot->startConversation(new OnboardingConversation);
});

// Start listening
$botman->listen();
还有配置

namespace LiborMatejka\Conversations;

use BotMan\BotMan\Messages\Conversations\Conversation;
use BotMan\BotMan\Messages\Incoming\Answer;

    class OnboardingConversation extends Conversation {

        protected $firstname;
        protected $email;

        function askFirstname() {

            $this->ask('Hello! What is your firstname?', function (Answer $answer) {

                // Save result
                $this->firstname = $answer->getText();

                $this->say('Nice to meet you ' . $this->firstname);

                $this->askEmail();

            });

        }

        public function askEmail() {

            $this->ask('One more thing - what is your email?', function (Answer $answer) {
                // Save result
                $this->email = $answer->getText();

                $this->say('Great - that is all we need, ' . $this->firstname);
            });

            //$this->bot->typesAndWaits(2);
        }

        public function run() {

            // This will be called immediately

            $this->askFirstname();

        }

    }
require_once "vendor/autoload.php";
require_once "class/onboardingConversation.php";

use BotMan\BotMan\BotMan;
use BotMan\BotMan\BotManFactory;
use BotMan\BotMan\Drivers\DriverManager;
use BotMan\Drivers\Facebook\FacebookDriver;
use LiborMatejka\Conversations\OnboardingConversation;

$config = [
    // Your driver-specific configuration
    'facebook' => [
        'token' => 'my_token',
        'app_secret' => 'my_secret_app_code',
        'verification' => 'verification_code',
    ],
    'botman' => [
        'conversation_cache_time' => 0,
    ],
];

// Load the driver(s) you want to use
DriverManager::loadDriver(\BotMan\Drivers\Facebook\FacebookDriver::class);

// Create an instance
$botman = BotManFactory::create($config);

$botman->hears('ahoj|hi|hello|cau|cus|zdar|zdarec|cago|hey|ciao', function (BotMan $bot) {
    $bot->startConversation(new OnboardingConversation);
});

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

问题已解决-我使用composer将symfony缓存添加到项目中

 composer require symfony/cache
将以下内容放在index.php(或其他)文件的顶部,您将在其中设置BotMan

use BotMan\BotMan\Cache\SymfonyCache;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
然后使用以下命令创建BotMan:

$adapter = new FilesystemAdapter();
$botman = BotManFactory::create($config, new SymfonyCache($adapter));
然后相应地使用
$botman
变量,如下例所示:

$botman->hears('Hi', function (BotMan $bot) {
    $bot->typesAndWaits(2);
    $bot->reply('Hello and welcome');
    $bot->typesAndWaits(2);
    $bot->ask('Anything I can do for you today?',function($answer, $bot){
        $bot->say("Oh, really! You said '{$answer->getText()}'... is that right?");
    });
});

我更愿意使用自动连接在创建Botman实例的任何位置注入SymfonyCache,而不必一次又一次地创建适配器和缓存

步骤1:
cache.yaml中配置缓存

framework:
    cache:
        # botman: cache adapter
        app: cache.adapter.filesystem
services:
    BotMan\BotMan\Cache\SymfonyCache:
        arguments:
            $adapter: '@cache.app'

步骤2:
服务中自动布线。yaml

framework:
    cache:
        # botman: cache adapter
        app: cache.adapter.filesystem
services:
    BotMan\BotMan\Cache\SymfonyCache:
        arguments:
            $adapter: '@cache.app'

步骤3:在需要的地方插入
SymfonyCache
,例如在
ChatController::message()中


要创建在线对话,只需按照

解决问题的文档进行操作-我添加了symfony缓存,现在一切正常。您好,您能帮助我将botman集成到我的symfony项目中吗?