Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

tools-for-instagram

Package Overview
Dependencies
Maintainers
1
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tools-for-instagram

Tools for instagram

  • 1.8.12
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
55
increased by816.67%
Maintainers
1
Weekly downloads
 
Created
Source

Tools-for-Instagram

Telegram Chat paypal Snyk Vulnerabilities for npm package NPM npm

Automation scripts for Instagram

  • With AI and Avoid Bans Example codes
  • Cross framework support: TFI can run their own tools or other tools like instabot

View changes

How to use it

Easy way:

1. npm install tools-for-instagram
2. create a .env file on the main directory with this fields:
IG_USERNAME=myUsername
IG_PASSWORD=myPassword

# Uncomment next line if you want to be in offline chat status
# ONLINE_MODE=false
# Uncomment next line to use a proxy
# IG_PROXY=http://proxyuser:proxypassword@xxx.xxx.xxx.xxx:xxxxx
# Uncomment next line to use email verifications | sms by default
# IG_VERIFICATION=email
3. Copy the example.js on the root folder of your project from the repo
4. Execute'node example.js' to test the scripts.
Following steps:
1. Write your automation bots or copy the existent ones inside Tools-for-Instagram module 
(Recommended to create a 'bots' folder in root of the project)
2. Tests the bot using 'node bots/yourBot.js'

Git way:

1. Download the repo and install dependencies using this terminal commands:
    git clone https://github.com/linkfy/Tools-for-Instagram.git
    cd Tools-for-Instagram
    npm install
2. Rename .env_example to .env and edit the configuration.
3. Execute 'node example.js' to test the scripts.
Following steps:
1. Write your automation bots inside bots folder or use the existent ones
2. Tests the bot using 'node bots/bot.js'
Npm install errors on Windows?:

Download this - Replace the node_modules folder (1.8.0) on Windows

Npm install errors on Linux?:

Download this - Replace the node_modules folder (1.8.2) on Linux

Bot skills:

  • Login Flow
  • SMS/Email verification modes
  • Save Cookies in files
  • Remove Cookies
  • Session Regeneration
  • Get User Information
  • Get User Recent Posts
  • Get recent post Likers / By Username
  • Get Followers of account (save into a json file)
  • Get Followings of account (save into a json file)
  • Get my Last followers / Detect new Followers
  • Read Following/Followers files generated and return Array.
  • Like Content by URL
  • Like Content by MediaId
  • Like Content by Post
  • Follow by Username
  • Follow by Id
  • Follow User by Post
  • Unfollow by Id
  • Unfollow by Username
  • View stories by User Id
  • View stories by Username
  • Get polls from stories
  • Vote poll from story
  • Get recent posts list of a hashtag
  • Get top posts list of a hashtag
  • Get recent post list by location
  • Get top post list by location
  • Save post list into scrape list
  • Implement lowdb Database
  • Save Likes information
  • Save Follows information
  • Save Unfollows information
  • Get Like activity
  • Get Follow activity
  • Get Unfollow activity
  • Current Time In Range Validator [ex: from 8:00 to 23:00]
  • Proxies
  • Multi-login
  • Multi-proxy per login
  • Like Recent Hashtags By Intervals
  • Follow Recent Hashtags By Intervals
  • Simple Bots Folder
  • NPM package support
  • View Stories from User Id/Ids
  • View Stories from User Followers
  • View Stories from User Following
  • Live Streaming
  • Comment Media by Id
  • Get Comments On Post by Id
  • Get Media information by Id
  • Upload Pictures
  • Get Media Type (photo, video, album...)
  • Get Photo/Video Url
  • Get Ibox/Pending Messages
  • Approve/Decline Pending Messages
  • Reply Messages / Send Stories
  • Detect Faces / Gender / Age Avg.
  • Anti Ban Mode (Better with mobile proxies)
  • Cookie validator/regenerator on Login
  • "It was Me message" validator checker
  • Low consumption proxies examples
  • Create Workers/Bosses threads
  • Cross Framework Support
  • Cross Framework Instabot example
  • Online Simulation
  • CLI Alpha under construction
  • Postprocessing of scrape list (detect faces, language, business accounts)

Wiki

https://github.com/linkfy/Tools-for-Instagram/wiki

Telegram group

https://t.me/toolsforinstagram

Follow the project

You can follow the streams of the project on the Twitch channel
https://www.twitch.tv/mimi_twitchbot

Follow the development status

