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