Search documentation of phoenix_kit

# PhoenixKit.Emails.SQSProcessor (phoenix_kit v1.6.19)

View Source

Processor for handling email events from AWS SQS messages.

This module is responsible for:

- Parsing SNS messages from SQS
- Processing different types of SES events
- Updating email statuses in the database
- Creating event records for tracking

## Supported Event Types

- Send - Email send confirmation through SES
- Delivery - Successful email delivery to recipient
- Bounce - Email bounce (hard/soft bounce)
- Complaint - Spam complaint
- Open - Email open (AWS SES tracking)
- Click - Link click in email

## Processing Architecture

    SQS Message → SNS Parsing → Event Processing → Database Update

## Security

- Message structure validation
- Event type checking
- Protection against event duplication
- Graceful handling of invalid data

## Examples

    # Parse SNS message
    {:ok, event_data} = SQSProcessor.parse_sns_message(sqs_message)

    # Process event
    {:ok, result} = SQSProcessor.process_email_event(event_data)

# Summary

## Functions

parse_sns_message(arg1)

Parses SNS message from SQS into event data structure.

process_email_event(event_data)

Processes email event and updates corresponding database records.

# Functions

# parse_sns_message(arg1)

Parses SNS message from SQS into event data structure.

## Parameters

- `sqs_message` - message from SQS queue

## Returns

- `{:ok, event_data}` - successfully parsed event data
- `{:error, reason}` - parsing error

## Examples

    iex> SQSProcessor.parse_sns_message(sqs_message)
    {:ok, %{
      "eventType" => "delivery",
      "mail" => %{"messageId" => "abc123"},
      "delivery" => %{"timestamp" => "2025-09-20T15:30:45.000Z"}
    }}

# process_email_event(event_data)

Processes email event and updates corresponding database records.

## Parameters

- `event_data` - event data from SNS

## Returns

- `{:ok, result}` - successful processing
- `{:error, reason}` - processing error

## Examples

    iex> SQSProcessor.process_email_event(event_data)
    {:ok, %{type: "delivery", log_id: 123, updated: true}}