class TwilioController < ApplicationController
  skip_before_action :verify_authenticity_token

rescue_from StandardError do |exception|
  trigger_sms_alerts(exception)
end

# Figure out how to add plant.nickname into msg
def trigger_sms_alerts (exception)
     alert_message = <<MSG
  [This is a test] ALERT!
  Time to water your plant!
  Exception: #{exception}.
  Go to: https://plantia.herokuapp.com/ for more details."
  MSG
end

def send_text(phone_number, alert_message)
    twilio_number = ENV['TWILIO_NUMBER']
    client = Twilio::REST::Client.new ENV['TWILIO_ACCOUNT_SID'], ENV['TWILIO_AUTH_TOKEN']

    client.messages.create(
      from: twilio_number,
      to:   phone_number,
      body: alert_message,
    )
  end

class TwilioController < ApplicationController
  skip_before_action :verify_authenticity_token

def send_text(phone_number, alert_message)
    twilio_number = ENV['TWILIO_NUMBER']
    client = Twilio::REST::Client.new ENV['TWILIO_ACCOUNT_SID'], ENV['TWILIO_AUTH_TOKEN']
    phone_number = User.phone_number
    # Trying to call on the specific plant belongs to the user that needs to be watered.
    plant = Plant.id.where(Plant.user_id == User_id)
    # Trying to include plant nickname and commonname in sms
    alert_message = <<MSG
                    [This is a test] ALERT!
                    Time to water your plant!
                    #{plant_nickname} #{plant_common_name}
                    Go to: https://plantia.herokuapp.com/ for more details."
                    MSG

    client.messages.create(
      from: twilio_number,
      to:   phone_number,
      body: alert_message,
    )
  end

# @message = @client.messages.create(
#       from: twilio_number,
#       to:   phone_number,
#       body: alert_message,
#       )
# end
Add functions to Twilio controller
Add functions to Twilio controller

Add more specific call function to send texts. Refractor code to one function from two.
Add twillio account information and new variables for calling on user phone number and plant ids.
