Daily post with Cloudflare Workers and AI SDK – fluent-wp-client
0 Stars
View on GitHub
A Cloudflare Cron Trigger that generates and publishes a post every morning using the Vercel AI SDK. fluent-wp-client uses only web-standard APIs, so it runs in the Workers runtime without any extra configuration.
[triggers]crons = ["0 8 * * *"]import { WordPressClient } from 'fluent-wp-client';import { generateText } from 'ai';import { openai } from '@ai-sdk/openai';
interface Env { WP_URL: string; WP_USER: string; WP_APP_PASSWORD: string; OPENAI_API_KEY: string;}
export default { async scheduled(_event: ScheduledEvent, env: Env) { const wp = new WordPressClient({ baseUrl: env.WP_URL, auth: { username: env.WP_USER, password: env.WP_APP_PASSWORD }, });
const today = new Date().toLocaleDateString('en-US', { weekday: 'long', month: 'long', day: 'numeric', });
const { text } = await generateText({ model: openai('gpt-4o-mini'), prompt: `Write a short web development tip for ${today}. Use clear HTML for paragraphs and headings.`, });
await wp.content('posts').create({ title: `Daily tip — ${today}`, content: text, status: 'publish', }); },};