簡體   English   中英

botman io + laravel 不繼續對話

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM