EVOLUTION-MANAGER
Edit File: BotManController.php
<?php namespace App\Http\Controllers; use BotMan\BotMan\BotMan; use Illuminate\Http\Request; use App\Conversations\ExampleConversation; use App\Conversations\BotConversation; use BotMan\BotMan\BotManFactory; use BotMan\BotMan\Drivers\DriverManager; use App\chatbot_respuestas; use App\chatbot_preguntas; use BotMan\BotMan\Messages\Outgoing\Question; use BotMan\BotMan\Messages\Outgoing\Actions\Button; use App\pregunta_respuestaModel; use BotMan\BotMan\Messages\Attachments\Image; use BotMan\BotMan\Messages\Outgoing\OutgoingMessage; class BotManController extends Controller { /** * Place your BotMan logic here. */ public function handle() { //$botman = app('botman'); $config = [ // Your driver-specific configuration // "telegram" => [ // "token" => "TOKEN" // ] ]; DriverManager::loadDriver(\BotMan\Drivers\Web\WebDriver::class); // Create BotMan instance $botman = BotManFactory::create($config); // $this->say('Hey 👋 soy Gia el chatbot de Sucre 💙 Cuéntame ¿En qué te puedo ayudar hoy? 💙😊'); // Give the bot something to listen for. // $this->inicio_conversacion($botman); $botman->hears('{pregunta}', function (BotMan $bot,$pregunta) { // dd($pregunta); // $chatbot = chatbot_preguntas::join('chatbot_respuestas','chatbot_respuestas.id','=','chatbot_preguntas.respuesta_id')->where('chatbot_preguntas.pregunta','like','%'.$pregunta.'%')->select('chatbot_preguntas.pregunta','chatbot_respuestas.respuesta')->first(); /* if ($chatbot) { //respuesta es tipo boton $question = Question::create($pregunta) //Saludamos al usuario //->fallback('Unable to ask question') // ->callbackId('ask_reason') ->addButtons([ Button::create($chatbot->respuesta)->value($chatbot->respuesta),//Primera opcion, esta tendra el value who //Button::create('¿Qué puedes decirme?')->value('info'), //Segunda opcion, esta tendra el value info ]); */ /* $this->ask($question, function (Answer $answer) { $chatbot = chatbot_preguntas::join('chatbot_respuestas','chatbot_respuestas.id','=','chatbot_preguntas.respuesta_id')->where('chatbot_preguntas.pregunta','like','%'.$answer->getValue().'%')->select('chatbot_preguntas.pregunta','chatbot_respuestas.respuesta')->first(); }); */ //$bot->reply($chatbot->respuesta); $respuestas=pregunta_respuestaModel::join('chatbot_preguntas','chatbot_preguntas.id','=','pregunta_respuesta.chatbot_preguntas_id') ->join('chatbot_respuestas','chatbot_respuestas.id','=','pregunta_respuesta.chatbot_respuestas_id') ->where('chatbot_preguntas.pregunta','like',$pregunta.'%') ->select('chatbot_preguntas.pregunta','chatbot_respuestas.respuesta','chatbot_respuestas.id','chatbot_preguntas.respuesta_texto','chatbot_respuestas.tipo_respuesta') ->groupBy('chatbot_respuestas.id') ->OrderBy('chatbot_respuestas.tipo_respuesta') ->get(); /* $attachment = new Image('https://d500.epimg.net/cincodias/imagenes/2018/11/13/lifestyle/1542113135_776401_1542116070_noticia_normal.jpg'); $message = OutgoingMessage::create('This is my text') ->withAttachment($attachment); $bot->reply($message); */ //$bot->reply($question); if(count($respuestas)){ if(!is_null($respuestas[0]->respuesta_texto)){ $resp_text=$respuestas[0]->respuesta_texto; $question = Question::create($resp_text); }else{ $question = Question::create($pregunta); } foreach ($respuestas as $resp) { //$bot->reply(Question::create('xxx')->addButtons([Button::create($resp->respuesta)->value($resp->respuesta)])); $question->addButtons([Button::create($resp->respuesta)->value($resp->respuesta)]); } $bot->reply($question); // $bot->reply($question); // $bot->reply($question); // $bot->reply($question); // $bot->reply($question); }else{ $bot->reply('Lo siento, No entiendo esa pregunta'); } }); //https://d500.epimg.net/cincodias/imagenes/2018/11/13/lifestyle/1542113135_776401_1542116070_noticia_normal.jpg // $botman->hears('hola', function (BotMan $bot) { // $bot->reply('Hey 👋 soy Gia el chatbot de Sucre 💙 Cuéntame ¿En qué te puedo ayudar hoy? 💙😊'); // }); // $botman->hears('hey', function (BotMan $bot) { // $bot->reply('Hey 👋 soy Gia el chatbot de Sucre 💙 Cuéntame ¿En qué te puedo ayudar hoy? 💙😊'); // }); // $botman->fallback(function($bot) { // $bot->reply('Lo siento, No entiendo esa pregunta. Intenta con hola o hey'); // }); // Start listening $botman->listen(); } /** * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View */ public function tinker() { // $config = [ // // Your driver-specific configuration // // "telegram" => [ // // "token" => "TOKEN" // // ] // ]; // DriverManager::loadDriver(\BotMan\Drivers\Web\WebDriver::class); // // Create BotMan instance // $botman = BotManFactory::create($config); // // Give the bot something to listen for. // $this->startConversation($botman); // $botman->hears('hello', function (BotMan $bot) { // $bot->reply('Hello yourself.'); // }); // $botman->hears('call me {name}', function ($bot, $name) { // $bot->reply('Your name is: '.$name); // }); // // Start listening // $botman->listen(); return view('frontend.chat_bot.tinker'); } /** * Loaded through routes/botman.php * @param BotMan $bot */ public function inicio_conversacion(BotMan $bot) { // $bot->startConversation(new ExampleConversation()); $bot->startConversation(new BotConversation()); } public function askForDatabase() { $question = Question::create('Do you need a database?') ->fallback('Unable to create a new database') ->callbackId('create_database') ->addButtons([ Button::create('Of course')->value('yes'), Button::create('Hell no!')->value('no'), ]); $this->ask($question, function (Answer $answer) { // Detect if button was clicked: if ($answer->isInteractiveMessageReply()) { $selectedValue = $answer->getValue(); // will be either 'yes' or 'no' $selectedText = $answer->getText(); // will be either 'Of course' or 'Hell no!' } }); } }