> ## Documentation Index
> Fetch the complete documentation index at: https://docs.younegotiate.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Campaigns

> EcoMail Hub users schedule or immediately run email campaigns to creditor profile groups.

## Real-World Example

Maya selects the Pending Member Follow-Up template, chooses a group of pending creditor members, and schedules a weekly campaign. If the team needs the email to go now, she runs it immediately after confirming the group has matching profiles.

The portal should create campaign tracking and process profile emails in background jobs.

## Visual Flow

```mermaid placement="top-right" actions={true} theme={"system"}
flowchart TD
    A["User selects template and group"] --> B["Choose once, daily, weekly, or monthly"]
    B --> C{"Run immediately?"}
    C -->|No| D["Save future campaign schedule"]
    C -->|Yes| E["Confirm group size"]
    E --> F{"Profiles found?"}
    F -->|No| G["Block empty campaign"]
    F -->|Yes| H["Create tracker and queue delivery"]
    classDef default fill:#F8FAFC,stroke:#64748B,stroke-width:1.5px,color:#0F172A;
    classDef actor fill:#E0F2FE,stroke:#0284C7,stroke-width:2px,color:#0C4A6E;
    classDef system fill:#F8FAFC,stroke:#64748B,stroke-width:1.5px,color:#0F172A;
    classDef decision fill:#FEF3C7,stroke:#D97706,stroke-width:2px,color:#78350F;
    classDef risk fill:#FEE2E2,stroke:#DC2626,stroke-width:2px,color:#7F1D1D;
    classDef outcome fill:#DCFCE7,stroke:#16A34A,stroke-width:2px,color:#14532D;
    class A actor;
    class B,D,E,H system;
    class C,F decision;
    class G risk;
    linkStyle default stroke:#94A3B8,stroke-width:2px;
```

## Schedule Rules

* One-time campaigns can be scheduled for a future date.
* Daily, weekly, and monthly campaigns require an end date.
* Weekly campaigns require a day of week.
* Monthly campaigns require a day of month.
* Immediate campaigns create tracking and queue delivery right away.

## Campaign Actions

| Action                    | Expected Behavior                                                                                           |
| ------------------------- | ----------------------------------------------------------------------------------------------------------- |
| Create scheduled campaign | Saves a future once, daily, weekly, or monthly campaign.                                                    |
| Run immediately           | Confirms group size, creates a tracker, and queues delivery right away.                                     |
| Edit                      | Loads an owned campaign into the campaign form.                                                             |
| Delete                    | Deletes the campaign and its tracker/profile records inside a transaction.                                  |
| Re-run                    | Creates a new campaign copy only when the original campaign is eligible and still has a template and group. |

## How It Should Work

* It should require an existing template and group owned by the logged-in EcoMail Hub user.
* It should prevent campaigns to empty groups.
* It should allow re-running only when the campaign is eligible.
* It should queue campaign delivery instead of sending all emails from the form request.

## How It Should Not Work

* It should not send to creditor profiles outside the selected group criteria.
* It should not let users edit or delete another user's campaign.
* It should not allow a recurring campaign without the needed schedule details.

## Developer Notes

* The scheduled command `run:eco-mail-hub-campaigns` runs daily at 17:30.
* Delivery chunks creditor profiles in batches of 500 and then dispatches individual message jobs.
* Email sends attach EcoMail Hub tracking metadata for SendGrid callbacks.

## Related App Areas

* `app/Livewire/ConsumerResponseManager/Communications/Campaign/IndexPage.php`
* `app/Livewire/ConsumerResponseManager/Communications/Campaign/ListView.php`
* `app/Livewire/ConsumerResponseManager/Forms/Communications/EcoMailHubCampaignForm.php`
* `app/Console/Commands/RunEcoMailHubCampaignCommand.php`
* `app/Jobs/ProcessEcoMailHubCampaignCreditorProfilesJob.php`
* `app/Jobs/SendEcoMailHubCampaignEmailJob.php`
* `app/Jobs/SendSingleEcoMailHubCampaignMessageJob.php`
