0

我正在将我的 laravel 应用程序与 botman 集成。我希望能够将所有对话存储到 mysql 中,然后构建一个管理界面来查看所有提出的问题。我希望我的聊天机器人能够从 mysql 表中获取响应,该表将具有以下字段 id_chat name (client) question response email ip

<?php

namespace App\Botman;

use App\Models\chatbot;
use BotMan\BotMan\Messages\Conversations\Conversation;
use BotMan\BotMan\Messages\Incoming\Answer;
use DB;

class OnboardingConversation extends Conversation
{
protected $name;

protected $email;

protected $query;

public function askName()
{
    $this->ask('Hi! What is your name?', function(Answer $answer) {
        // Save result
        $name = $answer->getText();

        $d_chat=$this->bot->getUser()->getId();



        //$db->save();
        $this->say('Nice to meet you '.$name);
        $this->askEmail();
    });
}

public function askEmail()
{
    $this->ask('One more thing - what is your email address?', function(Answer $answer) 
 {
        // Save result
        $this->email = $answer->getText();

        $this->say('Great - that is all we need, '.$this->name);
        $this->askHelp();
    });
}

public function askHelp()
{
    $this->ask('How can I help you?', function(Answer $answer) {
        // Save result
        $this->query = $answer->getText();

        $this->say('Your query has been forwarded, we will contact you soon.');
    });
}

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

0 回答 0