Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
moving receive to a webhook worker, cleaning up directory structure
- Loading branch information
Showing
9 changed files
with
86 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,19 @@ | ||
|
||
1. fill in values in config file | ||
2. iron_worker upload send_insanity | ||
3. deploy app to heroku | ||
Setup: | ||
|
||
To receive Twilio SMS's back: | ||
sudo bundle install (iron_worker_ng has the iron_worker command line interface) | ||
fill in values in config file | ||
fill in values in workers/iron.json | ||
cd workers | ||
iron_worker upload send_insanity | ||
iron_worker upload twilio_webhook | ||
|
||
https://devcenter.heroku.com/articles/ruby | ||
To Run: | ||
|
||
Deploy the Heroku app to your own account | ||
ruby web.rb | ||
browse to http://localhost:4567/ | ||
enter your number | ||
|
||
|
||
|
||
https://worker-aws-us-east-1.iron.io/2/projects/{PROJECT_ID}/tasks/webhook?code_name=TwilioWebhook&oauth={TOKEN} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,4 @@ name "SendInsanity" | |
gem "twilio-ruby" | ||
gem "iron_cache" | ||
|
||
file "config.yml" | ||
file "../config/config.yml" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
require 'cgi' | ||
require 'yaml' | ||
require 'iron_cache' | ||
require 'twilio-ruby' | ||
|
||
|
||
parsed = CGI::parse(payload) | ||
from = parsed["From"][0] | ||
body = parsed["Body"][0] | ||
|
||
|
||
puts "-------------- RECEIVING REQUEST ---------------" | ||
puts "PAYLOAD: #{payload}" | ||
puts "Parsed Payload: #{parsed}" | ||
puts "FROM: #{from}" | ||
puts "BODY: #{body}" | ||
puts "------------------------------------------------" | ||
|
||
number = from.reverse.chop.chop.reverse | ||
|
||
|
||
def shaunism | ||
all = [] | ||
File.open('shaunisms.txt', 'r') do |f| | ||
while line = f.gets | ||
all << line.chomp | ||
end | ||
end | ||
all[rand(all.size)] | ||
end | ||
|
||
|
||
|
||
def move_day_forward(number) | ||
puts "Moving Day Forward" | ||
|
||
config = YAML.load_file("config.yml") | ||
twilio = Twilio::REST::Client.new config['twilio']['account_sid'], config['twilio']['auth_token'] | ||
|
||
puts "Creating or Getting Cache...." | ||
ironcache = IronCache::Client.new(:project_id => config['iron']['project_id'], :token => config['iron']['token']) | ||
cache = ironcache.cache("insanity-#{number}") | ||
|
||
puts "Incrementing Day Cache" | ||
cache.increment("day") | ||
|
||
puts "Sending Shaunism" | ||
message = "Great job today. As Shaun T would say \"#{shaunism.chomp}\"" | ||
twilio.account.sms.messages.create( | ||
:from => config['app']['from'], | ||
:to => number, | ||
:body => message | ||
) | ||
end | ||
|
||
|
||
|
||
move_day_forward(number) if body.downcase == "done" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
runtime "ruby" | ||
exec "twilio_webhook.rb" | ||
name "TwilioWebhook" | ||
|
||
gem "twilio-ruby" | ||
gem "iron_cache" | ||
|
||
file "../config/config.yml" | ||
file "../lists/shaunisms.txt" |