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' => 'opened',
  'email.clicked' => 'opened'
}.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')
  message_uuid = message_uuid[1..-2] if message_uuid.starts_with?('<') && message_uuid.ends_with?('>')
  return [] if message_uuid.nil?

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