(Classic) Twilio Stock Checker Exercise

Objective

In this exercise you will learn how to develop KRL applications that interact with the Twilio telephony APIs.

Needs update to use Sky ESLs instead of webhooks.

Setup

  1. Set up a twilio account
  2. Have a cell phone handy to test SMS messages

Exercise

  1. Create a global function called stockmessage that retrieves the price of an Facebook's stock (ticker: FB)
    1. Use the http:get() method to retrieve stock price from Yahoo's finance service.
    2. Hint: Your life will be easier if you only retrieve the stock price. Check the format option on the API call.
    3. Extract the stock price as a number from the request response.
    4. Compare that stock price with the number 38.
    5. Create a message based on the value related to 38.
      1. If lower, something like this: "Fail! Facebook's latest stock price of #{fbstock} dollars is still below it's IPO price!"
      2. if higher, something like this: "Awesome! Facebook's latest stock price of #{fbstock} dollars is above it's IPO price!"
    6. Return the message from the function.
  2. Create a rule to display the message on any webpage with a notify. 
    1. We suggest using ktest.heroku.com/{appid} which will raise a pageview event to the appid you specify.
    2. Verify that your message looks correct, given the current value of facebook's stock.
  3. Write a rule that responds to a twilio callstart event.
    1. Call the stockmessage function and store it in a variable in the pre block.
    2. Use the twilio:say() call to say the message.
    3. Use the twilio:hangup() call to end the call.
    4. Hint: When using more then one action, enclose them in curly braces {}
  4. Write a rule that responds to twilio sms events.
    1. Call the stockmessage function and store it in a variable in the pre block.
    2. Use the twilio:sms() call to send a reply sms with the message.
  5. Configure Twilio
    1. In your Twilio account, Create a new app called StockChecker.
    2. Use http://webhooks.kynetxapps.net/t/{appid}.dev/callstart for the voice request URL.
    3. Use http://webhooks.kynetxapps.net/t/{appid}.dev/sms for the sms request URL.
    4. Set up a new number, and select StockChecker as the app for both Voice and SMS.
    5. Test, Share and Enjoy!

Copyright Picolabs | Licensed under Creative Commons.