As part of this exercise, you’re going to prepare an interactive mock up of your bot. Think of it as an ‘invision’ demonstration. As part of this weeks exercise you’ll translate your application into a form where you can test the workflow and experience live.
Simply put, it’s a prototype that isn’t hooked up with complex functionality, real outcomes or third party services.
We’re basically building a ‘wireframe’ diagram with code.
As part of this:
You won’t:
You will:
You’ll need two diagrams.
Starting with the workflow diagram:
If you were going to do a giphy search application through SMS you might end up with something like this
get 'sms_gateway' do
# get the parameters from twilio
sender = params[:From] || ""
body = params[:Body] || ""
# format the body correctly
body = body.downcase.strip
# decide what to respond with
message = decide_response( body )
# respond back to the message
twiml = Twilio::TwiML::Response.new do |resp|
resp.Message message
end
end
def decide_response body
# response to the search
if body == "hi"
"I'm a basic giphy search you can send me a command by saying search [something]"
elsif body == "help"
" you can send me a command by saying search [something]"
elsif body.starts_with? "search"
search_giphy body
elsif body.starts_with? "advanced_search"
advanced_search_giphy body
else
"I didn't understand"
end
end
# this will search the giphy api
# and return an image matching a query from the user
def search_giphy query
# return a dummy response for now...
# this will display a test image...
"http://i.giphy.com/gw3IWyGkC0rsazTi.gif"
end
# this contains a method for advance search of giphy
def advanced_search_giphy query
#...
"http://i.giphy.com/gw3IWyGkC0rsazTi.gif"
end
Note Avoid the temptation to actually implement functionality like calling a webservice. Just implement the workflow. Note See the above example doesn’t actually connect to a live web application. It just returns a hardcoded image to test with. Note Ideally incorporate the personality and script developed as part of class.
Then, use your data diagram to begin
app.rb
using a require_relative ./models/<model_name>
rake db:migrate
There’s a few ways you can test.
I highly recommend using cURL to test your app locally before you deploy. It’s a really useful strategy. If you’re going to do this, you can a) set up a dummy endpoint that allows you to pass information you’d like to test and get sample responses or b) simulate the kinds of calls you expect to get from whatever bot communication platform you plan to work with e.g Twilio. If you go with b; add a puts params
to your endpoint, deploy to heroku and test the
Once your confident the code works, deploy to heroku and test through the proper platform (Twilio’s SMS, Slack or Alexa).
Make sure you’re happy with the workflow, the interactions, conversation and outcomes. Adjust as necessary.