Skip to content

Instantly share code, notes, and snippets.

@jarodreyes
Created March 17, 2015 21:52
Show Gist options
  • Save jarodreyes/db7b74a1158dff1911bf to your computer and use it in GitHub Desktop.
Save jarodreyes/db7b74a1158dff1911bf to your computer and use it in GitHub Desktop.
Taco Tuesday Code
# 3rdSpace Taco Tuesday webhook
# Phone Number: 6692382267
# Register a subscriber through the web and send verification code
route :get, :post, '/tacos' do
@phone_number = Sanitize.clean(params[:From])
@body = params[:Body]
puts "******************* ERROR: #{@error} **********************"
puts "******************* BODY: #{@body} **********************"
@options = "Please type: 'chicken', 'pork', 'fish' or 'vegetarian'"
if @error == false
user = AnonUser.first_or_create(:phone_number => @phone_number)
if not @body.nil?
number_choice = @body.is_a? Integer
# Is this a taco order?
if $TACOS.include? @body or number_choice
if number_choice
@body = $TACOS[@body]
end
# Check and see how many tacos the person requested.
if user.tacos.length < 3
user.tacos.create(:flavor => @body)
user.save
num_tacos = user.tacos.length
@output = "One #{@body} coming right up. You have ordered #{num_tacos}. To order more #{@options}"
else
order = []
user.tacos.each do |taco|
order << taco
end
tacos = order * ","
@output = "Looks like you have ordered 3 tacos. Your current order is #{tacos}. Would you like to start over? If so type 'reset'."
end
else
# Since this isn't a taco order it must be something else.
case @body
# delete taco order and start over.
when 'reset'
user.tacos.all.destroy
@output = "Okay you're order has been reset. Let's start over! What kind of tacos would you like? #{@options}"
# Welcome the 3rdspacer
when 'hello'
@output = "Hello 3rd Spacer! Taco Tuesday is coming on April 7th! Free tacos for all! To order (up to 3) tacos, respond to this number. #{@options}"
else
@output = "Sorry, not sure what kind of taco that is. #{@options}"
end
end
else
@output = "Hello 3rd Spacer! Taco Tuesday is coming on April 7th! Free tacos for all! To order (up to 3) tacos, respond to this number. #{@options}"
end
end
response = Twilio::TwiML::Response.new do |r|
r.Sms @output
end
response.text
@msg2 = "This number was made intelligent using Twilio. See the code at: bit.ly/3rdTacos"
message = @client.account.messages.create(
:from => @tacos_number,
:to => @phone_number,
:body => @msg2
)
puts message.to
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment