wa multi session
v.3.7.2-stable
การเชื่อมต่อแอปของคุณกับ WhatsApp Messaging
ไลบรารีน้ำหนักเบาสำหรับ WhatsApp ไม่จำเป็นต้องมีซีลีเนียมหรือเบราว์เซอร์อื่น ๆ
ยืนอยู่เหนือห้องสมุด Baileys
ติดตั้งแพ็คเกจโดยใช้ NPM
npm install wa-multi-session@latest
จากนั้นนำเข้ารหัสของคุณ
ใช้โมดูล JS
import * as whatsapp from "wa-multi-session" ;หรือใช้ CommonJs
const whatsapp = require ( "wa-multi-session" ) ; เริ่มเซสชันใหม่
// create session with ID : mysessionid
const session = await whatsapp . startSession ( "mysessionid" ) ;
// Then, scan QR on terminalรับรหัสเซสชันทั้งหมด
const sessions = whatsapp . getAllSession ( ) ;
// returning all session ID that has been createdรับข้อมูลเซสชันด้วย ID
const session = whatsapp . getSession ( "mysessionid" ) ;
// returning session dataโหลดเซสชันจากเซสชันที่เก็บข้อมูล / โหลดที่บันทึกไว้
whatsapp . loadSessionsFromStorage ( ) ;
// Start saved session without scan again ส่งข้อความ
await whatsapp . sendTextMessage ( {
sessionId : "mysessionid" , // session ID
to : "6281234567890" , // always add country code (ex: 62)
text : "Hi There, This is Message from Server!" , // message you want to send
} ) ;ส่งภาพ
const image = fs . readFileSync ( "./myimage.png" ) ; // return Buffer
const send = await whatsapp . sendImage ( {
sessionId : "session1" ,
to : "6281234567890" ,
text : "My Image Caption" ,
media : image , // can from URL too
} ) ;ส่งวิดีโอ
const video = fs . readFileSync ( "./myvideo.mp4" ) ; // return Buffer
const send = await whatsapp . sendVideo ( {
sessionId : "session1" ,
to : "6281234567890" ,
text : "My Video Caption" ,
media : video , // can from URL too
} ) ;ส่งไฟล์เอกสาร
const filename = "mydocument.docx" ;
const document = fs . readFileSync ( filename ) ; // return Buffer
const send = await whatsapp . sendDocument ( {
sessionId : "session1" ,
to : "6281234567890" ,
filename : filename ,
media : document ,
text : "Hei, Check this Document" ,
} ) ;ส่งบันทึกเสียง
const filename = "myaudio.mp3" ;
const audio = fs . readFileSync ( filename ) ; // return Buffer
const send = await whatsapp . sendVoiceNote ( {
sessionId : "session1" ,
to : "6281234567890" ,
media : audio ,
} ) ;อ่านข้อความ
await whatsapp . readMessage ( {
sessionId : "session1" ,
key : msg . key ,
} ) ;ส่งเอฟเฟกต์การพิมพ์
await whatsapp . sendTyping ( {
sessionId : "session1" ,
to : "6281234567890" ,
duration : 3000 ,
} ) ; เพิ่มผู้ฟัง/โทรกลับเมื่อรับข้อความ
whatsapp . onMessageReceived ( ( msg ) => {
console . log ( `New Message Received On Session: ${ msg . sessionId } >>>` , msg ) ;
} ) ;เพิ่มผู้ฟัง/โทรกลับเมื่อพิมพ์ QR
whatsapp . onQRUpdated ( ( { sessionId , qr } ) => {
console . log ( qr ) ;
} ) ;เพิ่มผู้ฟัง/การโทรกลับเมื่อเชื่อมต่อเซสชัน
whatsapp . onConnected ( ( sessionId ) => {
console . log ( "session connected :" + sessionId ) ;
} ) ; 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
} ) ;
} ) ; 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
}
} ) ; ตั้งค่าไดเร็กทอรีข้อมูลรับรองที่กำหนดเอง
// default dir is "wa_credentials"
whatsapp . setCredentialsDir ( "my_custom_dir" ) ;
// or : credentials/mycreds หากคุณมีข้อเสนอแนะหรือการสนับสนุนโปรดติดต่อฉันที่ [email protected]