DEV Community

Subhendu Das
Subhendu Das

Posted on

AI Content Generation for Developer Marketing

Problem

Indie developers and small teams often ship code but struggle to document it. Writing consistent blog posts or social copy requires time that many already lack. The result is missed visibility and a fragmented promotion strategy.

How It Works

Herald solves this by turning repository activity into publishable content automatically. When a commit lands that changes a readme, a new feature flag is added, or a release tag is pushed, a GitHub webhook triggers a FastAPI endpoint. The request payload is parsed and stored in PostgreSQL via SQLAlchemy. A Celery worker picks up the trigger record, calls an AI model (OpenAI GPT‑4) to draft a markdown article, and stores the draft.

The front‑end, built with React and Vite, presents a content calendar where developers can review drafts, edit them, and schedule publication. Tailwind CSS keeps the UI concise and responsive.

Drafting Pipeline

# tasks.py
from celery import shared_task
from openai import OpenAI
from app.models import Trigger, Draft

@shared_task
def generate_draft(trigger_id: int):
    trigger = Trigger.get(trigger_id)
    prompt = f"Write a 700‑word blog post about the change: {trigger.summary}." 
    response = OpenAI().chat.completions.create(
        model="gpt-4",
        messages=[{"role": "system", "content": "You are a senior dev‑blogger."},
                  {"role": "user", "content": prompt}],
        temperature=0.7,
    )
    Draft.create(trigger_id=trigger_id, content=response.choices[0].message.content)
Enter fullscreen mode Exit fullscreen mode

The worker writes the draft to the database; the React UI fetches it via a FastAPI endpoint:

# api.py
@router.get("/drafts/{draft_id}")
async def get_draft(draft_id: int, db: Session = Depends(get_db)):
    return Draft.get(draft_id)
Enter fullscreen mode Exit fullscreen mode

Publishing Pipeline

When a draft is approved and scheduled, Celery schedules a publish task. The task uses the dev.to API to create the article.

# publish.py
import requests

DEVTO_TOKEN = os.getenv("DEVTO_TOKEN")

@shared_task
def publish_to_devto(draft_id: int, scheduled_at: datetime):
    draft = Draft.get(draft_id)
    if datetime.utcnow() < scheduled_at:
        # Reschedule until the time arrives
        publish_to_devto.apply_async((draft_id, scheduled_at), eta=scheduled_at)
        return
    headers = {"api-key": DEVTO_TOKEN, "Content-Type": "application/json"}
    data = {
        "article": {
            "title": draft.title,
            "description": draft.summary,
            "body_markdown": draft.content,
            "published": True,
            "tags": ["devops", "automation", "ai"],
        }
    }
    resp = requests.post("https://dev.to/api/articles", json=data, headers=headers)
    resp.raise_for_status()
    # Store the dev.to URL for later metrics
    draft.update(devto_url=resp.json()["url"])
Enter fullscreen mode Exit fullscreen mode

-Berkeley the task is idempotent; if the API call fails, Celery retries up to 3 times.

Using the Feature

  1. цию GitHub webhook** – Add the Herald endpoint to your repository’s webhook settings.
  2. Approve drafts – In the dashboard, read the AI‑generated markdown, tweak if necessary.
  3. Schedule – Pick a date/time; the calendar shows a 7‑day queue. The worker will publish automatically.
  4. Track engagement – After publication, Herald polls the dev.to API every 12 hours to pull the read count and.patterns. The dashboard visualises engagement per post.

The process requires no manual copy‑pasting; the entire workflow runs in the background.

Technical Highlights

  • FastAPI handles async HTTP requests with low latency, enabling real‑time webhook handling.
  • SQLAlchemy models map triggers, drafts, and posts to PostgreSQL tables. A single transient table holds unprocessed triggers, removed by a sweep job.
  • Celery + Redis orchestrates background tasks. Workers limit concurrency to 4 to avoid hitting OpenAI or dev.to rate limits.
  • React + Vite + Tailwind CSS deliver a lightweight UI; the calendar uses react-big-calendar for drag‑and‑drop scheduling.
  • Continuous testing reaches 100 % coverage; a recent commit raised the floor to 99.9 % and introduced a hard limit on the project list query.

Performance Optimizations

Recent changes addressed bottlenecks:

  • The transient table now reads in full via a single query, eliminating the unbounded loop that previously inflated latency.
  • The all my triggers endpoint was refactored to paginate results, reducing the 20‑fold memory spike.
  • A hard limit on project queries prevents accidental overload.
  • Unit tests no longer pay bcrypt 2,300 times; a mock replaces the password hash during testing.

These adjustments keep the system responsive even when a repository receives dozens of commits per day.

Summary

Herald’s AI‑powered drafting and publishing engine eliminates the friction between code commits and marketing content. By leveraging FastAPI, Celery, and the dev.to API, developers can ship code and let the platform turn each change into a polished, scheduled blog post or social snippet. The result is continuous, automated developer marketing without a dedicated marketing team.

Top comments (0)