In rails 4.2.4, I am using gem 'twilio-ruby'
to send SMS. Right now I am calling this twilio method for particular action, eg: send otp message & it is working fine. But the issue is same message will send when I am calling other actions.
In development.rb
config.middleware.use Rack::TwilioWebhookAuthentication, Rails.application.secrets.twilio_auth_token, '/voice'
In user model,
def send_otp_notification
begin
client = Twilio::REST::Client.new Rails.application.secrets.twilio_account_sid, Rails.application.secrets.twilio_auth_token
message = client.messages.create :from=> '+12015598867', :to=>"+#{self.mobile_number}", :body=> "Verify your otp: #{self.otp}"
rescue Twilio::REST::RequestError => e
puts "e = #{e}".red
end
end
In mobile/api/user.rb,
user = User.new(params[:user])
user.save
user.send_otp_notification
Here, send_otp_notification
method will call only once when user registers, right now when a user creates any other object(eg: create 'posts' table entry) then also otp message will send, how can I avoid this?
Aucun commentaire:
Enregistrer un commentaire