Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 7 commits
  • 4 files changed
  • 0 comments
  • 1 contributor
1  .gitignore
... ...
@@ -1,2 +1,3 @@
1 1
 .DS_Store
2 2
 Gemfile.lock
  3
+test.rb
4  mongoid.yml
@@ -8,6 +8,4 @@ development:
8 8
 production:
9 9
   sessions:
10 10
     default:
11  
-      database: twilio_reminder_production
12  
-      hosts:
13  
-        - mongohq_host:mongohq_port
  11
+      uri: <%= ENV['MONGOLAB_URI'] %>
4  rakefile.rb
@@ -5,8 +5,8 @@
5 5
 Mongoid.load!("./mongoid.yml")
6 6
 
7 7
 # set up account details
8  
-@account_sid = 'AC5062036e8c86de58c91a5a8defd91d26'
9  
-@auth_token = 'ab4a6af3f955de235068517bad0d8a26'
  8
+@account_sid = 'AC6718c6ad289aa8356207c9bc0648ce85'
  9
+@auth_token = 'e2aa801278603e955176ffa1c963fe73'
10 10
 
11 11
 # create a twilio client
12 12
 client = Twilio::REST::Client.new(@account_sid, @auth_token)
50  sms_receiver.rb
@@ -9,22 +9,54 @@
9 9
 Mongoid.load!("mongoid.yml")
10 10
 
11 11
 # set up account details
12  
-@account_sid = 'AC5062036e8c86de58c91a5a8defd91d26'
13  
-@auth_token = 'ab4a6af3f955de235068517bad0d8a26'
  12
+@account_sid = 'AC6718c6ad289aa8356207c9bc0648ce85'
  13
+@auth_token = 'e2aa801278603e955176ffa1c963fe73'
14 14
 
15 15
 # create a twilio client
16 16
 client = Twilio::REST::Client.new(@account_sid, @auth_token)
17 17
 
  18
+# table for day of the week into a number
  19
+days = { sunday: 0,
  20
+         monday: 1,
  21
+         tuesday: 2,
  22
+         wednesday: 3,
  23
+         thursday: 4,
  24
+         friday: 5,
  25
+         saturday: 6 }
  26
+
  27
+# protocol:
  28
+#   task on day of the week at time, day of the week at time, etc.
  29
+
  30
+# day of the week must be monday, tuesday, wednesday, thursday, friday
  31
+# time must be an hour and must have either an am/pm or be in 24 hour format
  32
+def split_into_task_and_time(text)
  33
+  task_and_time = text.split(" on ")
  34
+  task_and_time[1] = task_and_time[1].scan(/(monday|tuesday|wednesday|thursday|friday) at (\d{1,2})(?:am|pm|)/)
  35
+  return task_and_time
  36
+end
  37
+
18 38
 # callback for SMS receive
19  
-post '/' do
20  
-  to = params["From"].to_s
  39
+post '/sms-hook' do
  40
+  p params
  41
+
  42
+  t = split_into_task_and_time(params[:Body])
  43
+
  44
+  t[1].each do |pair|
  45
+    r = Reminder.new({task: t[0],
  46
+                     day: days[pair[0].to_sym],
  47
+                     hour: pair[1].to_i},
  48
+                     phone: params[:From])
21 49
 
22  
-  message = {:from => '+17328124972', 
23  
-             :to => to,  
24  
-             :body => 'Your text.'}
  50
+    puts r
25 51
 
26  
-  @account = client.account
27  
-  @message = @account.sms.messages.create(message)
  52
+    r.save!
  53
+  end
  54
+  
  55
+  twiml = Twilio::TwiML::Response.new do |r|
  56
+    r.Sms "We'll remind you to #{t[0]}! Text back 'stop' to stop."
  57
+  end
  58
+  
  59
+  twiml.text
28 60
 end
29 61
 
30 62
 # 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.