n8n OpenAI-powered Tweet Generator Workflow
Overview
🤖 n8n OpenAI-powered Tweet Generator
This n8n OpenAI-powered Tweet Generator workflow automates the generation of tweets using OpenAI’s language models. It picks a random hashtag from a predefined list and then generates a tweet that incorporates that hashtag, finally storing the generated content in Airtable. This setup is ideal for social media managers, marketers, content creators, or anyone looking to automate and streamline their tweet drafting process.
🔧 Workflow Steps:
- On clicking ‘execute’: This node serves as a manual trigger, initiating the workflow when executed, making it easy to run on demand.
- FunctionItem: This node contains a simple JavaScript function that randomly selects a hashtag from a pre-defined array (e.g., #techtwitter, #n8n). The selected hashtag is then passed on to the next node.
- HTTP Request: This node makes a POST request to the OpenAI API (specifically the text-davinci-001 engine). It sends a prompt to generate a tweet under 100 characters, incorporating the hashtag chosen by the ‘FunctionItem’ node.
- Set: This node extracts and formats the necessary data from the OpenAI response. It specifically pulls the generated tweet content and the hashtag, preparing them as key-value pairs for subsequent storage.
- Airtable: The final step in the workflow, this node appends the generated tweet content and its associated hashtag into a specified table within your Airtable base. This allows for easy archiving, review, and management of all generated tweets.
📌 Use Cases:
- Automating the creation of daily or weekly social media updates.
- Generating a continuous stream of tweet ideas for marketing campaigns.
- Maintaining an organized archive of all AI-generated content in a structured database like Airtable.
- Providing creative content inspiration for social media managers facing writer’s block.
🧰 Required Credentials:
- OpenAI API Key: Needed for the ‘HTTP Request’ node to interact with OpenAI’s language models.
- Airtable API Key: Required for the ‘Airtable’ node to append data to your Airtable base.
⚙️ Notes & Enhancements:
- Expand Hashtag List: Modify the ‘FunctionItem’ node to include a broader range of relevant hashtags to diversify tweet topics.
- Direct Social Media Posting: Integrate additional nodes (e.g., Twitter node) to directly post the generated tweets to your social media accounts after generation.
- Sentiment Analysis: Add a pre-posting step using a sentiment analysis node to ensure the generated tweet’s tone aligns with your brand’s voice.
- Scheduled Automation: Replace the ‘On clicking ‘execute” node with a ‘Cron’ or ‘Interval’ trigger to automatically generate tweets at predefined intervals without manual intervention.
- Tweet Length Control: Experiment with the ‘max_tokens’ parameter in the OpenAI HTTP Request to fine-tune the length of the generated tweets.
Workflow Editor Screenshot

Workflow JSON Code
{ "nodes": [ { "name": "On clicking 'execute'", "type": "n8n-nodes-base.manualTrigger", "position": [ 250, 300 ], "parameters": {}, "typeVersion": 1 }, { "name": "FunctionItem", "type": "n8n-nodes-base.functionItem", "position": [ 450, 300 ], "parameters": { "functionCode": "// hashtag list\nconst Hashtags = [\n \"#techtwitter\",\n \"#n8n\"\n];\n\n// random output function\nconst randomHashtag = Hashtags[Math.floor(Math.random() * Hashtags.length)];\nitem.hashtag = randomHashtag;\nreturn item;" }, "typeVersion": 1 }, { "name": "HTTP Request", "type": "n8n-nodes-base.httpRequest", "position": [ 650, 300 ], "parameters": { "url": "https://api.openai.com/v1/engines/text-davinci-001/completions", "options": {}, "requestMethod": "POST", "authentication": "headerAuth", "jsonParameters": true, "bodyParametersJson": "={\n \"prompt\": \"Generate a tweet, with under 100 characters, about and including the hashtag {{$node[\"FunctionItem\"].json[\"hashtag\"]}}:\",\n \"temperature\": 0.7,\n \"max_tokens\": 64,\n \"top_p\": 1,\n \"frequency_penalty\": 0,\n \"presence_penalty\": 0\n}" }, "credentials": { "httpHeaderAuth": "" }, "typeVersion": 1 }, { "name": "Airtable", "type": "n8n-nodes-base.airtable", "position": [ 1050, 300 ], "parameters": { "table": "main", "options": {}, "operation": "append", "application": "appOaG8kEA8FAABOr" }, "credentials": { "airtableApi": "" }, "typeVersion": 1 }, { "name": "Set", "type": "n8n-nodes-base.set", "position": [ 850, 300 ], "parameters": { "values": { "string": [ { "name": "Hashtag", "value": "={{$node[\"FunctionItem\"].json[\"hashtag\"]}}" }, { "name": "Content", "value": "={{$node[\"HTTP Request\"].json[\"choices\"][0][\"text\"]}}" } ] }, "options": {}, "keepOnlySet": true }, "typeVersion": 1 } ], "connections": { "Set": { "main": [ [ { "node": "Airtable", "type": "main", "index": 0 } ] ] }, "FunctionItem": { "main": [ [ { "node": "HTTP Request", "type": "main", "index": 0 } ] ] }, "HTTP Request": { "main": [ [ { "node": "Set", "type": "main", "index": 0 } ] ] }, "On clicking 'execute'": { "main": [ [ { "node": "FunctionItem", "type": "main", "index": 0 } ] ] } } }