MT-22401: Add email campaigns API - #27
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughChangesThe client now exposes an initialized Email campaigns
Estimated code review effort: 4 (Complex) | ~45 minutes Mergeability Score: ⚪ Minimal · up to The PR adds a localized public example and API surface; no actionable merge-blocking risk remains beyond normal checks and review. Possibly related PRs
Suggested reviewers: Sequence Diagram(s)sequenceDiagram
participant Application
participant EmailCampaignsService
participant MailtrapAPI
Application->>EmailCampaignsService: Create or update campaign
EmailCampaignsService->>MailtrapAPI: Send campaign request
MailtrapAPI-->>EmailCampaignsService: Return campaign data
Application->>EmailCampaignsService: Schedule, start, or retrieve statistics
EmailCampaignsService->>MailtrapAPI: Send action or stats request
MailtrapAPI-->>Application: Return typed campaign or statistics
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 4
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@email_campaigns_test.go`:
- Around line 137-141: Update the template assertions in the test to fail
immediately when c.Template is nil before dereferencing it. Keep the existing
field validation for non-nil templates, and ensure the BodyText assertion runs
only after the template has been safely validated.
In `@email_campaigns.go`:
- Around line 178-182: Update ContactListIDs and ContactSegmentIDs to use a
presence-aware representation so nil means unchanged while an explicitly empty
slice serializes and clears the full audience; preserve JSON field names and
existing non-empty behavior.
In `@examples/email-campaigns/main.go`:
- Around line 23-29: Update the campaign configuration around the fixed
contact-list IDs and the mailtrap.EmailCampaignReplyTo value to read
account-specific audience and reply-to settings from environment variables,
including replacing hardcoded IDs 55 and 56. Ensure ReplyTo is omitted when its
configuration is unset, and avoid using the unrelated hardcoded acme.com domain.
- Line 56: Update the scheduling call in the EmailCampaigns example to build the
timestamp at runtime using a future UTC time instead of the fixed date literal.
Ensure the generated value is reliably in the future when passed to Schedule.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: f7b6d101-c955-45e3-bcb3-7c2bdb5f5017
📒 Files selected for processing (5)
README.mdclient.goemail_campaigns.goemail_campaigns_test.goexamples/email-campaigns/main.go
|
Addressed the CodeRabbit review findings in c769077:
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
email_campaigns_test.go (1)
226-239: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick winAdd symmetric coverage for segment clearing.
This test proves that
ContactListIDs: &[]int64{}serializes as[]and that a nilContactSegmentIDsis omitted. It does not prove thatContactSegmentIDs: &[]int64{}also serializes as[]. Add a matching test or subtest for the segment field.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@email_campaigns_test.go` around lines 226 - 239, Extend TestEmailCampaigns_UpdateClearAudience with a matching case for ContactSegmentIDs: use an explicitly empty slice, assert the PATCH body contains {"contact_segment_ids": []}, and keep ContactListIDs nil so it remains omitted. Reuse the existing client update flow and handler pattern to verify symmetric clearing behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@email_campaigns_test.go`:
- Around line 226-239: Extend TestEmailCampaigns_UpdateClearAudience with a
matching case for ContactSegmentIDs: use an explicitly empty slice, assert the
PATCH body contains {"contact_segment_ids": []}, and keep ContactListIDs nil so
it remains omitted. Reuse the existing client update flow and handler pattern to
verify symmetric clearing behavior.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 0c5730c9-d5dc-40f9-a55c-052d5f172347
📒 Files selected for processing (3)
email_campaigns.goemail_campaigns_test.goexamples/email-campaigns/main.go
🚧 Files skipped from review as they are similar to previous changes (2)
- examples/email-campaigns/main.go
- email_campaigns.go
Decisions:
- Request bodies are flat (no email_campaign wrapper) per the current API contract
- Single-object and stats responses unwrap {data: ...} via local anonymous wrapper structs (webhooks.go precedent)
- Delete returns (*Response, error) since the API responds 204 No Content
- Lifecycle endpoints (start/schedule/cancel/terminate/reset) share a private action helper with a body param for schedule
- List returns a public page struct with *int prev/next tokens plus an All iter.Seq2 iterator (email_logs.go precedent)
Decisions: - Audience fields on UpdateEmailCampaignRequest become *[]int64 (tri-state): nil is omitted so partial updates stay partial, while a pointer to an empty slice serializes as [] to clear the full audience set, matching the API's "treated as the full set" semantics - Example reads the contact list ID from MAILTRAP_CONTACT_LIST_ID (repo env-var convention), drops the hardcoded acme.com ReplyTo, and derives the schedule time at runtime (now + 24h UTC) - Get test fails fast on nil Template instead of dereferencing it
c769077 to
ddac44d
Compare
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
Decisions: - Rename EmailCampaignsPagination to Pagination; nothing in it is campaign-specific - Move it beside Response in client.go, where shared response plumbing lives
Decisions: - The backend allows deleting only a campaign in the draft state (EmailCampaign#validate_soft_delete), not merely a non-sending one - Examples deleted a campaign after start/terminate, which would 422; a started campaign can never return to draft, so they now delete a fresh draft
Motivation
MT-22401
Port the Email Campaigns public API (MT-21113) to the Go SDK.
Changes
EmailCampaignsServicecovering the full contract: list (page-token pagination +searchfilter, plus anAlliterator), get, create, update, delete (204), the five lifecycle actions (Start,Schedule,Cancel,Terminate,Reset), andStatswith an optional date rangedata-envelope unwrapping,domain_idas int64 (matching Sending Domains ids), 10-value state consts, audience id lists, templatebody_html/body_text/merge_tagsexamples/email-campaigns/main.go+ README "Email marketing" sectionHow to test
examples/email-campaigns/main.gowith a real API token and a verified sending domain — create a draft, update design/audience, schedule + cancel, fetch stats, deleteAllwalks past page 1 on an account with >50 campaigns)Summary by CodeRabbit
New Features
Documentation