Quick overview
This workflow accepts a webhook request with a drama topic, genre, tone, and size constraints, uses Python-based genre classification plus OpenAI GPT‑4.1 to generate a full script as structured JSON, then returns the script to the caller and appends a summary log entry to Google Sheets.
How it works
- Receives a POST webhook request containing the script topic, genre, tone, language, act count, and character count.
- Normalizes inputs by applying defaults, clamping acts to 1–5 and characters to 2–8, and adding request metadata like a request ID and timestamp.
- Classifies the genre in Python and prepares genre-specific guidance used to shape the script structure, then filters out requests marked as invalid.
- Sends the prepared parameters and genre guidance to OpenAI (GPT‑4.1) to generate a complete drama script as a single JSON object.
- Parses and validates the AI response as JSON, falls back to a safe wrapper if parsing fails, and enriches the result with counts for acts, scenes, and characters.
- Waits briefly and then returns the structured script to the webhook caller while also appending a summary row to a Google Sheets tab for tracking.
Setup
- Configure the Webhook trigger URL in the system that will send requests, and ensure it can reach your n8n instance publicly if needed.
- Add an OpenAI API credential in n8n and attach it to the GPT‑4.1 chat model node.
- Add a Google Sheets OAuth2 credential in n8n for the Google Sheets API.
- Replace
YOUR_SHEET_ID in the Google Sheets HTTP request URL and create a ScriptLog sheet tab with the expected columns (date, requestId, title, genre, tone, topic, acts, scenes, characters, status, generatedAt).