[英]botman io + laravel not continue conversations
I am trying to start a conversation in laravel 7 and botman 2 with telegram.我正在尝试使用电报在 laravel 7 和 botman 2 中开始对话。 All works fine as but unable to continue the conversations.
一切正常,但无法继续对话。 When I am trying to answer any previous question of the conversation it assuming to start the new conversation and not asking the 2nd question of the conversation thread.
当我试图回答对话的任何先前问题时,它假设开始新对话而不是询问对话线程的第二个问题。
The telegram webhook url i set is :我设置的电报网络钩子网址是:
/api/telegram-bot
My routes/api.php我的路线/api.php
Route::post('/telegram-bot', 'TelegramController@bot');
TelegramController.php电报控制器.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();
}
}
and finally the 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();
}
}
Whenever is am typing hi/hello/start it's asking me first question of conversation "Hey What is your name ?"每当我输入 hi/hello/start 时,它都会问我对话的第一个问题“嘿,你叫什么名字?”
But after replying to the question it's going to fallback and returning "Sorry, I did not understand you. Just type start to continue."但在回答问题后,它会回退并返回“对不起,我不明白你的意思。只需输入 start 即可继续。”
What is the mistake i am doing here ?我在这里做的错误是什么?
You have not specified the cache driver.您尚未指定缓存驱动程序。
update section of your code.更新代码的部分。
DriverManager::loadDriver(\\BotMan\\Drivers\\Telegram\\TelegramDriver::class); DriverManager::loadDriver(\\BotMan\\Drivers\\Telegram\\TelegramDriver::class);
$botman = BotManFactory::create($config, new \\BotMan\\BotMan\\Cache\\LaravelCache()); $botman = BotManFactory::create($config, new \\BotMan\\BotMan\\Cache\\LaravelCache());
Botman uses cache to maintain the conversation. Botman 使用缓存来维护对话。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.