我已按照指令工作,Twilio短信不能与轨道4
https://www.twilio.com/blog/2016/04/receive-and-reply-to-sms-in-rails.html,
尝试和在轨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 /配置/ secrets.yml,我已经定义了SID和令牌。根据教程,我使用ngrok将我的应用程序展示给世界。如图所示,我输入了从ngrok到Twilio的configuration的URL。我已经验证了URL ngrok通过将其复制到浏览器的URL中给我。当我这样做时,它会在主页上打开我的Rails应用程序。
问题是,Twilio从未将短信路由到我的Rails应用。我的答复行动不是回复短信,而是“从Twilio试用帐户发送 - Twilio的Hello!”。这是我写过Rails应用之前得到的Twilio响应。我要指出,我在路由表中有
reply_messages POST /messages/reply(.:format) messages#reply
问题解决。这也是应对答复的更好方法。谢谢。 – RamJet
甜美!你会介意把答案标记为正确的,以便看到这个问题的其他人也能看到它的效果吗?谢谢! – philnash