I'm able to send SMS this way, but weird thing, it only sends to one user, even if I have 3 users.
def send_daily_sms(user)
@user = user
# put your own credentials here
account_sid = 'AC2556499574e7111844811bff28e73061'
auth_token = '0593dd8cc063cfbe704bc73a8f83fbba'
# set up a client to talk to the Twilio REST API
@client = Twilio::REST::Client.new account_sid, auth_token
@client.account.messages.create({
:from => '+14234350632',
:to => '+' + @user.phone,
:body => 'SMS journalier',
})
end
task :email_sender_daily => :environment do |_, args|
User.find_each do |user|
user.send_daily_sms(user) if user.daily_sms == true && user.phone.present?
end
end
So I decided to use the gem Textris to see if using this would work.
class UserTexter < Textris::Base
default from: "Our Team <+14234350632>"
def send_daily_sms(user)
@user = user
phone = "+" + @user.phone
puts phone
text :to => phone
end
end
+41798352547
rake aborted!
Twilio::REST::RequestError: The 'To' number 41798352547 is not a valid phone number.
But as you can see, the number printed in the log is right, and I was doing quite the same when I was using the method in User.rb (it was sending SMS then, but only to one user).
Don't know what to do.