Code Monkey home page Code Monkey logo

wabot-with-pairingcode's Introduction

Dependencies

node-cache
readline
@whiskeysockets/baileys: v6.4.0^

Variable and function

1.

   const { makeCacheableSignalKeyStore, PHONENUMBER_MCC } = require("@whiskeysockets/baileys")

   const NodeCache = require("node-cache");
   const readline = require("readline");

2.

   const usePairingCode = true;
   const useMobile = false;
   const useStore = false;

3.

const MAIN_LOGGER = pino({ timestamp: () => `,"time":"${new Date().toJSON()}"` });

const logger = MAIN_LOGGER.child({});
logger.level = "trace";

const store = useStore ? makeInMemoryStore({ logger }) : undefined;
store?.readFromFile("./session");

// Save every 1m
setInterval(() => {
  store?.writeToFile("./session");
}, 10000 * 6);

const msgRetryCounterCache = new NodeCache();

const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
});
const question = (text) => new Promise((resolve) => rl.question(text, resolve));

const P = require("pino")({
  level: "silent",
});

NOTICE

if you already have a variable store, then You have to change the name, because the store variable is different from before

 // change variable name
 //          |
  const stores = makeInMemoryStore({
  logger: pino().child({ level: "silent", stream: "store" }),
  });

Conection option

  async function start() {
  let { state, saveCreds } = await useMultiFileAuthState(sessionName);
   let { version, isLatest } = await fetchLatestBaileysVersion();
  const sock = makeWASocket({
      version,
      logger: P, // P for hidden log console
      printQRInTerminal: !usePairingCode, // If you want to use scan, then change the value of this variable to false
      mobile: useMobile,
      browser: ["chrome (linux)", "", ""], // If you change this then the pairing code will not work
      auth: {
         creds: state.creds,
         keys: makeCacheableSignalKeyStore(state.keys, P),
      },
      msgRetryCounterCache,
  });
  store?.bind(sock.ev);

  sock.ev.on("creds.update", saveCreds); // to save creds

 if (usePairingCode && !sock.authState.creds.registered) {
      if (useMobile) {
         throw new Error("cannot use mobile api");
      }
      const phoneNumber = await question(
         "Enter your active whatsapp number: "
      );
      const code = await sock.requestPairingCode(phoneNumber);
      console.log(`pairing with this code: ${code}`);
   }
}
start();

Thankyou for visit my github, please follow my haha

wabot-with-pairingcode's People

Contributors

apdev93 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.