1.5.31 • Published 9 months ago

whatsapp-multi-session v1.5.31

Weekly downloads
-
License
ISC
Repository
-
Last release
9 months ago

Whatsapp Multi Session - Connecting More Whatsapp Session in 1 App

Connecting Your app with Whatsapp Messaging

Lightweight library for whatsapp. Not require Selenium or any other browser.

Stand above Baileys Library.

Installation

Install package using npm

npm install whatsapp-multi-session@latest

Then import your code

Using JS Module

import * as whatsapp from "whatsapp-multi-session";

or using CommonJS

const whatsapp = require("whatsapp-multi-session");

Session Usage/Examples

Start New Session

// create session with ID : mysessionid

const session = await whatsapp.startSession("mysessionid");
// Then, scan QR on terminal

Start New Session with pairingcode

// create session with ID : mysessionid

const session = await whatsapp.startSessionWithPairingCode("mysessionid",{phoneNumber:"4267256437"});
console.log(session)

Get All Session ID

const sessions = whatsapp.getAllSession();
// returning all session ID that has been created

Get Session Data By ID

const session = whatsapp.getSession("mysessionid");
// returning session data

Load Session From Storage / Load Saved Session

whatsapp.loadSessionsFromStorage();
// Start saved session without scan again

Messaging Usage/Examples

Kick a user

await whatsapp.kickusr({
  sessionId: "mysessionid", // session ID
  to: chatId,//chatId is the group Id aka 123448242834@g.us
  text: "436779437@s.whatsapp.net", 
});

Send Text Message

await whatsapp.sendTextMessage({
  sessionId: "mysessionid", // session ID
  to: "436779437", // always add country code (ex: 62)
  isGroup = false , //set true for sending messages in groups
  text: "Hi There, This is Message from Server!", // message you want to send
  Jid:['@436779437'] //mentionedJid
});

Send Image

const image = fs.readFileSync("./myimage.png"); // return Buffer
const send = await whatsapp.sendImage({
  sessionId: "session1",
  to: "436779437",
  text: "My Image Caption",
  media: image, // can from URL too
});

Send Video

const video = fs.readFileSync("./myvideo.mp4"); // return Buffer
const send = await whatsapp.sendVideo({
  sessionId: "session1",
  to: "436779437",
  text: "My Video Caption",
  media: video, // can from URL too
});

Send Document File

const filename = "mydocument.docx";
const document = fs.readFileSync(filename); // return Buffer
const send = await whatsapp.sendDocument({
  sessionId: "session1",
  to: "436779437",
  filename: filename,
  media: document,
  text: "Hei, Check this Document",
});

Send Voice Note

const filename = "myaudio.mp3";
const audio = fs.readFileSync(filename); // return Buffer
const send = await whatsapp.sendVoiceNote({
  sessionId: "session1",
  to: "436779437",
  media: audio,
});

Delete a message

const send = await whatsapp.del({
  sessionId: "session1",
  to: "436779437",//witch group
  id: "ueifjs3230",//message id
  sender:"439137310"//witch user
});

Read a Message

await whatsapp.readMessage({
  sessionId: "session1",
  key: msg.key,
});

Send Typing Effect

await whatsapp.sendTyping({
  sessionId: "session1",
  to: "436779437",
  duration: 3000,
});

Listener Usage/Examples

Add Listener/Callback When Receive a Message

whatsapp.onMessageReceived((msg) => {
  console.log(`New Message Received On Session: ${msg.sessionId} >>>`, msg);
});

Add Listener/Callback When QR Printed

whatsapp.onQRUpdated(({ sessionId, qr }) => {
  console.log(qr);
});

Add Listener/Callback When Session Connected

whatsapp.onConnected((sessionId) => {
  console.log("session connected :" + sessionId);
});

Handling Incoming Message Examples

whatsapp.onMessageReceived(async (msg) => {
  if (msg.key.fromMe || msg.key.remoteJid.includes("status")) return;
  await whatsapp.readMessage({
    sessionId: msg.sessionId,
    key: msg.key,
  });
  await whatsapp.sendTyping({
    sessionId: msg.sessionId,
    to: msg.key.remoteJid,
    duration: 3000,
  });
  await whatsapp.sendTextMessage({
    sessionId: msg.sessionId,
    to: msg.key.remoteJid,
    text: "Hallo!",
    answering: msg, // auf die nachricht markieren
  });
});

Save Media Message (Image, Video, Document)

wa.onMessageReceived(async (msg) => {
  if (msg.message?.imageMessage) {
    // save image
    msg.saveImage("./myimage.jpg");
  }

  if (msg.message?.videoMessage) {
    // save video
    msg.saveVideo("./myvideo.mp4");
  }

  if (msg.message?.documentMessage) {
    // save document
    msg.saveDocument("./mydocument"); // without extension
  }
});

Optional Configuration Usage/Examples

Einstellen der von ihnen gewählte speicher ort

// default dir is "wa_credentials"
whatsapp.setCredentialsDir("my_custom_dir");
// or : credentials/mycreds

Einstellen der von ihnen gewählte namens der session

// default dir is "_credentials"
whatsapp.setCredentials("_credentials");

Feedback or Support

contact sebloidl13@gmail.com

1.5.30

10 months ago

1.5.31

9 months ago

1.5.27

10 months ago

1.5.26

10 months ago

1.5.29

10 months ago

1.3.17

11 months ago

1.3.18

11 months ago

1.3.15

11 months ago

1.3.16

11 months ago

1.3.19

11 months ago

1.3.20

11 months ago

1.3.21

11 months ago

1.3.24

10 months ago

1.3.25

10 months ago

1.3.22

11 months ago

1.3.23

11 months ago

1.3.26

10 months ago

1.3.10

1 year ago

1.3.13

1 year ago

1.3.14

1 year ago

1.3.11

1 year ago

1.3.12

1 year ago

1.3.9

1 year ago

1.3.8

1 year ago

1.3.7

1 year ago

1.3.6

1 year ago

1.3.5

1 year ago

1.3.4

1 year ago

1.3.3

1 year ago

1.3.2

1 year ago

1.3.1

1 year ago

1.2.0

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.1.6

1 year ago

1.1.5

1 year ago

1.1.4

1 year ago

1.1.3

1 year ago

1.2.1

1 year ago

1.1.2

1 year ago

1.0.0

1 year ago