csakon csakon - 5 months ago 13x
Ruby Question

Twilio Quickstart Code for SMS Conversations not incrementing

I'm using labcoder's Twilio-Hackpack-for-Heroku-and-Sinatra then am following the Ruby Quickstart on Twilio's site. I've literally copied and pasted the code and it refuses to increment the counter.

The only difference between the quickstart code and my code is I use get_or_post:

get_or_post '/sms/?' do

Instead of their:

get '/sms-quickstart' do

When I use their get method with the /sms-quickstart, I get an ERROR (11200) HTTP Retrieval Failure. When I use get_or_post with /sms/?, it works, but my counter will not increment and I just keep getting the same "Hello, thanks for the new message." Here is the code from my app.rb

get_or_post '/sms/?' do
session["counter"] ||= 0
sms_count = session["counter"]
if sms_count == 0
message = "Hello, thanks for the new message."
message = "Hello, thanks for message number #{sms_count + 1}"
twiml = Twilio::TwiML::Response.new do |r|
r.Sms message
session["counter"] += 1


Sinatra doesn't enable sessions by default. Need to add the following to app.rb:

enable :sessions

See documentation here