Follow the development status to see what's the next upcoming idea
https://trello.com/b/ZlwRr6l0/tools-for-instagram

Api mods

  • Injected loggedInUser inside ig Object after login (ig.loggedInUser)
  • Injected db inside ig Object after login (ig.db)
  • Injected shortid generator inside ig Object
  • Injected realtime modules on login

Api

Basic example

Using npm package
require("tools-for-instagram");

(async () => {

    let ig = await login();

    // .. Implement your code here
    let info = await getUserInfo(ig, "Instagram");
    console.log("User information, username: " + info.username);
    
    // ..
})();
Using Git repo:
require('./src/tools-for-instagram');

(async () => {
    let ig = await login();
    
    // .. Implement your code here
    let info = await getUserInfo(ig, "Instagram");
    console.log("User information, username: " + info.username);
    
    // ..

})();
loadConfig(loginFileName)

Load a config file from the accounts folder

By default it will use the proxy from .env file if the proxy is not set on login().

    let acc = loadConfig('exampleAccount');
    let myAccount2 = await login(acc);
    //same as await login("username", "password");

To avoid the default proxy from the .env file use false as inputProxy parameter on login file.

module.exports = {
    inputLogin: 'accountName',
    inputPassword: 'password',
    inputProxy: false,
}
setAntiBanMode(ig)

Currently Antiban is for likes/follow/unfollow. WARNING: Antiban IS NOT MAGIC, if you use simple code/examples Like_Easy or Like_With_Scanner (Super simple codes) it is possible to be banned anyway. A good Example is Like_Avoid_Bans, use it with caution.

    let ig = await login();
    await setAntiBanMode(ig);

Also it is possible to disable it:

    let ig = await login();
    await setAntiBanMode(ig, false);
getUserInfo(ig, username)

Get the user information of the desired username

   let info = await getUserInfo(ig, 'Instagram');
getRecentPostLikers(ig, post);

Get the last likers (max of 1000) of a post

    let posts = await getUserRecentPosts(ig, username);
    let likers = await getRecentPostLikers(ig, posts[0]);
getRecentPostLikersByUsername(ig, username)

Get the last likers (max of 1000) of the last post of the desired username

let likers = await getRecentPostLikersByUsername(ig,'instagram');
//Show the last liker of the array
console.log(likers[likers.length-1]);
getFollowers(ig, username)

It will save the followers inside the outputfolder with the format "acountName_followers.json"

   await getFollowers(ig, 'Instagram');

getMyLastFollowers(ig)

Get your last 100 followers, and save it to database, when some follower is new you will a is_new_follower attirbute

   let followers = await getMyLastFollowers(ig);
   console.log(followers[0].is_new_follower);
getFollowing(ig, username)

It will save the following inside the outputfolder with the format "acountName_following.json"

   await getFollowing(ig, 'Instagram');
readFollowers(ig, username)

It will return the followers inside the outputfolder with the format "acountName_followers.json"

   let followers = await readFollowers(ig, 'Instagram');
readFollowing(ig, username)

It will return the following inside the outputfolder with the format "acountName_following.json"

   let followers = await readFollowing(ig, 'Instagram');
likeUrl(ig, username, [force: bool])

like the desired instagram Url, the like will be saved inside database.

   await likeUrl(ig, 'https://www.instagram.com/p/B1gzzVpA462/');

If 'force' is set to true, when the item was already liked before it will force to continue the operation.

   await likeUrl(ig, 'https://www.instagram.com/p/B1gzzVpA462/', true);
viewStoriesFromUser(ig, username)

View all the current stories of the given username

   await viewStoriesFromUser(ig, 'instagram');
getPollsFromStories(ig, username)

Get Stories that currently have polls

    let user = await getUserInfo(ig, "its.crystinx");
    let stories = await getStoriesFromId(ig, user.id);
    let polls = await getPollsFromStories(ig, stories);
voteStoryPoll(ig, username, value = 1)

Vote a poll, the value can be 0 or 1 (left or right)

    let stories = await getStoriesFromId(ig, 18839378120);
    let polls = await getPollsFromStories(ig, stories);
    
    for(p in polls) {
        await voteStoryPoll(ig, polls[p]);//By default the value is always 1 if we don't set it
    }
    
isTimeInRange(startTime, endTime)

Returns True or False if the current time is inside the range

   await isTimeInRange("10:00", "23:00");

It is also possible to calculate night ranges between the current day and tomorrow.

   await isTimeInRange("23:00", "3:00");
