我已按照指令工作,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