Writing blog posts is hard work. Furthermore, writing threads to promote those articles is even harder. Its because a completely different writing style from blogging (punchy hooks, brevity) is required.
Therefore, I decided to automate this workflow using OpenAI (GPT-4o) and Twitter API . Here, I introduce how I built a script that analyzes my content and generates perfectly formatted threads.
The Problem: Just Post a Link and Pray Doesnt Work
Just posting a link to X (formerly Twitter) results in zero engagement. The algorithm gives the cold shoulder to posts with links. Its clear that threads that keep users on the platform perform better, but rewriting a 3, 000-character article into five tweets takes at least 30 minutes.
- Goal: Convert Markdown content → 5 impactful tweets.
- Tools: TypeScript,
twitter-api-v2, Vercel AI SDK.
The Script: post-to-x-thread.ts
I created a CLI script that takes a file path as input.
# Usage looks like this
npx tsx scripts/utils/post-to-x-thread.ts --file src/content/blog/my-post.mdx --url https://...
The Viral Prompt
The secret sauce is in the prompt, not the code. I instructed the AI to follow specific constraints:
- Tweet 1 (Hook): Include a paradoxical opinion or a specific promise. Reporting I wrote a post is a no-go.
- Tweets 2-4 (Value): One idea per tweet.
- Last Tweet (CTA): Link to the full article.
const prompt = \`
You are a professional social media manager.
Please convert the following blog post content into a high-engagement Twitter/X thread.
Constraints: Each tweet must fit within 280 characters (standard length).
Structure: Hook -> Value -> Value -> CTA
\`;
Automatic Image Processing
A text-only thread is boring. I updated the script to automatically fetch the heroImage from the articles frontmatter, upload it to X, and attach it to the first tweet.
// Auto-upload hero image
const mediaId = await client.v1.uploadMedia(heroPath);
await client.v2.tweet("text, { media: { media_ids: ["mediaId"] } });
Deep Dive: JSON Schema for Thread Generation
Allowing AI to output in a “free format” leads to parsing failures. The pro technique is to fix the structure using the Vercel AI SDK’s object mode.
const threadSchema = z.object({
tweets: z.array(z.object({
content: z.string().max(140),
hashtags: z.array(z.string())
})).length(5)
});
This ensures you always receive an “array containing exactly 5 tweets,” so the automated posting system never crashes.
Results
Now I can generate thread drafts in seconds. I added a --dryRun flag, so I can check the AI output before actually posting. 90% of the work is done; all that’s left is to refine the hooks and hit the send button.
This script is also integrated into my Chrome extension “HonoGear Extension.” You can trigger this workflow directly from your browser!



![Complete Guide to What You Can Do with Discord Bots [Latest 2026]](/images/discord-bot-guide-2026.jpg)


⚠️ コメントのルール
※違反コメントはAIおよび管理者により予告なく削除されます
まだコメントがありません。最初のコメントを投稿しましょう!