likeRecentHashtagsByIntervals(ig, hashtagArray, intervals, likesPerInterval, waitMinutesBetweenLikes)

Automate like actions on given array of recent hashtags feed

    let likesPerInterval = 15;
    let waitMinutesBetweenLikes = 3;

    let intervals = [
        ["7:00",    "8:00"],
        ["10:00",   "11:00"],
        ["22:00",   "23:00"],
    ];
    let hashtagArray = [
        "cats",
        "dogs",
        "music"
    ];

   let likeInterval = likeRecentHashtagsByIntervals(
                                                    ig,
                                                    hashtagArray, 
                                                    intervals, 
                                                    likesPerInterval,
                                                    waitMinutesBetweenLikes);

It is also possible to stop the interval clearing it

   clearInterval(likeInterval);
uploadPicture(ig, caption, picturePath, namesToTag = [])

Upload a picture from computer to Instagram account

const path = require('path');
let myPicturePath = path.join(__dirname, '/images');
await uploadPicture(ig, "My picture", myPicturePath);
uploadAlbum(ig, caption, album, namesToTag = [])

This example is not tested yet, if anyone can verify, please send a message to Issues section: Set tagged accounts to it

const path = require('path');
let myPicture = path.join(__dirname, '/images/image.jpg');
let album = [];
album.push(myPicture);
await uploadAlbum(ig, "My picture", "caption", album, namesToTag = ['linkfytester', 'instagram']);
uploadPictureByUrl(ig, caption, pictureUrl)

let pictureUrl = "https://i.ytimg.com/vi/w6-1O0WCdGM/maxresdefault.jpg";
let caption = "This is a test image that I'll delete in a few seconds";
let image = await uploadPictureByUrl(ig, caption, pictureUrl);
commentMediaId(ig, mediaId, commentContent)

Post a comment on the desired post giving the media Id

 let posts = await recentHashtagList(ig, "dogs");
 await commentMediaId(ig, posts[0].pk, "Amazing!");
commentPost(ig, post, comment)
    let posts = await recentHashtagList(ig, "dogs");
    await commentPost(ig, posts[0], "Lovely!");
getPostCommentsById(ig, id)

By default you will get 20 comments:

    let posts = await topHashtagList(ig, "dogs");
    //Each post have a pk (private key) that is used as Id.
    let comments = await getPostCommentsById(ig, posts[0].pk);
    comments.forEach(comment => {
        console.log(comment.text);
    });

You can specify a max for the comments:

    let posts = await topHashtagList(ig, "dogs");
    //Get 100 comments
    let comments = await getPostCommentsById(ig, posts[0].pk, 100);
    comments.forEach(comment => {
        console.log(comment.text);
    });
replyDirectMessage(ig, {userId:id}, message)

Send message by user id

    let user = await getUserInfo(ig, "Instagram");
    let sendDm = await replyDirectMessage(ig,{ userId : user.pk }, "yay!");
replyDirectMessage(ig, {threadId:id}, message)

Send message by Inbox thread Id

    let inbox = await getInbox(ig);
    let sendDm = await replyDirectMessage(ig,{ threadId : inbox[0].threadId }, "yay!");
replyDirectMessage(ig, {userId, story})

Send Story as a Message to userId or ThreadId

    let ig = await login();
    let instagram = await getUserInfo(ig, 'instagram');
    let stories = await getStoriesFromId(ig, instagram.id);
    let linkfy = await getUserInfo(ig, 'linkfytester');
    //Share normal message
    await replyDirectMessage(ig, {userId: linkfy.id}, 'I will send you a story');
    //Share story test
    await replyDirectMessage(ig, {userId: linkfy.id, story:stories[0]});

Undocumented methods:

