0

I am trying to add twilio to my rails app using the twilio gem and I am having issues. I first followed this tutorial https://www.twilio.com/docs/tutorials/walkthrough/appointment-reminders/ruby/rails#14 and did it in a separate app which works. However, when I moved it over to my main app its not working. I am not sure if it is because I don't have a specific route for twillio or what. Basically, I have an rsvp button on my site to rsvp to an event and I was hoping when the button is clicked it sends a text. Therefore, I put the code in the RSVP model. I am using delayed_jobs and when the button is clicked it is added to the delayed job queue. However, nothing is actually sent. Is there a way to look at logs for twilio? The code for the rsvp model is bellow. Thanks so much!!

require 'twilio-ruby'
class Rsvp < ApplicationRecord
belongs_to :user
belongs_to :event
validates :user_id, :uniqueness => { :scope => :event_id}

 after_create :reminder
    #
    #
  # @@REMINDER_TIME = 30.minutes # minutes before appointment
    #
  # def when_to_run
  #   time - @@REMINDER_TIME
  # end


  # Notify our appointment attendee X minutes before the appointment time
  def reminder
    @twilio_number = '+18888888888'
    @client = Twilio::REST::Client.new ENV['TWILLIO_ACCOUNT'], ENV['TWILLIO_SECRET']
    time_str = ((self.time).localtime).strftime("%I:%M%p on %b. %d, %Y")
     reminder = "Hi #{self.event_id}. Just a reminder that you have an Event coming up in 30 minutes at #{time_str}."
     message = @client.account.messages.create(
       :from => @twilio_number,
       :to => '+18888888888',
       :body => reminder,
     )
     puts message.to
   end

    handle_asynchronously :reminder, :run_at => Proc.new { 1.minutes.from_now}

end
aharonhillel
  • 49
  • 1
  • 9
  • First try to see the delayed_job task for that and see the last error on that task, to see if the task is failing or the problem is with twilio – xploshioOn Apr 22 '17 at 16:46
  • @xploshioOn Hi! thanks for the quick response. dealyed_jobs isn't showing an error when I look at the queue. I set a time as shown above (1 minute for now) and it is in the queue. When the time comes it is gone. So it seems to go off. I'm wondering if its a problem related to having it in RSVP model without its own controller/route. Not sure if thats necessary – aharonhillel Apr 22 '17 at 16:49
  • Are you trying with a real phone number? – xploshioOn Apr 22 '17 at 16:54
  • Yes, same exact code as in the working test rails app – aharonhillel Apr 22 '17 at 17:00
  • 1
    I fixed it thanks to rake jobs:work. Highly suggest it since it showed the error. There was a variable that it couldnt find that I was calling that threw an error. Thanks! – aharonhillel Apr 22 '17 at 18:02

0 Answers0