Instagram Automation with n8n and Playwright

A powerful, Instagram automation toolkit that leverages n8n workflows and Playwright for profile analysis, personalized messaging, and screenshot capture.

๐Ÿš€ Overview

This tutorial will guide you through setting up a powerful Instagram automation system using n8n workflows and Playwright browser automation. With this system, you can automate profile analysis, send personalized messages, and capture screenshots without writing a single line of code.

๐Ÿ” Profile Analysis

Automatically analyze Instagram profiles using AI to understand content themes, visual style, and audience engagement.

๐Ÿ’ฌ Personalized Messaging

Generate and send targeted messages based on profile content and user interests.

๐Ÿ“ธ Screenshot Capture

Take automated screenshots of profiles for further visual analysis and record-keeping.

๐ŸŒ Cross-Platform

Works seamlessly on Linux, macOS, and Windows with Docker.

๐Ÿ“‹ Prerequisites

Before you begin, make sure you have the following:

Note: This tutorial assumes you already have Docker set up with the necessary containers:

  • playwright-api (port 3333)
  • n8n (port 5678)
  • postgres (port 5432)
  • Additional services like redis, caddy, etc.

๐Ÿ”ง Installation and Setup

Step 1: Clone the Repository

First, clone the GitHub repository to get all the necessary files:

git clone https://github.com/wangdangel/insta_n8n.git
cd insta_n8n

Step 2: Set Up the Environment

The project includes setup scripts for both Linux/macOS and Windows:

For Linux/macOS:

chmod +x setup.sh
./setup.sh

For Windows:

Double-click setup.bat or run it from Command Prompt.

These scripts will:

Important: If you prefer manual setup, refer to the README.md file for detailed step-by-step instructions.

Step 3: Access n8n

Once the setup is complete, you can access n8n through your browser:

http://localhost:5678

You'll be prompted to create an account or log in if you already have one.

Step 4: Import Workflows

In the n8n interface:

  1. Click on "Workflows" in the left sidebar
  2. Click the "Import from File" button
  3. Select either basic_working_instagram_msg.json or instgram_v2 (working).json file
  4. Click "Import"

Tip: The instgram_v2 (working).json is the enhanced version with AI-powered profile analysis and personalized messaging capabilities.

๐Ÿ” Understanding the Workflow Components

The main workflow (instgram_v2 (working).json) consists of several interconnected components that handle different aspects of the automation:

1. Profile Finding

2. Profile Analysis

3. Visual Content Analysis

4. Message Generation

5. Message Delivery

Note: The workflow uses several AI models powered by Google Gemini. You'll need to configure these components with your own API key.

โš™๏ธ Configuration

Instagram Credentials

In both workflow files, you need to update the Instagram credentials node with your account information:

  1. Open the workflow in n8n
  2. Double-click on the "Instagram Credentials" node
  3. Replace YOUR_EMAIL@YOUR_PROVIDER.COM with your Instagram email
  4. Replace YOUR_PASSWORD with your Instagram password
  5. Click "Save"

Security Note: Your credentials are stored within n8n and are not transmitted outside your local environment. However, it's recommended to use a separate Instagram account for testing.

Google Gemini API Setup

To enable AI components, set up Google Gemini API integration:

  1. Go to Google AI Studio and create an API key
  2. In n8n, click on "Credentials" in the left sidebar
  3. Click "Create" and select "Google Gemini(PaLM) API"
  4. Enter your API key and save
  5. Update each Google Gemini node in the workflow to use your credentials

Tip: The free tier of Google Gemini API should be sufficient for testing and moderate usage.

๐Ÿš€ Running Your First Automation

Testing Basic Functionality

To test a simple workflow without AI components:

  1. Import the insta_n8n.json workflow
  2. Double-click the "Input Data" node and set parameters:
    • searchTerm: Instagram username you want to target
    • targetUsername: Same as above
    • message: The message you want to send
  3. Configure your Instagram credentials in the appropriate node
  4. Click "Execute Workflow" to run the test

Testing AI-Powered Analysis

For the complete AI-powered workflow:

  1. Import the instgram_v2 (working).json workflow
  2. Make sure all Google Gemini nodes are configured with your API key
  3. Update the Instagram credentials node with your account information
  4. Click "Execute Workflow"
  5. When prompted, enter a name or description of the Instagram account you're looking for

The workflow will:

  1. Find the appropriate Instagram account
  2. Take screenshots of the profile
  3. Analyze the visual content and themes
  4. Generate a personalized message
  5. Send the message via Instagram DM

Tip: Click on each node during execution to see its input and output data. This helps with troubleshooting and understanding the workflow.

๐Ÿ› ๏ธ Customizing the Workflow

Customizing AI Prompts

You can modify how the AI analyzes profiles and generates messages:

  1. Open the workflow in n8n
  2. Double-click on any AI Agent node (Username Agent, Viewing Agent, or Messaging Agent)
  3. Edit the "Text" field to change the prompt
  4. Click "Save" to apply changes

For example, in the Messaging Agent, you can adjust the prompt to emphasize different aspects of your product/service or change the messaging tone.

Adjusting Screenshot Settings

To modify how screenshots are captured:

  1. Find the "Screenshot Code" node
  2. Edit the code to change parameters such as:
    • numScreenshots: Number of screenshots to take (default: 3)
    • scrollPercent: How far to scroll between screenshots (default: 0.8)
    • waitTime: Milliseconds to wait between scrolls (default: 3000)

Adding New Features

The workflow is modular, so you can extend it with additional capabilities:

โš ๏ธ Instagram Guidelines and Limitations

Important Safety Considerations

When using automation with Instagram, be aware of the following:

  • Rate Limits: Instagram restricts the number of actions you can take per hour/day
  • Account Safety: Excessive automation can trigger temporary blocks or account restrictions
  • Message Limits: New accounts may be limited to 10-20 new conversations per day
  • Character Limits: Instagram messages have a 1,000 character limit

Best Practices

๐Ÿงน Cleanup and Maintenance

Stopping the Automation

When you're done using the automation, you can stop the Docker containers:

For Linux/macOS:

chmod +x cleanup.sh
./cleanup.sh

For Windows:

Double-click cleanup.bat or run it from Command Prompt.

Maintaining Your Setup

To keep your automation running smoothly:

๐Ÿ” Troubleshooting

Common Issues and Solutions

Issue Solution
Playwright installation fails Run manually in Docker:
docker exec -it playwright-api bash
cd /app
npm install
npx playwright install
npx playwright install-deps
n8n can't connect to Playwright Check if the API server is running:
docker logs playwright-api
Ensure the API is listening on port 3333.
Instagram security challenge If Instagram shows a security challenge, you'll need to manually log in to your account and complete the verification.
Line ending issues in Windows If you encounter errors related to line endings:
docker exec playwright-api bash -c "sed -i 's/\r$//' /app/*.js"

Need Help? If you encounter issues not covered here, check the GitHub repository issues or create a new one with detailed information about your problem.

๐Ÿค Support and Contribution

If you find this project helpful and would like to support its development:

Buy Me a Coffee

๐Ÿ“œ License

This project is licensed under the MIT License - see the LICENSE file for details.

Get Started with Instagram Automation

Take control of your Instagram outreach with this powerful, local-first automation solution.