Class: OTP::SMSJob

Inherits:
ActiveJob::Base
  • Object
show all
Defined in:
lib/otp/sms_job.rb

Overview

Uses the AWS SNS API to send the OTP SMS message.

Constant Summary collapse

TEMPLATE =

A generic template for the message body.

'%{otp} is your magic password 🗝️'
ENABLED =

Indicates if the messaging is disabled. Handy for testing purposes.

true

Instance Method Summary collapse

Instance Method Details

#perform(phone_number, otp_code, template = TEMPLATE) ⇒ Object

Sends the SMS message with the OTP code

Returns:

  • nil



19
20
21
22
23
24
25
26
# File 'lib/otp/sms_job.rb', line 19

def perform(phone_number, otp_code, template = TEMPLATE)
  message = template % { otp: otp_code }

  Aws::SNS::Client.new(region: ENV['AWS_SMS_REGION']).publish(
    message: message,
    phone_number: phone_number
  ) if ENABLED
end