2017-09-12 6 views
0

私はtwilio APIからSMSを受信しようとしています。私は自分のルートやリソースの中で何も処理しない別の応答コントローラを生成しました。これはtwilioと通信するためにpostメソッドを使用します。イムは、エラーを取得:ここRails - ArgumentError(引数が間違っています(指定された1、期待される0)):

"ArgumentError (wrong number of arguments (given 1, expected 0)):" 

replycontroller.rb

class ReplyController < ApplicationController 

    require 'twilio-ruby' 

    skip_before_action :verify_authenticity_token 

    def hart1 

    twiml = Twilio::TwiML::Response.new do |r| 
     r.Message 'The Robots are coming! Head for the hills!' 
    end 

    content_type 'text/xml' 
    twiml.text 
    end 

end 

は私のルートは、私が不適切にこれをルーティングてる印象の下だ

Rails.application.routes.draw do 
    resources :posts 
    resources :phones 
    resources :users 
    root 'home#index' 

    post "/reply/hart1" => "reply#hart1" 

end 

です。ヘロクのコンソールも私に500エラーを与えるので、私はそれが私の最後に固定可能であることを知っている。それはtwillo-ルビー 'の

require 'twilio-ruby' 
class ReplyController < ApplicationController 
    skip_before_action :verify_authenticity_token 

    def hart1 
    send_text_message 
    content_type 'text/xml' 
    end 

    private 

    def send_text_message 
    # put your own credentials here 
    account_sid = 'ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' 
    auth_token = 'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy' 

    # set up a client to talk to the Twilio REST API 
    @client = Twilio::REST::Client.new account_sid, auth_token 

    # Send SMS message 
    @client.api.account.messages.create(
    from: '+FROMNUMBER', 
    to: '+TONUMBER', 
    body: 'The Robots are coming! Head for the hills!' 
    ) 
    end 
end 

ドキュメントのようになります。コントローラのtwillio-Rubyのコードがあなたの中に、この

# put your own credentials here 
account_sid = 'ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' 
auth_token = 'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy' 

# set up a client to talk to the Twilio REST API 
@client = Twilio::REST::Client.new account_sid, auth_token 

# Send SMS message 
@client.api.account.messages.create(
    from: '+FROMNUMBER', 
    to: '+TONUMBER', 
    body: 'The Robots are coming! Head for the hills!' 
) 

ようになっているはずでメッセージを送信するために

+0

私はあまりよく分かりませんが、[THIS](https://www.twilio.com/docs/quickstart/ruby/sms/hello-monkey)のドキュメントでは、 'r.message(body : "ロボットが来て、丘の向こうに向かう!") ' – Abhi

+0

また、私は' r.Message'が 'r.message'(小文字)であるべきだと感じます[REF](https://www.twilio.com/ docs/guides/how-to-receive-and-in-ruby) – Abhi

+0

どのバージョンのRubyライブラリを使用していますか? – philnash

答えて

0

私はあなたが返信Twilioの言及ではなく、通常のテキストを送信する場所に記載されているルートnzajtを巻き取った。ルーティングはうまくいきました。すべてtwilioから私のサーバー上のポストルートに当たって、私は使用するためにペイロードから必要なすべてのパラメータを取ることができました。みんなありがとう。

関連する問題