Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

We’re showing branches in this repository, but you can also compare across forks.

base fork: RobertoECruz/Productivity-
base: 5944193a32
...
head fork: RobertoECruz/Productivity-
compare: b765eb249a
  • 7 commits
  • 4 files changed
  • 0 commit comments
  • 1 contributor
Showing with 45 additions and 14 deletions.
  1. +1 −0  .gitignore
  2. +1 −3 mongoid.yml
  3. +2 −2 rakefile.rb
  4. +41 −9 sms_receiver.rb
1  .gitignore
View
@@ -1,2 +1,3 @@
.DS_Store
Gemfile.lock
+test.rb
4 mongoid.yml
View
@@ -8,6 +8,4 @@ development:
production:
sessions:
default:
- database: twilio_reminder_production
- hosts:
- - mongohq_host:mongohq_port
+ uri: <%= ENV['MONGOLAB_URI'] %>
4 rakefile.rb
View
@@ -5,8 +5,8 @@
Mongoid.load!("./mongoid.yml")
# set up account details
-@account_sid = 'AC5062036e8c86de58c91a5a8defd91d26'
-@auth_token = 'ab4a6af3f955de235068517bad0d8a26'
+@account_sid = 'AC6718c6ad289aa8356207c9bc0648ce85'
+@auth_token = 'e2aa801278603e955176ffa1c963fe73'
# create a twilio client
client = Twilio::REST::Client.new(@account_sid, @auth_token)
50 sms_receiver.rb
View
@@ -9,22 +9,54 @@
Mongoid.load!("mongoid.yml")
# set up account details
-@account_sid = 'AC5062036e8c86de58c91a5a8defd91d26'
-@auth_token = 'ab4a6af3f955de235068517bad0d8a26'
+@account_sid = 'AC6718c6ad289aa8356207c9bc0648ce85'
+@auth_token = 'e2aa801278603e955176ffa1c963fe73'
# create a twilio client
client = Twilio::REST::Client.new(@account_sid, @auth_token)
+# table for day of the week into a number
+days = { sunday: 0,
+ monday: 1,
+ tuesday: 2,
+ wednesday: 3,
+ thursday: 4,
+ friday: 5,
+ saturday: 6 }
+
+# protocol:
+# task on day of the week at time, day of the week at time, etc.
+
+# day of the week must be monday, tuesday, wednesday, thursday, friday
+# time must be an hour and must have either an am/pm or be in 24 hour format
+def split_into_task_and_time(text)
+ task_and_time = text.split(" on ")
+ task_and_time[1] = task_and_time[1].scan(/(monday|tuesday|wednesday|thursday|friday) at (\d{1,2})(?:am|pm|)/)
+ return task_and_time
+end
+
# callback for SMS receive
-post '/' do
- to = params["From"].to_s
+post '/sms-hook' do
+ p params
+
+ t = split_into_task_and_time(params[:Body])
+
+ t[1].each do |pair|
+ r = Reminder.new({task: t[0],
+ day: days[pair[0].to_sym],
+ hour: pair[1].to_i},
+ phone: params[:From])
- message = {:from => '+17328124972',
- :to => to,
- :body => 'Your text.'}
+ puts r
- @account = client.account
- @message = @account.sms.messages.create(message)
+ r.save!
+ end
+
+ twiml = Twilio::TwiML::Response.new do |r|
+ r.Sms "We'll remind you to #{t[0]}! Text back 'stop' to stop."
+ end
+
+ twiml.text
end
# Callback for when people visit the site from their browser

No commit comments for this range

Something went wrong with that request. Please try again.