Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Let's Build a Chatbot - WavePHP 2018

Avatar for Marcus Moore Marcus Moore
September 20, 2018

Let's Build a Chatbot - WavePHP 2018

Avatar for Marcus Moore

Marcus Moore

September 20, 2018
Tweet

More Decks by Marcus Moore

Other Decks in Programming

Transcript

  1. 4

  2. 5

  3. 6

  4. 7

  5. 8

  6. 16

  7. 17

  8. 18

  9. 19

  10. 20

  11. 21

  12. 22

  13. 23

  14. 24

  15. 25

  16. DRIVERS Alexa Cisco Spark Facebook Messenger Hangouts Chat HipChat Microsoft

    Bot FW Nexmo Slack Telegram Twilio Web WeChat 29
  17. BOTMAN STUDIO ▸ A pre-configured Laravel application to get you

    started using BotMan quickly ▸ botman new weather-bot ▸ php artisan botman:install-driver facebook ▸ Easy testing 32
  18. // routes/botman.php $botman = app('botman'); $dialogflow = Dialogflow::create(config('wave.dialogflow_key'))->listenForAction(); $botman->middleware->received($dialogflow); $botman->group(['middleware'

    => $dialogflow], function ($bot){ $bot->hears('cfp', BotManController::class . '@cfp'); $bot->hears('greet', BotManController::class . '@greet'); $bot->hears('help', BotManController::class . '@help'); $bot->hears('info', BotManController::class . '@info'); $bot->hears('speaker', BotManController::class . '@speaker'); $bot->hears('speaker_bio', BotManController::class . '@speaker_bio'); $bot->hears('speaker_schedule', BotManController::class . '@speaker_schedule'); $bot->hears('sponsor_information', BotManController::class . '@sponsor_information'); }); 34
  19. // App\Http\Controllers\BotmanController.php public function help(Botman $bot) { $bot->reply('You can ask

    me a few things like such as "When is the conference?", "Who is speaking?"'); $bot->typesAndWaits(1); $bot->reply('You can even ask me about a specific speaker or sponsor with "Tell me about SDPHP" or "tell me about Cal Evans"'); } 35
  20. public function greet(Botman $bot) { $user = $bot->getUser(); $greeting =

    array_random([ 'Hello', 'Hey there', 'Greetings', 'Yo, what\'s up', 'Salutations', 'Bonjour', 'Hola', 'Namaste', ]); $bot->reply($greeting . ' ' . $user->getFirstName()); } 36
  21. public function sponsor_information(Botman $bot) { // .... // create attachment

    with sponsor logo image $attachment = new Image($sponsorData['logo_url'], [ 'custom_payload' => true, ]); // build the logo message $message = OutgoingMessage::create() ->withAttachment($attachment); // send the logo $bot->reply($message); } 37
  22. class OnboardingConversation extends Conversation { protected $firstname; protected $email; public

    function askFirstname() { $this->ask('Hello! What is your firstname?', function(Answer $answer) { // Save result $this->firstname = $answer->getText(); $this->say('Nice to meet you '.$this->firstname); $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->askFirstname(); } } 38
  23. 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!' } }); } 39