Хранить пользовательские ответные сообщения в БД через Botman Chat Widget

<?php

namespace App\Http\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 ChatConversation extends Conversation
{


public function askName(){
return $this->ask('Hello! I am Webber, your personal webpage designer. What\'s your name?', function(Answer $answer){
$this->userName = $answer->getText();
$this->say('Welcome '.$this->userName. ', let\'s create your new webpage!');
$this->askWebpageActivity();
});
}

public function askWebpageActivity(){
$question = Question::create("What type of activity would your webpage be for?")
->fallback('Unable to ask question')
->callbackId('ask_webpage_activity')
->addButtons([
Button::create('Blog')->value('blog'),
Button::create('Food')->value('food'),
Button::create('Books')->value('books'),
Button::create('E-Commerce')->value('ecom'),
Button::create('Yoga')->value('yoga'),
Button::create('Science')->value('science'),
]);

$this->ask($question, function (Answer $answer) {
if ($answer->isInteractiveMessageReply()) {
if ($answer->getValue() === 'blog') {
$this->webActivity = 'Blog';
$this->say($this->webActivity);
} else if($answer->getValue() === 'food') {
$this->webActivity = 'Food';
$this->say($this->webActivity);
} else if($answer->getValue() === 'books') {
$this->webActivity = 'Books';
$this->say($this->webActivity);
} else if($answer->getValue() === 'ecom') {
$this->webActivity = 'E-Commerce';
$this->say($this->webActivity);
} else if($answer->getValue() === 'yoga') {
$this->webActivity = 'Yoga';
$this->say($this->webActivity);
} else if($answer->getValue() === 'science') {
$this->webActivity = 'Science';
$this->say($this->webActivity);
}
}
$this->say('Good, now let\'s name your webpage');
$this->askTitle();
});
}

public function askTitle(){
$this->ask('What\'s the title of your page?', function(Answer $answer){
$this->userTitle = $answer->getText();
$this->say('Got it!');
$this->say('Now let\'s name your brand');
$this->askBrand();
});
}

public function askBrand(){
$this->ask('What would you like your brand name be?', function(Answer $answer){
$this->userBrand = $answer->getText();
$this->say('Thankyou');
$this->askNavigation();
});
}

public function askNavigation(){
$question2 = Question::create("Which navigation pages would you like to have?")
->fallback('Unable to ask question')
->callbackId('ask_webpage_navigation')
->addButtons([
Button::create('Home')->value('home'),
Button::create('About')->value('about'),
Button::create('Services')->value('services'),
Button::create('Contact')->value('contact')
]);
$this->ask($question2, function(Answer $answer){
if ($answer->isInteractiveMessageReply()) {
if ($answer->getValue() === 'home') {
$this->userNavigation = 'Home';
$this->say($this->userNavigation);
}
if($answer->getValue() === 'about') {
$this->userNavigation = 'About';
$this->say($this->userNavigation);
}
if($answer->getValue() === 'services') {
$this->userNavigation = 'Services';
$this->say($this->userNavigation);
}
if($answer->getValue() === 'contact') {
$this->userNavigation = 'Contact';
$this->say($this->userNavigation);
}
}
$this->askSlider();
});
}

public function askSlider(){
$this->ask('Do you like to have slider images? [Yes/No]', function(Answer $answer){
$this->slider = $answer->getText();
$this->say($this->slider);
if ($answer->getText() === 'yes'){
$this->askUpload();
}else{
$this->askWelcome();
}
});
}

public function askUpload(){
$this->say('Upload the slider images');
$this->askWelcome();
}

public function askWelcome(){
$this->ask('What will be your welcome text? [this is the heading text]', function(Answer $answer){
$this->header = $answer->getText();
$this->say($this->header);
$this->say('Great!');
$this->askWelcomeP();
});
}

public function askWelcomeP(){
$this->ask('Now, what would be your welcome text?', function(Answer $answer){
$this->para = $answer->getText();
$this->say($this->para);
$this->say('Got it! Just wait for a moment while we generate your webpage');
});
}

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

Это мой файл чата.
Я хочу сохранить информацию, предоставленную пользователем здесь, в моей базе данных, но я не могу этого сделать. Я просто не могу этого понять. Все, что я делаю, вешает бота.

Я хочу добавить данные после того, как последняя функция скажет а затем перенаправить его для отображения веб-страницы с готовым шаблоном [у меня уже есть].

0

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector