botman io + laravel无法继续对话

问题描述

我正在尝试通过电报在laravel 7和botman 2中进行对话。一切正常,但无法继续对话。当我尝试回答对话的任何先前问题时,它假设是开始新对话,而不是询问对话线程的第二个问题。

我设置的电报Webhook网址为:

/api/telegram-bot

我的路线/api.PHP

Route::post('/telegram-bot','TelegramController@bot');

TelegramController.PHP

<?PHP
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Template
use App\Channel;
use Config;

use BotMan\BotMan\BotMan;
use BotMan\BotMan\BotManFactory;
use BotMan\BotMan\Drivers\DriverManager;
use App\Conversations\BankingConversation;

class TelegramController extends Controller{
  public function bot(){
        $config = [
            "telegram" => [
               "token" => "{MY_BOT_TOKEN}",'conversation_cache_time' => 30
            ]
        ];
        DriverManager::loadDriver(\BotMan\Drivers\Telegram\TelegramDriver::class);
        $botman = BotManFactory::create($config);
        
         
        $botman->hears('(hi|hello|start)',function (BotMan $bot) {
            $bot->startConversation(new BankingConversation,\BotMan\Drivers\Telegram\TelegramDriver::class );
        });

        $botman->fallback(function($bot) {
            $bot->reply('Sorry,I did not understand you. Just type start to continue.');
        });

        $botman->listen();
    }
}

最后是BankingConversation

<?PHP

namespace App\Conversations;

use Illuminate\Foundation\Inspiring;
use BotMan\BotMan\Messages\Incoming\Answer;
use BotMan\BotMan\Messages\Outgoing\Question;
use BotMan\BotMan\Messages\Outgoing\Actions\Button;
use BotMan\BotMan\Messages\Conversations\Conversation;

class BankingConversation extends Conversation
{

    protected $fullname;

    protected $email;

    public function askFullname()
    {
        $welcome = 'hey '; 

        $this->ask($welcome.' What is your name ?',function(Answer $answer) {
            // Save result
            $this->fullname = $answer->getText();

            $this->say('Nice to meet you '.$this->fullname);
            $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);
        });
    }

    public function run()
    {
        // This will be called immediately
        $this->askFullname();
    }
}

无论何时键入hi / hello / start,它都会问我第一个对话问题“嘿,你叫什么名字?”

但是,在回答了这个问题之后,它会退回并返回“对不起,我不明白您的意思。只需键入start即可继续。”

在这里犯什么错误

解决方法

您尚未指定缓存驱动程序。

更新代码部分。

DriverManager::loadDriver(\BotMan\Drivers\Telegram\TelegramDriver::class);

$botman = BotManFactory::create($config,new \BotMan\BotMan\Cache\LaravelCache());

Botman 使用缓存来维护对话。