首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >botman io + laravel不继续对话

botman io + laravel不继续对话
EN

Stack Overflow用户
提问于 2020-09-05 23:13:31
回答 1查看 580关注 0票数 0

我正试着用电报开始7号和2号瓶的对话。一切正常,但无法继续对话。当我试图回答之前对话的任何问题时,它假设开始新的对话,而不是问对话线程的第二个问题。

我设置的电报webhook url是:

代码语言:javascript
复制
/api/telegram-bot

我的路由/api.php

代码语言:javascript
复制
Route::post('/telegram-bot', 'TelegramController@bot');

TelegramController.php

代码语言:javascript
复制
<?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

代码语言:javascript
复制
<?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时,它都会问我对话的第一个问题:“嘿,你叫什么名字?”

但在回答问题后,它将后退并返回“对不起,我没听懂您的话。只需键入开始继续。”

我在这里做的错误是什么?

EN

回答 1

Stack Overflow用户

发布于 2021-01-28 18:22:10

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

更新代码的一部分。

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

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

Botman使用缓存来维护会话。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63755421

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档