So I am writing this chatbot project that can retrieve few user input information through conversation in Widget and retrieve all that information to generate a webpage in the new tab for the user in the prebuilt template.
For example:
1. User name
2. Web activity [basically to select the template which is stored in my db under template table. This entry is input via button system - interactive one]
3. Brand name
4. Welcome Header message,
etc.
How to store these information and retrieve it into another tab as soon as the conversation ends?
I am currently stuck at storing the information. I cannot understand documentation.
I have a BotmanController which links to Chatconversation.php where the chat conversation are kept.
I tried creating a Botman Model with migration and protected fillable array for the same entries into the database and tried invoking the $temp = new Botman in BotmanController but it's not storing any information.
Here's a structure:
BotmanController.php
public function chatConversation(BotMan $bot)
{
$bot->startConversation(new ChatConversation());
$temp = new BotmanDB;
$temp->name = $this->userName;
$temp->webact = $this->webActivity;
$temp->webname = $this->userTitle;
$temp->webbrand = $this->userBrand;
$temp->webimage = $this->slider;
$temp->webheader = $this->header;
$temp->webheaderpara = $this->para;
$temp->save();
}
ChatConversation.php
<?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();
}
}
I want the user input informations to reach the database from where I can retrieve it.
Any suggestion.
Sorry if this isn't the right place for this but I cannot seem to figure it out at all.