Undefined account method for Twilio

I use twilio and get: error undefined `account 'method 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."
)
+4
source share
3 answers

You missed apiin the call chain. Try the following:

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."
)
+4
source

Recommend a review of Twilio documentation here:

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

There are some changes to the Ruby Helper Library 5.x. (Please note that the old version 4.x will only be supported until 10/15/17 - see Disclaimer).

Using 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?'
)

- v5.2.1.

+1

:

client.api.account.messages.create
0

Source: https://habr.com/ru/post/1683402/


All Articles