Sha256: 03268bad06bea8ee45abb7fb2a4b5a6f85a07c4de462607cf212b8b6124b84de

Contents?: true

Size: 834 Bytes

Versions: 4

Compression:

Stored size: 834 Bytes

Contents

# frozen_string_literal: true

module Emailbutler
  module Webhooks
    module Mappers
      class Resend
        DELIVERABILITY_MAPPER = {
          'email.sent' => 'processed',
          'email.delivered' => 'delivered',
          'email.opened' => 'delivered',
          'email.clicked' => 'delivered'
        }.freeze

        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
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
emailbutler-0.8.8 lib/emailbutler/webhooks/mappers/resend.rb
emailbutler-0.8.7 lib/emailbutler/webhooks/mappers/resend.rb
emailbutler-0.8.6 lib/emailbutler/webhooks/mappers/resend.rb
emailbutler-0.8.5 lib/emailbutler/webhooks/mappers/resend.rb