Suggestion On social media automation

Hi everyone, I am building an AI-powered social media advertisement automation workflow using n8n (running locally through Docker), Python ML, OpenAI APIs, Google Sheets, Instagram, and Facebook APIs. I want feedback and suggestions regarding the architecture, best practices, and especially the ML + image generation part.

Workflow Summary

1. Daily Trigger

A Cron trigger in n8n runs every day at 12 PM.


2. ML Prediction Engine

The workflow accesses an Instagram engagement dataset stored in either:

  • Google Drive CSV

  • Airtable

A Python ML script then:

  • Cleans and preprocesses the dataset

  • Uses rolling engagement windows

    • Example:

      • Day 1 → May 1–30

      • Day 2 → May 2–31

  • Analyzes:

    • Likes

    • Comments

    • Shares

    • Saves

    • Reach

    • Engagement rates

The ML model predicts the best time to post an advertisement for the current day.

The predicted posting time is stored in a Google Sheet (Sheet1).


3. AI Advertisement Generation

After prediction:

  • An AI agent/LLM generates advertisement prompts

  • An image generation model creates the advertisement image

  • The generated image URL/path is stored in the same Google Sheet row along with the predicted posting time


4. Caption + Hashtag Generator

Another AI agent:

  • Generates multiple caption options

  • Generates hashtags

  • Performs trend-aware captioning/prompt engineering

The generated captions are stored in Google Sheets and one caption is manually selected.

The final selected caption + hashtags are saved in the same row.


5. Automated Posting System

At the predicted posting time:

  • The workflow reads the row from Google Sheets

  • Posts the advertisement automatically to:

    • Instagram

    • Facebook

Likely using:

  • Facebook Graph API

  • Instagram Graph API

Then:

  • IF nodes check whether posting succeeded or failed

  • Notifications are sent through:

    • Telegram

    • WhatsApp

    • Email


Current Stack

  • n8n (Docker local installation)

  • Python ML

  • Google Sheets

  • OpenAI API

  • Instagram/Facebook APIs

  • Possible Hugging Face image generation APIs


Questions

1. ML Integration in n8n

What is the best way to integrate the ML part into n8n?

Should I use:

  • Python Code node

  • Execute Command node

  • External FastAPI/Flask ML service

  • Dockerized ML microservice

Also, what would be the best ML approach for predicting optimal posting times from Instagram engagement data?


2. Free AI Image Generation

What are the best free or low-cost options for AI image generation inside n8n?

I am considering:

  • Hugging Face Inference API

  • Stable Diffusion

  • FLUX

  • Pollinations AI

  • Local ComfyUI / AUTOMATIC1111

I need something scalable and preferably free/self-hosted.


3. Instagram + Facebook Integration

What is the best way to connect n8n with Instagram and Facebook posting?

Should I directly use:

  • Facebook Graph API

  • HTTP Request nodes

  • Webhooks

  • Third-party schedulers

Also:

  • Do I need Instagram Business account only?

  • How does media publishing work for Instagram through Meta APIs?


4. Workflow Architecture

Is splitting the automation into separate workflows the correct approach?

Current architecture:

  1. ML prediction workflow

  2. Ad generation workflow

  3. Caption generation workflow

  4. Scheduled posting workflow

All connected through Google Sheets.

Would queues/databases be better than Google Sheets?


5. Human Approval Layer

What is the best way to manually approve/select one caption from multiple AI-generated captions?

Possible options:

  • Google Sheet manual selection

  • Telegram buttons

  • Custom webhook dashboard

Which is most practical in production?


6. Scaling + Reliability

Any recommendations for:

  • Error handling

  • Retry systems

  • Logging

  • Preventing duplicate posting

  • Managing API limits

  • Production deployment of n8n + ML

Would appreciate architecture suggestions, especially from people already using AI + n8n + Meta APIs together.

Don’t put the model itself in the n8n Code node unless it is tiny and has almost no dependencies. A small pandas transform can live in a Python task runner. Once you have model files, package versions, or retraining, a separate FastAPI container is easier to test and deploy. n8n can send features over HTTP and get back a predicted time. Execute Command ties the model too closely to the n8n container and gets annoying during upgrades.

Google Sheets is fine for the first version, but make the row behave like a job record. Give it a stable `content_id`, `model_version`, `status`, `approved_at`, `attempt_count`, and the final platform post ID. Move it through `Draft`, `Approved`, `Publishing`, then `Published` or `Failed`. Claim the row before calling a publish API. I have had 2 scheduled executions pick up the same due row before either one wrote the result back.

Split this into smaller workflows as you planned. One collects metrics and creates features. Another builds the asset and caption options. Approval should freeze the chosen caption and media URL. The publisher only reads approved rows that are due. Add a separate error workflow that stores the raw response and increments the attempt count. Retry a timeout or 5xx with backoff, but do not keep retrying a bad media file or missing permission.

For the timing model, start with a boring baseline by account, weekday, and hour before training anything clever. Validate on later dates, not a random split, or the rolling windows will leak future behavior into the test. Also pick one outcome. Likes, saves, and reach do not reward the same posting time.

Direct Meta APIs make sense if instagram and facebook are the whole scope and you want to own the integration. If more networks are likely, blotato’s official n8n node can take the approved caption, public media URL, and exact scheduled time while n8n keeps the ML and review logic. Write the returned post ID and final `published` or `failed` state back to the row.

For image generation, use one provider behind a small wrapper so you can swap it later. Local ComfyUI is cheap only if you already have the GPU and want to maintain it. Get one instagram image post through approval, publish, and writeback before turning on the daily trigger.

1 Like

Hi @Hammad_Ahmad1 Welcome!
For picking one caption, the Telegram node’s Send and Wait for Response operation with Response Type set to Custom Form does it in a single node: the generated captions go into a dropdown element, the execution pauses there, and it resumes with the chosen one in its output, so nothing downstream has to watch a Sheet cell. Set Limit Wait Time on it as well, or a missed approval leaves the execution parked past the posting slot you predicted.
The part that bites here is the local Docker install. Approve Within Chat needs your instance reachable from the internet over HTTPS on port 443, 80, 88 or 8443, and turning that option off only falls back to link buttons that still point at your instance, so a tunnel or reverse proxy with WEBHOOK_URL set has to be in place before the approval step works from a phone.

1 Like

So basically N8n will handle all data collection and Machine learning and Blotato will handle all Social media automation right?