Skip to content

Gtajisan/Instagram-FCA

Repository files navigation

Instagram-FCA v1.0.0

npm version License: MIT

The fastest and most powerful Node.js library for Instagram Private API - Unofficial Instagram Chat API designed for Goat Bot v2 integration.

Similar to Nexus-fCA but for Instagram!

Features

  • Dual Login Support - AppState (cookies) and username/password authentication
  • Safe & Stable - Session persistence, auto-reconnect, random user agents
  • Proxy Support - HTTP/HTTPS/SOCKS5 proxy for all connections
  • Full DM Support - Send/receive messages, photos, videos, links, reactions
  • User Operations - Follow, unfollow, block, search users
  • Media Operations - Like, comment, save posts and stories
  • Thread Management - Create groups, add/remove members, mute/unmute
  • Health Metrics - Monitor connection status and performance
  • TypeScript Support - Full type definitions included
  • Promise + Callback - Both patterns supported

Author

Installation

npm install instagram-fca

Quick Start

Option 1: AppState Login (Recommended)

const login = require('instagram-fca');

(async () => {
  const api = await login({ appState: require('./appstate.json') }, {
    autoReconnect: true,
    randomUserAgent: true
  });
  
  console.log('Logged in as', api.getCurrentUserID());
  
  api.listen((err, event) => {
    if (err) return console.error('Listen error:', err);
    if (event.body) {
      api.sendMessage('Echo: ' + event.body, event.threadID);
    }
  });
})();

Option 2: Username/Password Login

const login = require('instagram-fca');

(async () => {
  const api = await login({
    username: 'your_username',
    password: 'your_password'
  }, {
    autoReconnect: true,
    randomUserAgent: true
  });
  
  console.log('Logged in!');
  
  // Save appState for future logins
  api.saveAppState('./appstate.json');
  
  api.listen((err, msg) => {
    if (err) return console.error(err);
    if (msg.body === 'ping') {
      api.sendMessage('pong', msg.threadID);
    }
  });
})();

Option 3: With Proxy

const api = await login({ appState }, {
  proxy: 'socks5://127.0.0.1:1080',
  randomUserAgent: true,
  autoMarkRead: true
});

Configuration Options

Option Type Default Description
autoReconnect boolean true Auto reconnect on disconnect
randomUserAgent boolean true Use random user agent
userAgent string - Custom user agent
proxy string - Proxy URL (http/https/socks5)
autoMarkRead boolean false Auto mark messages as read
selfListen boolean false Listen to own messages
emitReady boolean true Emit ready event
listenTimeout number 60000 Listen timeout in ms
listenInterval number 3000 Polling interval in ms

API Methods

Messaging

// Send text message
await api.sendMessage('Hello!', threadID);

// Send photo
await api.sendPhoto('./image.jpg', threadID);

// Send video
await api.sendVideo('./video.mp4', threadID);

// Send link
await api.sendLink('https://example.com', threadID, 'Check this out!');

// Send like/heart
await api.sendLike(threadID);

// React to message
await api.reactMessage(threadID, messageID, '❤️');

// Delete/unsend message
await api.unsendMessage(threadID, messageID);

// Typing indicator
await api.sendTypingIndicator(threadID, true);

Thread Operations

// Get thread list
const { threads } = await api.getThreadList(20);

// Get thread info
const thread = await api.getThreadInfo(threadID);

// Create new thread
const result = await api.createThread(['user_id_1', 'user_id_2'], 'Hello!');

// Set thread name (groups)
await api.setThreadName(threadID, 'My Group');

// Add/remove users from group
await api.addUserToThread(threadID, userID);
await api.removeUserFromThread(threadID, userID);

// Mute/unmute thread
await api.muteThread(threadID);
await api.unmuteThread(threadID);

// Mark as read/unread
await api.markAsRead(threadID, messageID);
await api.markAsUnread(threadID);

// Leave thread
await api.leaveThread(threadID);

// Pending requests
const pending = await api.getPendingThreads();
await api.approvePendingThread(threadID);

User Operations

// Get user info
const user = await api.getUserInfo(userID);

// Search users
const users = await api.searchUser('username', 10);

// Follow/unfollow
await api.followUser(userID);
await api.unfollowUser(userID);

// Block/unblock
await api.blockUser(userID);
await api.unblockUser(userID);

// Get friendship status
const friendship = await api.getFriendship(userID);

// Get online presence
const presence = await api.getPresence();

Feed & Media Operations

// Get timeline
const timeline = await api.getTimeline(20);

// Get user feed
const feed = await api.getUserFeed(userID, 20);

// Get stories
const stories = await api.getStoryFeed();

// Like/unlike media
await api.likeMedia(mediaID);
await api.unlikeMedia(mediaID);

// Comment on media
const comment = await api.commentMedia(mediaID, 'Nice!');
await api.deleteComment(mediaID, commentID);

// Save/unsave media
await api.saveMedia(mediaID);
await api.unsaveMedia(mediaID);

Session & Metrics

// Get current user
const userID = api.getCurrentUserID();
const user = api.getCurrentUser();

// Get/save appState
const appState = api.getAppState();
api.saveAppState('./appstate.json');

// Health metrics
const health = api.getHealthMetrics();
console.log(health.status, health.uptime, health.ackCount);

// Memory metrics
const memory = api.getMemoryMetrics();

// Logout
await api.logout();

Events

api.on('ready', () => {
  console.log('Bot is ready!');
});

api.on('message', (event) => {
  console.log('New message:', event.body);
});

api.on('error', (error) => {
  console.error('Error:', error);
});

api.on('listen', () => {
  console.log('Started listening');
});

api.on('stop', () => {
  console.log('Stopped listening');
});

Message Event Object

{
  type: 'message',
  threadID: '123456789',
  messageID: '987654321',
  senderID: '111222333',
  body: 'Hello world!',
  timestamp: 1702500000000,
  isGroup: true,
  attachments: [],
  mentions: {}
}

Goat Bot v2 Integration

// In your Goat Bot v2 config
module.exports = {
  instagram: {
    appState: './instagram_appstate.json',
    options: {
      autoReconnect: true,
      randomUserAgent: true,
      listenInterval: 3000
    }
  }
};

How to Get AppState

  1. Login to Instagram on your browser
  2. Open Developer Tools (F12)
  3. Go to Application > Cookies
  4. Copy all cookies for instagram.com
  5. Format them as JSON array and save to appstate.json

Example appstate.json format:

[
  {
    "key": "sessionid",
    "value": "your_session_id",
    "domain": ".instagram.com",
    "path": "/",
    "secure": true,
    "httpOnly": true
  },
  {
    "key": "csrftoken",
    "value": "your_csrf_token",
    "domain": ".instagram.com",
    "path": "/"
  }
]

License

MIT License - see LICENSE for details.

Disclaimer

This is an unofficial library. Use at your own risk. Not affiliated with Instagram or Meta.

About

Instagram-FCA fork which adapted to work with GoatBot-V2 source made by NTKhang03

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published