-
Notifications
You must be signed in to change notification settings - Fork 4
feat: Recoup Content Agent Slack bot #341
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: test
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| import type { NextRequest } from "next/server"; | ||
| import { after } from "next/server"; | ||
| import { contentAgentBot } from "@/lib/content-agent/bot"; | ||
| import { handleUrlVerification } from "@/lib/slack/handleUrlVerification"; | ||
| import "@/lib/content-agent/handlers/registerHandlers"; | ||
|
|
||
| /** | ||
| * GET /api/content-agent/[platform] | ||
| * | ||
| * Handles webhook verification handshakes for the content agent bot. | ||
| * | ||
| * @param request - The incoming verification request | ||
| * @param params - Route params containing the platform name | ||
| */ | ||
| export async function GET( | ||
| request: NextRequest, | ||
| { params }: { params: Promise<{ platform: string }> }, | ||
| ) { | ||
| const { platform } = await params; | ||
|
|
||
| const handler = contentAgentBot.webhooks[platform as keyof typeof contentAgentBot.webhooks]; | ||
|
|
||
| if (!handler) { | ||
| return new Response("Unknown platform", { status: 404 }); | ||
| } | ||
|
|
||
| return handler(request, { waitUntil: p => after(() => p) }); | ||
| } | ||
|
|
||
| /** | ||
| * POST /api/content-agent/[platform] | ||
| * | ||
| * Webhook endpoint for the content agent bot. | ||
| * Handles Slack webhooks via dynamic [platform] segment. | ||
| * | ||
| * @param request - The incoming webhook request | ||
| * @param params - Route params containing the platform name | ||
| */ | ||
| export async function POST( | ||
| request: NextRequest, | ||
| { params }: { params: Promise<{ platform: string }> }, | ||
| ) { | ||
| const { platform } = await params; | ||
|
|
||
| if (platform === "slack") { | ||
| const verification = await handleUrlVerification(request); | ||
| if (verification) return verification; | ||
| } | ||
|
|
||
| await contentAgentBot.initialize(); | ||
|
|
||
| const handler = contentAgentBot.webhooks[platform as keyof typeof contentAgentBot.webhooks]; | ||
|
|
||
| if (!handler) { | ||
| return new Response("Unknown platform", { status: 404 }); | ||
| } | ||
|
|
||
| return handler(request, { waitUntil: p => after(() => p) }); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import type { NextRequest } from "next/server"; | ||
| import { contentAgentBot } from "@/lib/content-agent/bot"; | ||
| import { handleContentAgentCallback } from "@/lib/content-agent/handleContentAgentCallback"; | ||
|
|
||
| /** | ||
| * POST /api/content-agent/callback | ||
| * | ||
| * Callback endpoint for the poll-content-run Trigger.dev task. | ||
| * Receives task results and posts them back to the Slack thread. | ||
| * | ||
| * @param request - The incoming callback request | ||
| */ | ||
| export async function POST(request: NextRequest) { | ||
| await contentAgentBot.initialize(); | ||
| return handleContentAgentCallback(request); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| import type { NextRequest } from "next/server"; | ||
| import { NextResponse } from "next/server"; | ||
| import { getCorsHeaders } from "@/lib/networking/getCorsHeaders"; | ||
| import { generateCampaignHandler } from "@/lib/launch/generateCampaignHandler"; | ||
|
|
||
| /** | ||
| * OPTIONS handler for CORS preflight requests. | ||
| * | ||
| * @returns Empty 200 response with CORS headers. | ||
| */ | ||
| export async function OPTIONS() { | ||
| return new NextResponse(null, { | ||
| status: 200, | ||
| headers: getCorsHeaders(), | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * POST /api/launch | ||
| * | ||
| * Streams an AI-generated music release campaign given artist and song details. | ||
| * Returns a text/plain stream with XML-style section markers that the client | ||
| * parses to render each campaign section in real-time. | ||
| * | ||
| * Authentication: x-api-key header OR Authorization: Bearer token required. | ||
| * | ||
| * Request body: | ||
| * - artist_name: string (required) — the artist's name | ||
| * - song_name: string (required) — the song or album name | ||
| * - genre: string (required) — musical genre | ||
| * - release_date: string (required) — release date (any format) | ||
| * - description: string (optional) — additional context for the AI | ||
| * | ||
| * Response: streaming text with section markers: | ||
| * [SECTION:press_release]...[/SECTION:press_release] | ||
| * [SECTION:spotify_pitch]...[/SECTION:spotify_pitch] | ||
| * [SECTION:instagram_captions]...[/SECTION:instagram_captions] | ||
| * [SECTION:tiktok_hooks]...[/SECTION:tiktok_hooks] | ||
| * [SECTION:fan_newsletter]...[/SECTION:fan_newsletter] | ||
| * [SECTION:curator_email]...[/SECTION:curator_email] | ||
| * | ||
| * @param request - The incoming request | ||
| * @returns Streaming text response or error | ||
| */ | ||
| export async function POST(request: NextRequest): Promise<Response> { | ||
| return generateCampaignHandler(request); | ||
| } | ||
|
|
||
| export const dynamic = "force-dynamic"; | ||
| export const fetchCache = "force-no-store"; | ||
| export const revalidate = 0; | ||
|
Comment on lines
+45
to
+51
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add endpoint tests before merge. This new API route needs coverage for success and failure paths (auth failures, invalid JSON/body validation errors, and successful stream response). As per coding guidelines: 🤖 Prompt for AI Agents |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion | 🟠 Major
Please add automated coverage for these webhook branches.
I don't see tests in this PR for the 404 path, Slack URL-verification short-circuit, or normal dispatch through
contentAgentBot.webhooks. This is internet-facing ingress, so relying on the manual Slack/Vercel checklist is pretty fragile.As per coding guidelines "Write tests for new API endpoints covering all success and error paths".
🤖 Prompt for AI Agents