Class: Emailbutler::Webhooks::Mappers::Smtp2Go

Inherits:
Object
  • Object
show all
Defined in:
lib/emailbutler/webhooks/mappers/smtp2go.rb

Constant Summary collapse

DELIVERABILITY_MAPPER =
{
  'processed' => 'processed',
  'delivered' => 'delivered',
  'open' => 'delivered',
  'click' => 'delivered'
}.freeze

Instance Method Summary collapse

Instance Method Details

#call(payload:) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/emailbutler/webhooks/mappers/smtp2go.rb', line 14

def call(payload:)
  payload.stringify_keys!
  # message-id contains data like <uuid>
  message_uuid = payload['message-id'][1..-2]
  status = DELIVERABILITY_MAPPER[payload['event']] || Emailbutler::Message::FAILED
  return [] if message_uuid.nil?

  [
    {
      message_uuid: message_uuid,
      status: status,
      timestamp: payload['sendtime'] ? Time.at(payload['sendtime'].to_i).utc.to_datetime : nil
    }
  ]
end