【发布时间】:2017-04-21 01:57:52
【问题描述】:
我已按照以下说明进行操作,
https://www.twilio.com/blog/2016/04/receive-and-reply-to-sms-in-rails.html,
尝试在 rails 4.0 中发送短信。我有一个带有简单 Rails 控制器的试用帐户,如下所示
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
在 MyAppName/config/secrets.yml 中,我定义了 SID 和令牌。根据教程,我正在使用 ngrok 向世界公开我的应用程序。如图所示,我已将 ngrok 的 URL 输入到 Twilio 的 configuration 中。我已经通过将 ngrok 给我的 URL 复制到浏览器的 URL 中来验证它。当我这样做时,它会在主页上打开我的 rails 应用程序。
问题是 Twilio 从不将 SMS 路由到我的 rails 应用程序。我没有在回复操作中回复 SMS,而是收到“从您的 Twilio 试用帐户发送 - Twilio 您好!”。这是我在编写 Rails 应用程序之前得到的 Twilio 响应。我应该提一下,我有
reply_messages POST /messages/reply(.:format) messages#reply
在我的路由表中
【问题讨论】:
标签: ruby-on-rails twilio