Receiving RequestError when using the twilio-ruby gem

I am try to use the twilio-ruby gem, but got a Twilio::REST::RequestError. What does this mean? Here's the code I'm using:

Controller

Class UserController < ApplicationController

    def new
        @user = User.new
    end

    def createUser
        @user = User.new(user_params)
        if @user.save
            render text: "Thank you! You will receive sms notification"

            account_sid = '*****' 
            auth_token = '*****'

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

            #@client = Twilio::REST::Client.new account_sid, auth_token
            #client = Twilio::REST::Client.new(TWILIO_CONFIG['sid'], TWILIO_CONFIG['token'])
            # Create and send an SMS message

            @client.account.messages.create
            ({
                :from => '+127*****',
                :to => @user.phone,
                :body => "Hello"    
            })


        else
            render 'new'
        end
    end


    private

    def user_params
        params.require(:user).permit(:name, :email, :phone)
    end

end

Why is this generating an error?

Answers


A RequestError means that we couldn't send the SMS message. It may mean you don't have international permissions to send to the number in question, or you are trying to use a Caller ID for a phone number that you don't own, or you're trying to send to a landline, or any number of problems.

Here is an example of how to catch a RequestError and view the attached error message.

require 'twilio-ruby'

begin
    client = Twilio::REST::Client.new account_sid, auth_token
    client.account.sms.messages.create(
      from => from_number,
      to =>   to_number,
      body => "Hello World"
    )
rescue Twilio::REST::RequestError => e
    puts e.message
end

Need Your Help

Change child text color different from parent text color?

css wordpress

I have a navbar that drops down. The parent text is black, when you hover over the parent text it drops down and shows other categories. The text for the categories is also white, is it possible to

How do I upload to an imgur user's account

c# oauth imgur

I am able to upload anonymous images to imgur using the api like this: