BUild a bot

php[world] 2017

Ian Littman / @iansltx

follow along at https://ian.im/botworld17s

join the #build-a-bot-workshop Slack channel

NOTE: this isn't an Alexa Skill talk

See VoiceHacks tutorials for that

We aren't building bots for Siri, Slack, or Facebook either.

If you want to do that, you're probably looking for botman.

Our bot will

  • Be accessed via a browser (initially, anyway)
  • Accept text and speech input
  • Respond with text and speech
  • Recognize various phrasings of a question
  • Pull information from a web hook we set up
  • Remember context from previous questions
  • Integrate with Google Assistant

Get Ready

You'll need...

  • Google Chrome
  • Docker or PHP 7.1
  • An ngrok (ngrok.com) account
  • A Dialogflow api.ai account (a Google product)

Requirements Gist at http://ian.im/botworld17

Pieces of a Bot

UI (web, chat, voice)

Natural Language Understanding

Data Sources (web hooks)

Pieces of a Bot

UI (web, chat, voice)

Natural Language Understanding

Data Sources (web hooks)

DIalogflow

  • Intents
  • Utterances
  • Entities
  • Slots + Parameters
  • Actions
  • Contexts
  • Fulfillment

Pieces of a Bot

UI (web, chat, voice)

Natural Language Understanding

Data Sources (web hooks)

git clone iansltx/build-a-bot*

composer install

git checkout initial-setup

* You probably want to fork my repo

JS Judgment-free zone starts now

Step 1: Get Dialogflow wired Up

Step 2: Speak your response

Step 3: Add Voice Recognition

  • SpeechRecognition
    • Chrome only; uses Google Cloud Speech
    • Easy wrapper: annyang
  • Here's what I did (see: add-voice-recognition branch)
  • Tips
    • You can use "*text" to map all recognition input to one function (param name "text") in annyang
    • annyang will keep listening until you tell it not to

Pieces of a Bot

UI (web, chat, voice)

Natural Language Understanding

Data Sources (web hooks)

composer require iansltx/dialogflow-bridge

This is the part where you need ngrok

Step 1: Set up the Web Hook

Step 2: Do something useful*

  • composer require iansltx/joind-in-client
    • You'll need to set minimum-stability to dev here...

    • ...and you may want to add prefer-stable: true

  • Use classes, rather than callables, to  handle actions
  • Here's what I did

* No special bot fairy dust here

Step 3: Add some context

  • $question->getContextParam($contextName, $paramName)
  • $answer->setContext($name, $params, $lifetime)
  • Here's what I did
  • Look ma, no database!

Bot Built. Boom.

THanks! Questions?

Build a Bot - php[world] 2017

By Ian Littman

Build a Bot - php[world] 2017

Build a Bot workshop

  • 653
Loading comments...

More from Ian Littman