3

Following the tutorial for Twilio Client. Got stuck here where you do the testing https://www.twilio.com/docs/quickstart/ruby/client/incoming-calls

curl -X POST http://localhost:3000/voice

I keep getting the WEBrick::HTTPStatus::LengthRequired response.

When I put it as

curl -X POST http://localhost:3000/voice -d ''

It works. But how do I fix for this in my routes or controller?

routes.rb

post 'voice', to: 'calls#voice', as: :voice

controller

def voice
    response = Twilio::TwiML::Response.new do |r|
    # Should be your Twilio Number or a verified Caller ID
        r.Dial :callerId => '+16479316790' do |d|
            d.Client 'jenny'
        end
    end
    render :text => response.text
end

Thanks! Also, if you have done this previously... having trouble adding localhost:3000 as the callback url in the dashboard. Any suggestions?

Mohamed El Mahallawy
  • 13,024
  • 13
  • 52
  • 84

1 Answers1

1

The voice URL does not need to be a POST request, it can be a GET request. In the App dashboard, you can change the type of the voice request URL to GET and then modify your routes.rb to use get.

Using 'localhost' as the domain will not work as want a URL to point to your webserver. What you instead want is the full URL to your web server which you can accomplish with something like ngrok.

Megan Speir
  • 3,745
  • 1
  • 15
  • 25
Kunal
  • 11
  • 1