Skip to content

ejs, node.js, express, sequelize, postgres application to reply direct message using instagram-private-api

Notifications You must be signed in to change notification settings

iSeanWeiDev/instagram_direct_message_bot

Repository files navigation

version license GitHub issues open GitHub issues closed

Product Image

Introduction.

This is Instagram Direct message bot for IG marketing with real user account. Main functions had been built by Node.js. Codebase look like :

  1. Node.js (Back-end platform to integrate the npm modules)
  2. Express.js (Back-end framework to host the http server with http module.)
  3. Postgres (Main database to store all data and history from project.)
  4. Sequelize (Database management tools to excute the sql with NoSQL type of application)
  5. EJS (Front-end to disply the initialize data and validate all of event by using javascript.)

Core modules and functions.

Core modules:

  • Used npm modules like this:
    • "bcrypt-nodejs": "0.0.3",
    • "bluebird": "^3.5.4",
    • "body-parser": "^1.19.0",
    • "child_process": "^1.0.2",
    • "cookie-parser": "~1.4.4",
    • "debug": "~2.6.9",
    • "ejs": "^2.6.1",
    • "express": "~4.16.1",
    • "express-ejs-layouts": "^2.5.0",
    • "express-session": "^1.16.1",
    • "http-errors": "~1.6.3",
    • "instagram-private-api": "^0.10.1",
    • "jsonwebtoken": "^8.5.1",
    • "lodash": "^4.17.11",
    • "morgan": "~1.9.1",
    • "passport": "^0.4.0",
    • "passport-jwt": "^4.0.0",
    • "path": "^0.12.7",
    • "pg": "^7.11.0",
    • "pg-hstore": "^2.3.2",
    • "sequelize": "^5.8.6"

Main techniques:

  • Used thread function and related function based core functions:
    • Threading: child process fork function.

      Create bot by fork function:

      arrBotProcess.push(fork(path.join(__dirname, '[process].js')));
      arrBotProcessName.push(id);
      
      arrBotProcess[botNum].on('message', function(data) {
          if(data == 1) {
              // Validation part.
          }
      });
      
      arrBotProcess[botNum].send(sendData);

      Destroy bot by .kill() function:

      for(var i = 0; i < arrBotProcessName.length; i++) {    
          
          if(arrBotProcessName[i] == id) {
              arrBotProcess[i].kill(); // destroy bot by id
              arrBotProcessName[i] = "###";
          }
      }
      
      // loop for bot list and pop empty bot
      
      arrBotProcessBackup = [];
      arrBotProcessNameBackup = [];
      
      for(var kk = 0; kk < arrBotProcessName.length; kk++)
      {
          if(arrBotProcessName[kk] != "###")
          {
              arrBotProcessBackup.push(arrBotProcess[kk]);
              arrBotProcessNameBackup.push(arrBotProcessName[kk]);
          }                            
      }
      
      
      // initialize and copy original thread array for bots with backup arraylist
      
      arrBotProcess = [];
      arrBotProcessName = [];
      
      arrBotProcess = arrBotProcessBackup.slice(0);
      arrBotProcessName = arrBotProcessNameBackup.slice(0);
    • Promising: get data from instagram using instagram-private-api.

      Example for promise

      var feed = new Client.Feed.Inbox(session);
      
      var pFeed = new Promise(function(resolve) {
          return resolve(feed.get());
      });
      
      pFeed.then(function(results) {
          // manufactoring about results.
      });
    • Recursive function for sysncronization.

      Example for recursive fucntion.

      async function getNewInbox() {
          countResult--;
      
          // manufactoring for recursive.
      
          if(countResult > 0) {
              getNewInbox();
          }
      }
      getNewInbox();

Project structure.

Building express application.

    express my-new-express-app

Sequelize model structuring

Example of create model and migrate database.

    sequelize init

    sequelize model:create --name Bots --attributes name:string,filters:string,status:integer

    sequelize db:migrate

Project file structure.

.
├── bin
│   └── www
├── config
│   ├── config.json
│   └── env.js
├── controllers
│   ├── apiController.js
│   ├── boardController.js
│   ├── botController.js
│   ├── newBotProcess.js
│   └── userController.js
├── cookies
│   ├── gamer.wraps.json
│   └── super-sean.json
├── migrations
├── models
│   └── 20190530173910-create-user.js
├── node_modules
├── public
│   ├── app
│   │   ├── css
│   │   └── js
│   └── assets
│   │   ├── fonts
│   │   ├── images
│   │   ├── javascripts
│   │   └── stylesheets
├── routes
│   ├── api.js
│   ├── board.js
│   ├── bots.js
│   ├── index.js
│   └── users.js
├── seeders
├── services
│   ├── botService.js
│   ├── dashBoardService.js
│   └── passport.js
├── views
│   ├── pages
│   │   ├── allbots.ejs
│   │   ├── connect.ejs
│   │   ├── dashboard.ejs
│   │   ├── signup.ejs
│   │   └── login.ejs
│   ├── partials
│   │   ├── footer.ejs
│   │   ├── header.ejs
│   │   ├── scripts.ejs
│   │   └── sidebar.ejs
│   └── layout.ejs
├── .sequelizerc
├── package.json
└── README.md

Environment requirements.

Install global npm modules for migrate database.

  • Install nodemon
    npm install -g nodemon
  • Install sequelize
    npm install -g sequelize-cli

How to excute this application?

Follow this steps:

    # install node modules.
    npm install
    # database migrate.
    sequelize db:migrate
    # application start.
    npm start

UI desing assets..

bootstrap 4 material

https://fezvrasta.github.io/bootstrap-material-design/ https://fezvrasta.github.io/bootstrap-material-design/docs/4.0/getting-started/introduction/ https://xdsoft.net/jqplugins/datetimepicker/

Font-Awesome url

https://fonts.googleapis.com/css?family=Roboto:300,400,500,700|Material+Icons https://use.fontawesome.com/releases/v5.0.6/css/all.css https://material.io/tools/icons/?icon=insert_comment&style=outline https://www.woolha.com/tutorials/node-js-express-persistent-session-store-with-postgresql-sequelize

core modules

- child_process
- instagram-privat-api ^0.10.1
- sequelize
- pg, pg-hstore

issues

Change log

Please see the changelog for more information on what has changed recently.

Credits

License

MIT License.

Reporting Issues

We use GitHub Issues as the official bug tracker for the Material Kit. Here are some advices for our users that want to report an issue:

  1. Make sure that you are using the latest version of the Material Kit. Check the CHANGELOG from your dashboard on our website.
  2. Providing us reproducible steps for the issue will shorten the time it takes for it to be fixed.
  3. Some issues may be browser specific, so specifying in what browser you encountered the issue might help.

Licensing

Useful Links

Social Media

Twitter: https://twitter.com/CreativeTim?ref=adn-readme

Facebook: https://www.facebook.com/CreativeTim?ref=adn-readme

Dribbble: https://dribbble.com/creativetim?ref=adn-readme

Instagram: https://www.instagram.com/CreativeTimOfficial?ref=adn-readme

Credits

About

ejs, node.js, express, sequelize, postgres application to reply direct message using instagram-private-api

Resources

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

Packages

No packages published