簡體   English   中英

Twilio sms表單在本地工作,但沒有推送到heroku - Ruby

[英]Twilio sms form works on local but not pushed to heroku - Ruby

這里的新手ruby on rails - 一直無法弄清楚這個問題。 這可能非常簡單。

我使用Twilio的api / sms功能構建了一個RoR站點,因此我可以用戶發送短信 (使用activeadmin和devise)。 一切似乎都適用於當地,但當我向Heroku推進時,我遇到了一個問題。

在我的儀表板上的activeadmin里面,我添加了表單字段來發送短信( http://i.stack.imgur.com/TXLrq.png

我有里面的視圖>管理員>儀表板> _send_a_message.html.erb和_send_message_all.html.erb我有

<%= form_tag('/send_sms', method: 'POST') do %>
<input type="text" placeholder="enter number" name="number">
<input type="text" placeholder="enter message here" name="message">
<button type="submit">Submit</button>
<% end %>

<%= form_tag('/send_sms', method: 'POST') do %>
<input type="text" placeholder="enter number" name="number">
<input type="text" placeholder="enter message here" name="message">
<button type="submit">Submit</button>
<% end %>

我將這些渲染到activeadmin儀表板然后在我的'TwilioController'中我有這兩個:

def send_sms
 message = params[:message]
 number = params[:number]
 account_sid = 'my sid'
 auth_token = 'my token'

 @client = Twilio::REST::Client.new account_sid, auth_token

 @message = @client.account.messages.create ({:to => "+1"+"#{number}",
                                              :from => "+my number",
                                              :body => "#{message}"})
 redirect_to '/admin/dashboard', :flash => { :success => "Your message sent!" }

 rescue Twilio::REST::RequestError => e
 puts e.message
end

def send_sms_all
 user_phones = User.where(:subscribed => true).pluck(:phone)
 message = params[:message]
 account_sid = 'my sid'
 auth_token = 'my token'

 @client = Twilio::REST::Client.new account_sid, auth_token

 user_phones.each do |number|
  @client.account.messages.create ({:to => "+1"+"#{number}",
                                    :from => "+my number",
                                    :body => "#{message}"})
 end 

 redirect_to '/admin/dashboard', :flash => { :success => "Your message sent!" }

 rescue Twilio::REST::RequestError => e
 puts e.message
end

我的路線是

post '/send_sms' => 'twilio#send_sms'
post '/send_sms_all' => 'twilio#send_sms_all'

這一切似乎在本地工作正常 - 可以發送消息。 當我向上推送到heroku並提交任何一個表格時,它會指示我/ send_sms頁面,它給了我“我們很抱歉,但出了點問題。” 頁面,不發送短信。

我的heroku日志似乎沒有顯示任何“錯誤”。 這個問題是否與get vs post有關? 我已經嘗試過heroku run rake和db:migrate以確保所有設置完成並且看起來很好。

有幫助嗎? 如果您需要查看其他內容,請與我們聯系。

更新:我最初調用我的secrets.yml文件,其中存儲了我的令牌和SID,而Heroku不喜歡這樣。 在我的production.rb文件中,我有這個:config.middleware.use Rack :: TwilioWebhookAuthentication,Rails.application.secrets.twilio_auth_token,'/ send_sms','/ send_sms_all'

所以我將它們移動到一個.env文件中並將它們調成這樣:config.middleware.use Rack :: TwilioWebhookAuthentication,ENV ['TWILIO_AUTH_TOKEN'],'/ send_sms','/ send_sms_all'但這給了我一個新的問題“Twilio請求驗證失敗。” 我通過制作兩個'// send_sms','// send_sms_all'來修復它。

希望這一切都有助於未來的其他人! 感謝所有幫助過以下的人!

更新:我最初調用我的secrets.yml文件,其中存儲了我的令牌和SID,而Heroku不喜歡這樣。 在我的production.rb文件中,我有這個: config.middleware.use Rack::TwilioWebhookAuthentication, Rails.application.secrets.twilio_auth_token, '/send_sms', '/send_sms_all'

所以我將它們移動到一個.env文件中並將它們調成這樣: config.middleware.use Rack::TwilioWebhookAuthentication, ENV['TWILIO_AUTH_TOKEN'], '/send_sms', '/send_sms_all'但這給了我一個新的問題“Twilio請求驗證失敗。” 我通過制作兩個'//send_sms', '//send_sms_all'

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM