4.1.1 • Published 1 year ago
synbussolutions-whatsapp v4.1.1
WhatsApp Multi-Session Library - Connect more WhatsApp sessions in 1 application.
Connecting your app with WhatsApp.
Lightweight library for WhatsApp. You don't need to use Selenium or other browsers.
Standing on Baileys Library.
Installation
Install the package using the npm
npm install synbussolutions-whatsappThen import your code
Use JS Module
import * as whatsapp from "synbussolutions-whatsapp";or use CommonJS
const whatsapp = require("synbussolutions-whatsapp");Session Usage/Examples
Start New Session
const session = await whatsapp.startSession("sumit");
// Create session with ID: synbussolutions
// Then, scan the QR in the terminalGet All Session ID
const sessions = whatsapp.getAllSession();
// Returns all session IDs that have been createdGet Session Data By ID
const session = whatsapp.getSession("sumit");
// Return session dataLoad Session From Storage / Load Saved Session
whatsapp.loadSessionsFromStorage();
// Start a saved session without scanning againMessaging Usage/Examples
Send Text Message
await whatsapp.sendTextMessage({
sessionId: "sumit", // session ID
to: "917838343515", // always add country code (example: 91)
text: "Hi. This is a message from Server.", // message you want to send
});Send Image
const image = fs.readFileSync("./myimage.png"); // return Buffer
const send = await whatsapp.sendImage({
sessionId: "sumit",
to: "917838343515",
text: "My Image Caption",
media: image, // can from URL too
});Send Video
const video = fs.readFileSync("./video.mp4"); // return Buffer
const send = await whatsapp.sendVideo({
sessionId: "sumit",
to: "917838343515",
text: "My video caption",
media: video, // can from URL too
});Send Document File
const filename = "file.pdf";
const document = fs.readFileSync(filename); // return Buffer
const send = await whatsapp.sendDocument({
sessionId: "sumit",
to: "917838343515",
filename: filename,
media: document,
text: "Hi check this Document",
});Read a Message
await whatsapp.readMessage({
sessionId: "sumit",
key: msg.key,
});Send Typing Effect
await whatsapp.sendTyping({
sessionId: "sumit",
to: "917838343515",
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: "Hello!",
answering: msg, // for quoting message
});
});Save Media Message (Image, Video, Document)
wa.onMessageReceived(async (msg) => {
if (msg.message?.imageMessage) {
// save image
msg.saveImage("./image.jpg");
}
if (msg.message?.videoMessage) {
// save video
msg.saveVideo("./video.mp4");
}
if (msg.message?.documentMessage) {
// save document
msg.saveDocument("./file"); // without extension
}
});Optional Configuration Usage/Examples
Set custom credentials directory
// default dir is "wa_credentials"
whatsapp.setCredentialsDir("my_custom_dir");
// or : credentials/mycredsSet custom Browser
// Default browser is SynbusSolutionsB
whatsapp.setBrowser("macOS");
// or any other your custom nameAuthors
Feedback or Support
If you have any feedback or support, please contact me at support@synbussolutions.com