Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

undefined method `account' for Twilio

I am using twilio and get: error undefined method `account' for Twilio.

    client = Twilio::REST::Client.new('twilio_sid','twilio_token')
    # Create and send an SMS message
    client.account.sms.messages.create(
    from: "+12345678901",
    to: user.contact,
    body: "Thanks for signing up. To verify your account, please reply HELLO to this message."
)
like image 209
rohan Avatar asked Aug 10 '17 08:08

rohan


2 Answers

You missed api in your chain of calls. Try this:

client.api.account.messages.create(
  from: "+12345678901",
  to: user.contact,
  body: "Thanks for signing up. To verify your account, please reply HELLO to 
  this message."
)
like image 56
S. Alekseenko Avatar answered Oct 24 '22 01:10

S. Alekseenko


Would recommend reviewing Twilio's documentation here:

https://www.twilio.com/docs/guides/how-to-send-sms-messages-in-ruby

There have been some changes with Ruby Helper Library 5.x. (Note that the old version 4.x will only be supported until 10/15/17 - see deprecation notice.)

With 5.x, SMS can be sent as follows:

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

@message = @client.messages.create(
  from: '+15017250604',
  to: '+15558675309',
  body: 'This is the ship that made the Kessel Run in fourteen parsecs?'
)

My use of this approach has worked so far with twilio-ruby gem v5.2.1.

like image 34
Ben Avatar answered Oct 24 '22 02:10

Ben