recentHashtagList(ig, hashtag)
topHashtagList(ig, hashtag)
likeMediaId(ig, pk)
likePost(ig, post)
recentLocationList(ig, location, [randomize: bool])
topLocationList(ig, location, [randomize: bool])
savePosts(ig, posts, filename)
followUser(ig, username)
followById(ig, userId)
followUserByPost(ig, post)
getLikeActivityByHours(ig, startingHour)
getFollowActivityByHours(ig, startingHour)
getUnfollowActivityByHours(ig, startingHour)
getLikeActivityFromHourToNow(ig, "12:05")
lastLikeMinutesAgo(ig)
removeCookie(ig)
followRecentHashtagsByIntervals(ig, hashtagArray, intervals, followsPerInterval, waitMinutesBetweenFollows)
viewStoriesFromId(ig, userId)
getStoriesFromId(ig, userId);
viewStoriesFromFollowing(ig, username)
viewStoriesFromFollowers(ig, username)
getUserRecentPosts(ig, username)
requestLivestream(ig)
getMediaIdInfo(ig, mediaId)
getMediaUrlInfo(ig, url)
getMediaType(ig, mediaIdOrUrl)
getPhotoUrl(ig, mediaIdOrUrl)
getVideoUrl(ig, mediaIdOrUrl)
getInbox(ig)
getInboxPending(ig)
approveInboxPending(ig, id)
declineInboxPending(ig, id)
unfollowUser(ig, accountName)
unfollowById(ig, id)
regenerateSession(ig)
executeAntiBanChecks(ig)

Scrapper / Spider

Login is not required for the next functions

spider.getUserInfo(username)

Get the basic information of some user, also the last posts

(async () => {

    let info = await spider.getUserInfo("linkfytester");
    console.log(info);
})();
spider.userHasStories(username)

Get true or false if the user has stories

(async () => {

    let info = await spider.userHasStories("linkfytester");
    console.log(info);
})();
spider.getUserLikers(username, maxUsers)

Get user likers of some post, it is useful when trying to scrap more than 10k users

(async () => {

    let users = await spider.getUserLikers("linkfytester");
    console.log(info);
})();
(async () => {

    let users = await spider.getUserLikers("linkfytester", maxUsers=50);
    console.log(info);
})();

Advanced Stuff

Using Bosses and Workers

We will be able to use "workers". Multiple executions of bots that work as "threads" and report the execution to a Boss or Controller. Example Uses:

  1. Bot continue execution when one worker is not working
  2. Bot have a max time to resolve operations, (useful to know if a service is down)
  3. Bot can retry the worker code if it fails
  4. Bot can run code that is not from from the repo/or is another language like python or C++ and expect a result in a certain time
How to use properly
  • All workers must go inside the bots/workers folder
  • All bosses must go inside the bots/bosses folder
  • The accounts used by th workers must be declared inside the account folder as the example show (not all the fields are required)
  • Not all the workers will need an account, it depends on the code of your worker, maybe you use want to use a worker for Maths for example
Developing a worker and boss
  1. Copy the example worker from bots/workers and modify the code
  2. Copy the example boss from bots/bosses and edit the code, (a boss can work as a normal bot, but they are specially designed to manage workers)
  3. Use the executeWorker as the example shows to call workers sync/async as you preffer on the boss script, all parameters are optional except workerName
  4. Call the boss script from the root directory where the accounts are located (thats important, it will try to load the accounts from there), example below
node bots/bosses/exampleBoss
Advanced workers, execution of script bots as a worker subroutine

There is also possible to execute advanced workers with the function executeAdvancedWorker, instead of sending an 'accountLogin' parameter, use the 'variables' parameter to send all the related parameters and information to the bot.

For example the advanced boss scriptLoaderBoss.js sends an script name to the scriptLoader.js worker.

    let worker1 =  executeAdvancedWorker({
        workerName: 'scriptLoader',
        variables: {scriptName: 'Message_New_Followers'},
        timeout: Infinity  // Set to Infinity to avoid Timeout seconds on subroutines
    });

The advanced worker read the variables like that:

module.exports = function (variables, callback) {
    (async () => {
        console.log(variables.scriptName +'.js')
        ///...

Recursive intervals (setInterval) are only executed once when normal scripts are called from a worker, so consider to set the intervals inside the worker code and not inside the script code. In this example (scriptLoader.js) you can see how Message_New_Followers is only executed once for that reason.

Using CLI for development

The CLI is currently under construction so it will change constantly

Installing

Inside the root folder on git / the node_modules folder on npm

cd cli
npm link
cd ..

Well done! Now you can use tfi on your current session

Using tfi

Use tfi from the root working folder to see expected results.

Get the current available commands:

tfi help

Create a new bot:

tfi new bot

Create a new bot called myBot:

tfi new bot myBot

Execute an existing bot [Proxy is optional]:

tfi start -b bots/botname.js -u username -p password -y proxy 

When the cookie exists you can use it without password

tfi start -b bots/botname.js -u username
Thanks to Nerixyz, Dilame, Richard Hutta, Pasha Lev, valga, mgp25 and all the Tfi community researchers for doing an incredible work.

Keywords

FAQs

Package last updated on 11 Jan 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc