rohan
rohan

Reputation: 85

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."
)

Upvotes: 7

Views: 1468

Answers (3)

Ben
Ben

Reputation: 30474

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.

Upvotes: 2

Asif Alam
Asif Alam

Reputation: 69

should be:

client.api.account.messages.create

Upvotes: 0

S. Alekseenko
S. Alekseenko

Reputation: 109

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."
)

Upvotes: 6

Related Questions