Skip to content

Conversation

@BhaveshKukreja29
Copy link
Collaborator

Description

Closes #126

This PR introduces the POST /create-newsletter endpoint, which allows authenticated users to schedule recurring newsletters. The implementation includes plan-based limits and sends a sample newsletter to whitelisted users upon creation.

The /user endpoint has also been updated to return newsletter usage stats.

Checklist

  • I have created an issue for this change (not mandatory for small changes)
  • My changes are to-the-point
  • Code is styled as the rest of the codebase and linting passes
  • I have tested my changes locally and they work as expected
  • I have updated the documentation (if needed)
  • I have reviewed the code myself once and I don't see any issues

Additional Notes

Changes by File

  • mxgo/api.py:

    • Added the new /create-newsletter endpoint.
    • It checks user plan limits for the max number of newsletters and minimum schedule interval.
    • Updated the /user endpoint to include newsletter_usage in the response.
  • mxgo/config.py:

    • Added NEWSLETTER_LIMITS_BY_PLAN to define the limits.
  • mxgo/schemas.py:

    • Added CreateNewsletterRequest and CreateNewsletterResponse for the new endpoint.
    • Introduced ScheduleOptions to accept a user-friendly schedule (e.g., weekly on specific days) instead of a raw cron string.
  • mxgo/utils.py:

    • Added convert_schedule_to_cron_list to convert the new ScheduleOptions into one or more cron expressions.
    • Moved and updated calculate_cron_interval to validate schedule frequency against plan limits.
  • tests/test_api.py:

    • Added a new test suite for /create-newsletter.
    • Tests cover the success path, plan limit enforcement, and whitelist logic.

Request Response Structure

Request: POST /create-newsletter

{
  "prompt": "Weekly summary of AI advancements",
  "schedule": {
    "type": "RECURRING_WEEKLY",
    "recurring_weekly": {
      "days": ["friday"],
      "time": "09:00"
    }
  }
}

Success Response (200 OK):

{
  "is_scheduled": true,
  "is_whitelisted": true,
  "sample_email_sent": true,
  "scheduled_task_ids": [
    "c4a6b2e8-6e7b-4a1d-8c3e-0f1d5e2a3b4c"
  ]
}

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Dec 17, 2025

Deploying mxtoai-backend with  Cloudflare Pages  Cloudflare Pages

Latest commit: 40fdc5b
Status: ✅  Deploy successful!
Preview URL: https://c5c84f25.mxtoai-backend.pages.dev
Branch Preview URL: https://bk-news-endpoint.mxtoai-backend.pages.dev

View logs

@satwikkansal
Copy link
Collaborator

There's a merge conflict with main branch, let's resolve that as well

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 11 changed files in this pull request and generated 9 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@satwikkansal satwikkansal merged commit ff34241 into master Dec 24, 2025
7 checks passed
@BhaveshKukreja29 BhaveshKukreja29 deleted the bk_news_endpoint branch January 12, 2026 05:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dedicated Custom Newsletter API endpoint

3 participants