Class: Emailbutler::Webhooks::Mappers::Resend

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

Constant Summary collapse

DELIVERABILITY_MAPPER =
{
  'email.sent' => 'processed',
  'email.delivered' => 'delivered',
  'email.opened' => 'delivered',
  'email.clicked' => '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
# File 'lib/emailbutler/webhooks/mappers/resend.rb', line 14

def call(payload:)
  payload.stringify_keys!
  message_uuid = payload.dig('data', 'email_id')
  status = DELIVERABILITY_MAPPER[payload['type']] || Emailbutler::Message::FAILED
  return [] if message_uuid.nil?

  [
    {
      message_uuid: message_uuid,
      status: status,
      timestamp: payload['created_at'] ? DateTime.parse(payload['created_at']).utc : nil
    }
  ]
end