(Classic) SMS Blog Exercise
Objective
In this exercise you will learn how to develop multiple ruleset applications.
Setup
- Create an account at Twilio
- Complete the (Classic) Twilio Stock Checker Exercise
- Complete the Data Storage exercise
Exercise
- Create and activate a ruleset named
sms_blog_data
- Add a rule named inbound_sms that listens for
twilio:inbound_sms events
. The attribute to this event will beBody
. When the
inbound_sms
rule fires, it should store theBody
attribute in a map entity variable, with the current time as the key andBody
as the value.- Finally, in the postlude put the map entity variable into the persistent application variable
sms_articles
- Add a new rule named
retrieve_data
that listens forexplicit:need_blog_data
- When the
need_blog_data
rule fires, raise an explicit event namedblog_data_ready
with the persistent application variablesms_articles
as a parameter for the ruleset namedsms_blog
.
- Add a rule named inbound_sms that listens for
- Create and activate another ruleset named
sms_blog
- Add a rule named
init_blog
the listens for apageview
event. - When the
pageview
event fires an html DIV container (with an id ofblogbody
) will be appended to the DOMbody
with an unordered list. - In the postlude raise an explicit event
container_ready
. - Also raise an explicit event
need_blog_data
for thesms_blog_data
ruleset. - Add a new rule named
show_articles
that listens for bothexplicit:container_ready
andexplicit:blog_data_ready
. - When the
show_articles
rule fires, iterate over each of the hash values in the map attributesms_articles
, recall that the hash key is thepostTime
and the value is thepostBody
. - Format and append each item as a list item into the unordered list contain.
- Add a rule named
- Configure Twilio
- In your Twilio account, create a new app called
smsBlog
. - Create an ESL (using the alternate syntax where the event domain and type are in the path) to raise
twilio:inbound_sms
to your pico (where the rulesets from the two previous steps are installed). Use that ESL for the sms request URL in Twilio. - Set up a new number, and select
smsBlog
as the app for SMS.
- In your Twilio account, create a new app called
Copyright Picolabs | Licensed under Creative Commons.