[英]botman io + laravel not continue conversations
我正在尝试使用电报在 laravel 7 和 botman 2 中开始对话。 一切正常,但无法继续对话。 当我试图回答对话的任何先前问题时,它假设开始新对话而不是询问对话线程的第二个问题。
我设置的电报网络钩子网址是:
/api/telegram-bot
我的路线/api.php
Route::post('/telegram-bot', 'TelegramController@bot');
电报控制器.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();
}
}
最后是银行业对话
<?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 使用缓存来维护对话。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.