I have followed the instructions at,
https://www.twilio.com/blog/2016/04/receive-and-reply-to-sms-in-rails.html,
to try and send an SMS in rails 4.0. I have a trial account with a simple Rails controller as follows
class MessagesController < ApplicationController
skip_before_filter :verify_authenticity_token
# skip_before_filter :authenticate_user!, :only => "reply"
def reply
message_body = params["Body"]
from_number = params["From"]
boot_twilio
sms = @client.messages.create(
from: Rails.application.secrets.twilio_number,
to: from_number,
body: "Hello there, thanks for texting me. Your number is #{from_number}."
)
end
private
def boot_twilio
account_sid = Rails.application.secrets.twilio_sid
auth_token = Rails.application.secrets.twilio_token
@client = Twilio::REST::Client.new account_sid, auth_token
end
end
In MyAppName/config/secrets.yml, I have defined the SID and token. As per the tutorial, I am using ngrok to expose my application to the world. I have entered the URL from ngrok into Twilio's configuration as shown. I have verified the URL ngrok gave me by copying it into browser's URL. When I do, it opens my rails app at the home page.
The problem is that Twilio never routes the SMS to my rails app. Rather than responding to the SMS in my reply action, I get "Sent from your Twilio trial account - Hello from Twilio!". This is the Twilio response I got before I even wrote my Rails app. I should mention, I have
reply_messages POST /messages/reply(.:format) messages#reply
in my routing table