id: ai-blog-post-generator
namespace: company.team
inputs:
- id: post_topic
type: STRING
displayName: Blog post topic
description: The topic or title idea for the new blog post to generate
- id: brand_url
type: STRING
displayName: Brand RSS feed URL
description: RSS feed URL for your existing blog articles (used to extract brand voice)
defaults: "https://yourblog.com/feed"
- id: target_audience
type: STRING
displayName: Target audience
description: Target audience for tone calibration (e.g., software engineers,
marketing managers)
defaults: "software engineers"
- id: cms_api_url
type: STRING
displayName: WordPress REST API base URL
description: WordPress REST API base URL (e.g., https://yourblog.com/wp-json/wp/v2)
defaults: "https://yourblog.com/wp-json/wp/v2"
tasks:
- id: fetch_reference_articles
type: io.kestra.plugin.core.http.Request
uri: "{{ inputs.brand_url }}"
method: GET
headers:
Accept: "application/rss+xml, application/xml, text/xml, application/json"
- id: extract_brand_voice
type: io.kestra.plugin.openai.ChatCompletion
apiKey: "{{ secret('OPENAI_API_KEY') }}"
model: gpt-4o
maxTokens: 800
jsonResponseSchema: |
{
"type": "object",
"properties": {
"tone": {"type": "string"},
"vocabulary": {"type": "string"},
"structure_pattern": {"type": "string"},
"example_opening": {"type": "string"},
"content_guidelines": {"type": "string"}
},
"required": ["tone", "vocabulary", "structure_pattern", "example_opening", "content_guidelines"]
}
messages:
- role: system
content: |
You are a brand voice analyst. Given sample blog content, extract the writing style and brand voice.
Analyze and return structured JSON with:
- tone: overall tone (e.g., "technical and direct", "conversational and encouraging")
- vocabulary: characteristic word choices, jargon level, formality
- structure_pattern: typical article structure (e.g., "problem → solution → example → CTA")
- example_opening: a sample opening sentence in this brand's style
- content_guidelines: key rules about what this brand does/avoids (bullet list as string)
- role: user
content: |
Analyze the brand voice from this blog content (first 3000 characters):
{{ outputs.fetch_reference_articles.body | truncate(3000) }}
- id: generate_blog_post
type: io.kestra.plugin.openai.ChatCompletion
apiKey: "{{ secret('OPENAI_API_KEY') }}"
model: gpt-4o
maxTokens: 2000
messages:
- role: system
content: |
You are an expert content writer. Write a complete, publication-ready blog post that perfectly
matches the provided brand voice profile. The post should be in Markdown format with:
- A compelling H1 title
- An engaging introduction (2-3 paragraphs)
- 3-4 H2 sections with substantive content
- A conclusion with a clear takeaway
Target audience: {{ inputs.target_audience }}
Write for this audience specifically, calibrate depth, examples, and terminology accordingly.
Match the brand voice exactly. Do not add meta-commentary about the writing.
- role: user
content: |
Brand voice profile:
{{ outputs.extract_brand_voice.choices[0].message.content }}
Topic to write about: {{ inputs.post_topic }}
Write the full blog post now.
- id: prepare_wp_payload
type: io.kestra.plugin.scripts.python.Script
dependencies:
- markdown2
inputFiles:
post_content.md: "{{ outputs.generate_blog_post.choices[0].message.content }}"
script: |
import json
import re
import markdown2
from kestra import Kestra
with open("post_content.md") as f:
md_content = f.read()
# Extract H1 title from markdown
title_match = re.search(r'^#\s+(.+)$', md_content, re.MULTILINE)
title = title_match.group(1).strip() if title_match else "{{ inputs.post_topic }}"
# Remove the H1 from content (WordPress uses title field separately)
body_md = re.sub(r'^#\s+.+\n', '', md_content, count=1).strip()
# Convert Markdown to HTML
html_content = markdown2.markdown(body_md, extras=["fenced-code-blocks", "tables", "header-ids"])
# Generate excerpt from first paragraph
first_para = re.search(r'<p>(.+?)</p>', html_content, re.DOTALL)
excerpt = re.sub(r'<[^>]+>', '', first_para.group(1))[:300] if first_para else ""
# Count words
word_count = len(md_content.split())
payload = {
"title": title,
"content": html_content,
"status": "draft",
"excerpt": excerpt
}
Kestra.outputs({
"payload": json.dumps(payload),
"title": title,
"word_count": word_count,
"excerpt": excerpt
})
- id: publish_to_cms
type: io.kestra.plugin.core.http.Request
uri: "{{ inputs.cms_api_url }}/posts"
method: POST
contentType: "application/json"
headers:
Authorization: "Basic {{ secret('WP_AUTH_TOKEN') }}"
body: "{{ outputs.prepare_wp_payload.vars.payload }}"
- id: notify_slack
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
url: "{{ secret('SLACK_WEBHOOK_URL') }}"
messageText: |
:pencil: *New Blog Draft Created*
*Topic:* {{ inputs.post_topic }}
*Title:* {{ outputs.prepare_wp_payload.vars.title }}
*Words:* {{ outputs.prepare_wp_payload.vars.word_count }}
*Status:* Draft saved to WordPress
*Audience:* {{ inputs.target_audience }}
_Review and publish at: {{ inputs.cms_api_url | replace('/wp-json/wp/v2', '/wp-admin/') }}_