Need help with integrating Twillio in a rails app made for making appointments. I am trying to integrate twilio to send appointment reminders.
I have two models User & Appointment.
class User < ActiveRecord::Base
attr_accessible :email, :password, :password_confirmation, :remember_me, :provider, :uid, :name,
has_many :appointments, dependent: :destroy
end
class Appointment < ActiveRecord::Base
attr_accessible :discription, :appointment_time, :reserve_time, :reserve_date
belongs_to :usermodel
end
and now there is the appointment reminder from Twillio which i want to integerate: https://github.com/twilio/twilio-ruby
The documentation works with controller only and it is ambiguous, Do i need to create a new model and have relationship with User or Appointment model?
Really need some help, please
2
Answers
I would recommend creating the Twillio client in an initializer and setting it to a global variable:
config/initializers/twillio
Now you can interact with the twillio client using
$twillio
wherever you need to. For example if you what to send a text message when an appointment is created you could do something like this:If you want to schedule an appointment reminder text message consider using something like Sidekiq to queue a worker that will perform the action at the time you want. Using sidekiq your create appointment action would then look something like this:
Then in your
TextReminderWorker
you would send the text.Ricky from Twilio here.
We put together a tutorial for appointment reminders using Ruby that could be helpful here:
https://www.twilio.com/docs/tutorials/walkthrough/appointment-reminders/ruby/rails
Here’s the code block in this tutorial where we’re sending the reminder:
For scheduling the reminder, we’re using Delayed::Job with the ActiveRecord adapter.