Multi Session Whatsapp Library
npm install whatsapp-multi-sessionConnecting Your app with Whatsapp Messaging
Lightweight library for whatsapp. Not require Selenium or any other browser.
Stand above Baileys Library.
Install package using npm
```
npm install whatsapp-multi-session@latest
Then import your code
Using JS Module
`ts`
import * as whatsapp from "whatsapp-multi-session";
or using CommonJS
`ts`
const whatsapp = require("whatsapp-multi-session");
Start New Session
`ts
// create session with ID : mysessionid
const session = await whatsapp.startSession("mysessionid");
// Then, scan QR on terminal
`
Start New Session with pairingcode
`ts
// create session with ID : mysessionid
const session = await whatsapp.startSessionWithPairingCode("mysessionid",{phoneNumber:"4267256437"});
console.log(session)
`
Get All Session ID
`ts
const sessions = whatsapp.getAllSession();
// returning all session ID that has been created
`
Get Session Data By ID
`ts`
const session = whatsapp.getSession("mysessionid");
// returning session data
Load Session From Storage / Load Saved Session
`ts`
whatsapp.loadSessionsFromStorage();
// Start saved session without scan again
Kick a user
`ts`
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
`ts`
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
`ts`
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
`ts`
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
`ts`
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
`ts`
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
`ts`
const send = await whatsapp.del({
sessionId: "session1",
to: "436779437",//witch group
id: "ueifjs3230",//message id
sender:"439137310"//witch user
});
Read a Message
`ts`
await whatsapp.readMessage({
sessionId: "session1",
key: msg.key,
});
Send Typing Effect
`ts`
await whatsapp.sendTyping({
sessionId: "session1",
to: "436779437",
duration: 3000,
});
Add Listener/Callback When Receive a Message
`tsNew Message Received On Session: ${msg.sessionId} >>>
whatsapp.onMessageReceived((msg) => {
console.log(, msg);`
});
Add Listener/Callback When QR Printed
`ts`
whatsapp.onQRUpdated(({ sessionId, qr }) => {
console.log(qr);
});
Add Listener/Callback When Session Connected
`ts`
whatsapp.onConnected((sessionId) => {
console.log("session connected :" + sessionId);
});
`ts`
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
});
});
`ts
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
}
});
`
Einstellen der von ihnen gewählte speicher ort
`ts`
// default dir is "wa_credentials"
whatsapp.setCredentialsDir("my_custom_dir");
// or : credentials/mycreds
Einstellen der von ihnen gewählte namens der session
`ts
// default dir is "_credentials"
whatsapp.setCredentials("_credentials");
``
contact sebloidl13@gmail.com