class Stealth::Services::Smooch::MessageEvent

Attributes

params[R]
service_message[R]

Public Class Methods

new(service_message:, params:) click to toggle source
# File lib/stealth/services/smooch/events/message_event.rb, line 12
def initialize(service_message:, params:)
  @service_message = service_message
  @params = params
end

Public Instance Methods

process() click to toggle source
# File lib/stealth/services/smooch/events/message_event.rb, line 17
def process
  fetch_message
  fetch_location
  fetch_attachments
end

Private Instance Methods

fetch_attachments() click to toggle source
# File lib/stealth/services/smooch/events/message_event.rb, line 38
def fetch_attachments
  if params['type'] == 'image'
    service_message.attachments << {
      type: 'image',
      url: params['mediaUrl']
    }
  elsif params['type'] == 'file'
    service_message.attachments << {
      type: params['mediaType'],
      url: params['mediaUrl']
    }
  end
end
fetch_location() click to toggle source
# File lib/stealth/services/smooch/events/message_event.rb, line 29
def fetch_location
  if params['type'] == 'location'
    service_message.location = {
      lat: params['coordinates']['lat'],
      lng: params['coordinates']['lng']
    }
  end
end
fetch_message() click to toggle source
# File lib/stealth/services/smooch/events/message_event.rb, line 25
def fetch_message
  service_message.message = params['text']
end