Sha256: 034c158ed28f3a80d66eace48f2f135cdf566436ffd05c462bd90390cc0c3367

Contents?: true

Size: 947 Bytes

Versions: 2

Compression:

Stored size: 947 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',
          'email.delivered_delayed' => 'failed',
          'email.bounced' => 'failed',
          'email.complained' => 'failed'
        }.freeze

        def call(payload:)
          payload.stringify_keys!
          message_uuid = payload.dig('data', 'email_id')
          status = DELIVERABILITY_MAPPER[payload['type']]
          return [] if message_uuid.nil? || status.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

2 entries across 2 versions & 1 rubygems

Version Path
emailbutler-0.8.4 lib/emailbutler/webhooks/mappers/resend.rb
emailbutler-0.8.3 lib/emailbutler/webhooks/mappers/resend.rb