Class: NotificationServiceWorkers::Sms

Inherits:
ApplicationWorker show all
Defined in:
app/workers/notification_service_workers/sms.rb

Overview

Sms Worker to shorten URL in a message

Instance Method Summary collapse

Methods inherited from ApplicationWorker

unlimited_retry

Instance Method Details

#perform(msg, phones, opt) ⇒ Object

Example: “` msg = “hello %<url>s” url = “hungryhub.com” output = perform(msg, phones, url: url) # output => “hello https//:hungryhub.com “`

Parameters:

  • msg (String)
  • phones (Array)

    array of phone numbers

  • opt (Hash)

    if there is `url` key, then it will replace any url template on the `msg` param with the value of url key



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/workers/notification_service_workers/sms.rb', line 19

def perform(msg, phones, opt)
  options = opt.with_indifferent_access
  reservation_id = options.delete(:reservation_id)

  BUSINESS_LOGGER.set_business_context({ reservation_id: reservation_id }) if reservation_id.present?

  if Rails.env.development? || IS_STAGING_ENV
    BUSINESS_LOGGER.info('SMS skipped in development/staging environment. SMS details are logged below:',
                         reservation_id: reservation_id,
                         message: msg,
                         phone_numbers: phones,
                         options: opt)

    return
  end

  url = options.delete(:url)
  if url.present?
    url = MyUrlShortener.by_url(url)
    msg = format(CGI.unescapeHTML(msg), url: url)
  else
    msg.gsub!('%<url>s', '')
  end

  SmsWorker.perform_async(msg.strip, phones, reservation_id)
end