Venom是一個由JavaScript開發的高性能係統,可為WhatsApp創建一個機器人,支持創建任何交互,例如客戶服務,媒體發送,基於人工智能的句子識別以及WhatsApp的所有類型的設計體系結構。
完整的文檔
這是WhatsApp的高性能替代API,您可以發送,短信,文件,圖像,視頻等。
請記住,API是在一個名為Restful Web服務的平台上開發的,可在Internet上提供互操作性。
它使用一組適用於所有信息資源的定義明確的操作:HTTP本身定義了一小部分操作,最重要的是發布,獲取,放置和刪除。
用您喜歡的語言(例如PHP,Python,C#等)使用它。只要您的語言得到HTTP協議的支持,您就可以節省時間和金錢。您不需要知道毒液的工作原理,我們以專業的方式擁有完整的API文檔!


SuperChats是一個高級庫,具有獨特功能,可以控制WhatsApp功能。使用SuperChats,您可以構建服務機器人,多服務聊天或使用WhatsApp的任何系統
SuperChats是毒液的高級版本,具有全球公司和開發人員的獨家功能和支持
https://github.com/orkestral/superchats
許可證的價值為每月50美元,通過單擊下圖,以獲取WhatsApp的聯繫!
| ?自動QR刷新 | ✔ |
| ?發送文本,圖像,視頻,音頻和文檔 | ✔ |
| 獲取聯繫人,聊天,小組,小組成員,塊列表 | ✔ |
| ?發送聯繫人 | ✔ |
| 發送按鈕 | ✔ |
| 發送貼紙 | ✔ |
| 發送貼紙gif | ✔ |
| 多個會議 | ✔ |
| ⏩向前消息 | ✔ |
| ?接收消息 | ✔ |
| ?插入用戶部分 | ✔ |
| ?發送位置!! | ✔ |
| ?還有更多 | ✔ |
https://orkestral.github.io/venom/index.html的文檔
> npm i --save venom-bot或夜間發行:
> npm i --save https://github.com/orkestral/venom/releases/download/nightly/venom-bot-nightly.tgz安裝當前存儲庫“您可以從當前存儲庫中下載Beta版本!”
> npm i github:orkestral/venom // Supports ES6
// import { create, Whatsapp } from 'venom-bot';
const venom = require ( 'venom-bot' ) ;
venom
. create ( {
session : 'session-name' //name of session
} )
. then ( ( client ) => start ( client ) )
. catch ( ( erro ) => {
console . log ( erro ) ;
} ) ;
function start ( client ) {
client . onMessage ( ( message ) => {
if ( message . body === 'Hi' && message . isGroupMsg === false ) {
client
. sendText ( message . from , 'Welcome Venom ?' )
. then ( ( result ) => {
console . log ( 'Result: ' , result ) ; //return object success
} )
. catch ( ( erro ) => {
console . error ( 'Error when sending: ' , erro ) ; //return object error
} ) ;
}
} ) ;
} create()函數後, Venom將創建WhatsApp Web的實例。如果未登錄,它將在終端中打印一個QR碼。用手機掃描它,您準備出發了! create()函數: // Init sales whatsapp bot
venom . create ( 'sales' ) . then ( ( salesClient ) => { ... } ) ;
// Init support whatsapp bot
venom . create ( 'support' ) . then ( ( supportClient ) => { ... } ) ; venom create()方法第三參數可以具有以下可選參數:
如果您使用的是Linux服務器,請不要忘記通過browserargs中的Args --user-agent Original參數
const venom = require ( 'venom-bot' ) ;
venom
. create (
//session
'sessionName' , //Pass the name of the client you want to start the bot
//catchQR
( base64Qrimg , asciiQR , attempts , urlCode ) => {
console . log ( 'Number of attempts to read the qrcode: ' , attempts ) ;
console . log ( 'Terminal qrcode: ' , asciiQR ) ;
console . log ( 'base64 image string qrcode: ' , base64Qrimg ) ;
console . log ( 'urlCode (data-ref): ' , urlCode ) ;
} ,
// statusFind
( statusSession , session ) => {
console . log ( 'Status Session: ' , statusSession ) ; //return isLogged || notLogged || browserClose || qrReadSuccess || qrReadFail || autocloseCalled || desconnectedMobile || deleteToken || chatsAvailable || deviceNotConnected || serverWssNotConnected || noOpenBrowser || initBrowser || openBrowser || connectBrowserWs || initWhatsapp || erroPageWhatsapp || successPageWhatsapp || waitForLogin || waitChat || successChat
//Create session wss return "serverClose" case server for close
console . log ( 'Session name: ' , session ) ;
} ,
// options
{
browserPathExecutable : '' , // browser executable path
folderNameToken : 'tokens' , //folder name when saving tokens
mkdirFolderToken : '' , //folder directory tokens, just inside the venom folder, example: { mkdirFolderToken: '/node_modules', } //will save the tokens folder in the node_modules directory
headless : 'new' , // you should no longer use boolean false or true, now use false, true or 'new' learn more https://developer.chrome.com/articles/new-headless/
devtools : false , // Open devtools by default
debug : false , // Opens a debug session
logQR : true , // Logs QR automatically in terminal
browserWS : '' , // If u want to use browserWSEndpoint
browserArgs : [ '' ] , // Original parameters ---Parameters to be added into the chrome browser instance
addBrowserArgs : [ '' ] , // Add broserArgs without overwriting the project's original
puppeteerOptions : { } , // Will be passed to puppeteer.launch
disableSpins : true , // Will disable Spinnies animation, useful for containers (docker) for a better log
disableWelcome : true , // Will disable the welcoming message which appears in the beginning
updatesLog : true , // Logs info updates automatically in terminal
autoClose : 60000 , // Automatically closes the venom-bot only when scanning the QR code (default 60 seconds, if you want to turn it off, assign 0 or false)
createPathFileToken : false , // creates a folder when inserting an object in the client's browser, to work it is necessary to pass the parameters in the function create browserSessionToken
addProxy : [ '' ] , // Add proxy server exemple : [e1.p.webshare.io:01, e1.p.webshare.io:01]
userProxy : '' , // Proxy login username
userPass : '' // Proxy password
} ,
// BrowserInstance
( browser , waPage ) => {
console . log ( 'Browser PID:' , browser . process ( ) . pid ) ;
waPage . screenshot ( { path : 'screenshot.png' } ) ;
}
)
. then ( ( client ) => {
start ( client ) ;
} )
. catch ( ( erro ) => {
console . log ( erro ) ;
} ) ; 如果會話被isLogged或browserClose或notLogged或qrReadSuccess或qrReadFail或autocloseCalled或desconnectedMobile或deleteToken或serverWssNotConnected或deviceNotConnected或noOpenBrowser或initBrowser或connectBrowserWs或initWhatsapp chatsAvailable waitForLogin openBrowser erroPageWhatsapp successPageWhatsapp waitChat Create session wss return "serverClose" case server for close
| 地位 | 狀態 |
|---|---|
isLogged | 當用戶已經登錄到瀏覽器時 |
notLogged | 當用戶未連接到瀏覽器時,有必要通過選項Whatsapp Web中的手機掃描QR碼 |
browserClose | 如果關閉瀏覽器,則返回此參數 |
qrReadSuccess | 如果未登錄用戶,則在終端上傳遞QR碼,返回回調。通過手機正確閱讀後,返回此參數 |
qrReadFail | 如果在進行QR代碼掃描時瀏覽器停止,則返回此參數 |
autocloseCalled | 使用AutoClose命令關閉瀏覽器 |
desconnectedMobile | 客戶已與移動 |
serverClose | 客戶已與WSS相關聯 |
deleteToken | 如果您在功能中通過 |
chatsAvailable | 當毒液連接到聊天列表時 |
deviceNotConnected | 聊天不可用,因為電話已斷開(Trying to connect to the phone) |
serverWssNotConnected | 找不到地址WSS! |
noOpenBrowser | 它在瀏覽器中沒有發現,或者在ARGS中缺少一些命令 |
initBrowser | 啟動瀏覽器 |
openBrowser | 瀏覽器已成功打開! |
connectBrowserWs | 成功完成了與瀏覽器的聯繫! |
initWhatsapp | 開始WhatsApp! |
erroPageWhatsapp | 訪問WhatsApp頁面的錯誤 |
successPageWhatsapp | 頁面WhatsApp成功訪問了 |
waitForLogin | 等待登錄驗證! |
waitChat | 等待聊天加載 |
successChat | 聊天成功加載! |
const venom = require ( 'venom-bot' ) ;
venom
. create ( 'sessionName' , undefined , ( statusSession , session ) => {
console . log ( 'Status Session: ' , statusSession ) ;
//return isLogged || notLogged || browserClose || qrReadSuccess || qrReadFail || autocloseCalled || desconnectedMobile || deleteToken || chatsAvailable || deviceNotConnected || serverWssNotConnected || noOpenBrowser || initBrowser || openBrowser || connectBrowserWs || initWhatsapp || erroPageWhatsapp || successPageWhatsapp || waitForLogin || waitChat || successChat
//Create session wss return "serverClose" case server for close
console . log ( 'Session name: ' , session ) ;
} )
. then ( ( client ) => {
start ( client ) ;
} )
. catch ( ( erro ) => {
console . log ( erro ) ;
} ) ; 默認情況下,QR碼將出現在終端上。如果您需要通過其他地方的QR將QR傳遞:
const fs = require ( 'fs' ) ;
const venom = require ( 'venom-bot' ) ;
venom
. create (
'sessionName' ,
( base64Qr , asciiQR , attempts , urlCode ) => {
console . log ( asciiQR ) ; // Optional to log the QR in the terminal
var matches = base64Qr . match ( / ^data:([A-Za-z-+/]+);base64,(.+)$ / ) ,
response = { } ;
if ( matches . length !== 3 ) {
return new Error ( 'Invalid input string' ) ;
}
response . type = matches [ 1 ] ;
response . data = new Buffer . from ( matches [ 2 ] , 'base64' ) ;
var imageBuffer = response ;
require ( 'fs' ) . writeFile (
'out.png' ,
imageBuffer [ 'data' ] ,
'binary' ,
function ( err ) {
if ( err != null ) {
console . log ( err ) ;
}
}
) ;
} ,
undefined ,
{ logQR : false }
)
. then ( ( client ) => {
start ( client ) ;
} )
. catch ( ( erro ) => {
console . log ( erro ) ;
} ) ; Puppeteer會照顧文件下載。解密盡可能快地完成(本機方法)。支持大文件!
import fs = require ( 'fs' ) ;
import mime = require ( 'mime-types' ) ;
client . onMessage ( async ( message ) => {
if ( message . isMedia === true || message . isMMS === true ) {
const buffer = await client . decryptFile ( message ) ;
// At this point you can do whatever you want with the buffer
// Most likely you want to write it into a file
const fileName = `some-file-name. ${ mime . extension ( message . mimetype ) } ` ;
fs . writeFile ( fileName , buffer , ( err ) => {
...
} ) ;
}
} ) ; 並非每個可用功能都列出
chatId可以是<phoneNumber>@c.us或<phoneNumber>-<groupId>@g.us // Send Poll
const poll = {
name : 'new poll' ,
options : [
{
name : 'option 1'
} ,
{
name : 'option 2'
}
] ,
selectableOptionsCount : 1
} ;
await client . sendPollCreation ( '[email protected]' , poll )
. then ( ( result ) => {
console . log ( 'Result: ' , result ) ; //return object success
} )
. catch ( ( erro ) => {
console . error ( 'Error when sending: ' , erro ) ; //return object error
} ) ;
// Send List menu
const list = [
{
title : "Pasta" ,
rows : [
{
title : "Ravioli Lasagna" ,
description : "Made with layers of frozen cheese" ,
}
]
} ,
{
title : "Dessert" ,
rows : [
{
title : "Baked Ricotta Cake" ,
description : "Sweets pecan baklava rolls" ,
} ,
{
title : "Lemon Meringue Pie" ,
description : "Pastry filled with lemonand meringue." ,
}
]
}
] ;
await client . sendListMenu ( '[email protected]' , 'Title' , 'subTitle' , 'Description' , 'menu' , list )
. then ( ( result ) => {
console . log ( 'Result: ' , result ) ; //return object success
} )
. catch ( ( erro ) => {
console . error ( 'Error when sending: ' , erro ) ; //return object error
} ) ;
// Send Messages with Buttons Reply
const buttons = [
{
"buttonText" : {
"displayText" : "Text of Button 1"
}
} ,
{
"buttonText" : {
"displayText" : "Text of Button 2"
}
}
]
await client . sendButtons ( '[email protected]' , 'Title' , 'Description' , buttons )
. then ( ( result ) => {
console . log ( 'Result: ' , result ) ; //return object success
} )
. catch ( ( erro ) => {
console . error ( 'Error when sending: ' , erro ) ; //return object error
} ) ;
// Send audio file MP3
await client . sendVoice ( '[email protected]' , './audio.mp3' ) . then ( ( result ) => {
console . log ( 'Result: ' , result ) ; //return object success
} )
. catch ( ( erro ) => {
console . error ( 'Error when sending: ' , erro ) ; //return object error
} ) ;
// Send audio file base64
await client . sendVoiceBase64 ( '[email protected]' , base64MP3 )
. then ( ( result ) => {
console . log ( 'Result: ' , result ) ; //return object success
} )
. catch ( ( erro ) => {
console . error ( 'Error when sending: ' , erro ) ; //return object error
} ) ;
// Send contact
await client
. sendContactVcard ( '[email protected]' , '[email protected]' , 'Name of contact' )
. then ( ( result ) => {
console . log ( 'Result: ' , result ) ; //return object success
} )
. catch ( ( erro ) => {
console . error ( 'Error when sending: ' , erro ) ; //return object error
} ) ;
// Send a list of contact cards
await client
. sendContactVcardList ( '[email protected]' , [
'[email protected]' ,
'[email protected]' ,
] )
. then ( ( result ) => {
console . log ( 'Result: ' , result ) ; //return object success
} )
. catch ( ( erro ) => {
console . error ( 'Error when sending: ' , erro ) ; //return object error
} ) ;
// Send basic text
await client
. sendText ( '[email protected]' , ' Hello from venom!' )
. then ( ( result ) => {
console . log ( 'Result: ' , result ) ; //return object success
} )
. catch ( ( erro ) => {
console . error ( 'Error when sending: ' , erro ) ; //return object error
} ) ;
// Send text message by injecting keystrokes into WhatsApp, thus maintaining the typing indicator
let success = await client . sendTextViaTyping ( '[email protected]' , ' Hello from venom!' ) ;
// Send photo or video by injecting keystrokes
let success = await client . sendPhotoVideoViaTyping ( '[email protected]' , 'path/to/file.jpg' , 'Pretty sunset' ) ;
// Send location
await client
. sendLocation ( '[email protected]' , '-13.6561589' , '-69.7309264' , 'Brasil' )
. then ( ( result ) => {
console . log ( 'Result: ' , result ) ; //return object success
} )
. catch ( ( erro ) => {
console . error ( 'Error when sending: ' , erro ) ; //return object error
} ) ;
// Automatically sends a link with the auto generated link preview. You can also add a custom message to be added.
await client
. sendLinkPreview (
'[email protected]' ,
'https://www.youtube.com/watch?v=V1bFr2SWP1I' ,
'Kamakawiwo ole'
)
. then ( ( result ) => {
console . log ( 'Result: ' , result ) ; //return object success
} )
. catch ( ( erro ) => {
console . error ( 'Error when sending: ' , erro ) ; //return object error
} ) ;
// Send image (you can also upload an image using a valid HTTP protocol)
await client
. sendImage (
'[email protected]' ,
'path/to/img.jpg' ,
'image-name' ,
'Caption text'
)
. then ( ( result ) => {
console . log ( 'Result: ' , result ) ; //return object success
} )
. catch ( ( erro ) => {
console . error ( 'Error when sending: ' , erro ) ; //return object error
} ) ;
// Send image file base64
await client . sendImageFromBase64 ( '[email protected]' , base64Image , "name file" )
. then ( ( result ) => {
console . log ( 'Result: ' , result ) ; //return object success
} )
. catch ( ( erro ) => {
console . error ( 'Error when sending: ' , erro ) ; //return object error
} ) ;
// Send file (venom will take care of mime types, just need the path)
// you can also upload an image using a valid HTTP protocol
await client
. sendFile (
'[email protected]' ,
'path/to/file.pdf' ,
'file_name' ,
'See my file in pdf'
)
. then ( ( result ) => {
console . log ( 'Result: ' , result ) ; //return object success
} )
. catch ( ( erro ) => {
console . error ( 'Error when sending: ' , erro ) ; //return object error
} ) ;
// Sends file
// base64 parameter should have mime type already defined
await client
. sendFileFromBase64 (
'[email protected]' ,
base64PDF ,
'file_name.pdf' ,
'See my file in pdf'
)
. then ( ( result ) => {
console . log ( 'Result: ' , result ) ; //return object success
} )
. catch ( ( erro ) => {
console . error ( 'Error when sending: ' , erro ) ; //return object error
} ) ;
// Generates sticker from the provided animated gif image and sends it (Send image as animated sticker)
// image path imageBase64 A valid gif and webp image is required. You can also send via http/https (http://www.website.com/img.gif)
await client
. sendImageAsStickerGif ( '[email protected]' , './image.gif' )
. then ( ( result ) => {
console . log ( 'Result: ' , result ) ; //return object success
} )
. catch ( ( erro ) => {
console . error ( 'Error when sending: ' , erro ) ; //return object error
} ) ;
// Generates sticker from given image and sends it (Send Image As Sticker)
// image path imageBase64 A valid png, jpg and webp image is required. You can also send via http/https (http://www.website.com/img.jpg)
await client
. sendImageAsSticker ( '[email protected]' , './image.jpg' )
. then ( ( result ) => {
console . log ( 'Result: ' , result ) ; //return object success
} )
. catch ( ( erro ) => {
console . error ( 'Error when sending: ' , erro ) ; //return object error
} ) ;
// Forwards messages
await client . forwardMessages (
'[email protected]' ,
[ '[email protected]_B70847EE89E22D20FB86ECA0C1B11609' , '[email protected]_B70847EE89E22D20FB86ECA0C1B11777' ]
) . then ( ( result ) => {
console . log ( 'Result: ' , result ) ; //return object success
} )
. catch ( ( erro ) => {
console . error ( 'Error when sending: ' , erro ) ; //return object error
} ) ;
// Send @tagged message
await client . sendMentioned (
'[email protected]' ,
'Hello @5218113130740 and @5218243160777!' ,
[ '5218113130740' , '5218243160777' ]
) ;
// Reply to a message
await client . reply (
'[email protected]' ,
'This is a reply!' ,
'[email protected]_7C22WHCB6DKYHJKQIEN9'
) . then ( ( result ) => {
console . log ( 'Result: ' , result ) ; //return object success
} ) . catch ( ( erro ) => {
console . error ( 'Error when sending: ' , erro ) ; //return object error
} ) ;
// Send message with options
await client .
. sendMessageOptions (
'[email protected]' ,
'This is a reply!' ,
{
quotedMessageId : reply ,
}
)
. then ( ( retorno ) => {
resp = retorno ;
} )
. catch ( ( e ) => {
console . log ( e ) ;
} ) ;
// Send gif
await client . sendVideoAsGif (
'[email protected]' ,
'path/to/video.mp4' ,
'video.gif' ,
'Gif image file'
) ;
//checks and returns whether a message and a reply
// exemple:
// await client.onMessage(async (message) => {
// console.log(await client.returnReply(message)); // replicated message
// console.log(message.body ); //customer message
// })
checkReply = await client . returnReply ( messagem ) ;
// Send seen ✔️✔️
await client . sendSeen ( '[email protected]' ) ;
// Start typing...
await client . startTyping ( '[email protected]' ) ;
// Set chat state (0: Typing, 1: Recording, 2: Paused)
await client . setChatState ( '[email protected]' , 0 | 1 | 2 ) ; // Retrieve all chats
const chats = await client . getAllChats ( ) ;
//Retrieves all chats new messages
const chatsAllNew = getAllChatsNewMsg ( ) ;
//Retrieves all chats Contacts
const contacts = await client . getAllChatsContacts ( ) ;
//Retrieve all contacts new messages
const contactNewMsg = await client . getChatContactNewMsg ( ) ;
// Retrieve all groups
// you can pass the group id optional use, exemple: client.getAllChatsGroups('[email protected]')
const chats = await client . getAllChatsGroups ( ) ;
//Retrieve all groups new messages
const groupNewMsg = await client . getChatGroupNewMsg ( ) ;
//Retrieves all chats Transmission list
const transmission = await client . getAllChatsTransmission ( ) ;
// Retrieve contacts
const contacts = await client . getAllContacts ( ) ;
// Returns a list of mute and non-mute users
// "all" List all mutes
// "toMute" List all silent chats
// "noMute" List all chats without silence
const listMute = await client . getListMute ( 'all' ) ;
// Calls your list of blocked contacts (returns an array)
const getBlockList = await client . getBlockList ( ) ;
// Retrieve messages in chat
//chatID chat id
//includeMe will be by default true, if you do not want to pass false
//includeNotifications will be by default true, if you do not want to pass false
//const Messages = await client.getAllMessagesInChat(chatID, includeMe, includeNotifications)
const Messages = await client . getAllMessagesInChat ( '[email protected]' ) ;
// Retrieve more chat message
const moreMessages = await client . loadEarlierMessages ( '[email protected]' ) ;
// Retrieve all messages in chat
const allMessages = await client . loadAndGetAllMessagesInChat (
'[email protected]'
) ;
// Retrieve contact status
const status = await client . getStatus ( '[email protected]' ) ;
// Retrieve user profile
// Please note that this function does not currently work due to a bug in WhatsApp itself.
// There is no telling if or when this function might work again.
const user = await client . getNumberProfile ( '[email protected]' ) ;
// Retrieve all unread message
const messages = await client . getUnreadMessages ( ) ;
// Retrieve profile fic (as url)
const url = await client . getProfilePicFromServer ( '[email protected]' ) ;
// Retrieve chat/conversation
const chat = await client . getChat ( '[email protected]' ) ;
// Check if the number exists
const chat = await client
. checkNumberStatus ( '[email protected]' )
. then ( ( result ) => {
console . log ( 'Result: ' , result ) ; //return object success
} )
. catch ( ( erro ) => {
console . error ( 'Error when sending: ' , erro ) ; //return object error
} ) ; // groupId or chatId: leaveGroup [email protected]
//change group description
await client
. setGroupDescription ( '[email protected]' , 'group description' )
. then ( ( result ) => {
console . log ( 'Result: ' , result ) ; //return object success
} )
. catch ( ( erro ) => {
console . error ( 'Error when sending: ' , erro ) ; //return object error
} ) ;
// Leave group
await client . leaveGroup ( '[email protected]' ) ;
// Get group members
await client . getGroupMembers ( '[email protected]' ) ;
// Get group members ids
await client . getGroupMembersIds ( '[email protected]' ) ;
// Generate group invite url link
await client . getGroupInviteLink ( '[email protected]' ) ;
// Create group (title, participants to add)
await client . createGroup ( 'Group name' , [
'[email protected]' ,
'[email protected]'
] ) ;
// Remove participant
await client . removeParticipant ( '[email protected]' , '[email protected]' ) ;
// Add participant
await client . addParticipant ( '[email protected]' , '[email protected]' ) ;
// Promote participant (Give admin privileges)
await client . promoteParticipant ( '[email protected]' , '[email protected]' ) ;
// Demote particiapnt (Revoke admin privileges)
await client . demoteParticipant ( '[email protected]' , '[email protected]' ) ;
// Get group admins
await client . getGroupAdmins ( '[email protected]' ) ;
// Return the group status, jid, description from it's invite link
await client . getGroupInfoFromInviteLink ( InviteCode ) ;
// Join a group using the group invite code
await client . joinGroup ( InviteCode ) ; // Set client status
await client . setProfileStatus ( 'On vacations! ✈️' ) ;
// Set client profile name
await client . setProfileName ( 'Venom bot' ) ;
// Set client profile photo
await client . setProfilePic ( 'path/to/image.jpg' ) ;
// Get device info
await client . getHostDevice ( ) ; // Disconnect from service
await client . logout ( ) ;
// Delete the Service Worker
await client . killServiceWorker ( ) ;
// Load the service again
await client . restartService ( ) ;
// Get connection state
await client . getConnectionState ( ) ;
// Get battery level
await client . getBatteryLevel ( ) ;
// Is connected
await client . isConnected ( ) ;
// Get whatsapp web version
await client . getWAVersion ( ) ; //Listens to all new messages
//To receiver or recipient
client . onAnyMessage ( message => {
...
} ;
// Listen to messages
client . onMessage ( message => {
...
} )
// Listen for messages that have been edited
client . onMessageEdit ( message => {
...
} )
// Listen for messages that have been deleted
client . onMessageDelete ( message => {
...
} )
// Listen to state changes
client . onStateChange ( state => {
...
} ) ;
// Listen to ack's
// See the status of the message when sent.
// When receiving the confirmation object, "ack" may return a number, look {@link AckType} for details:
// -7 = MD_DOWNGRADE,
// -6 = INACTIVE,
// -5 = CONTENT_UNUPLOADABLE,
// -4 = CONTENT_TOO_BIG,
// -3 = CONTENT_GONE,
// -2 = EXPIRED,
// -1 = FAILED,
// 0 = CLOCK,
// 1 = SENT,
// 2 = RECEIVED,
// 3 = READ,
// 4 = PLAYED =
client . onAck ( ack => {
...
} ) ;
// Listen to live location
// chatId: '[email protected]'
client . onLiveLocation ( "[email protected]" , ( liveLocation ) => {
...
} ) ;
// chatId looks like this: '[email protected]'
// Event interface is in here: https://github.com/s2click/venom/blob/master/src/api/model/participant-event.ts
client . onParticipantsChanged ( "[email protected]" , ( event ) => {
...
} ) ;
// Listen when client has been added to a group
client . onAddedToGroup ( chatEvent => {
...
} ) ; //Check if there is chat
await client
. checkChat ( chatId )
. then ( ( result ) => {
console . log ( 'Result: ' , result ) ; //return object success
} )
. catch ( ( erro ) => {
console . error ( 'Error when sending: ' , erro ) ; //return object error
} ) ;
// Pin chat and Unpin chat messages with true or false
// Pin chat, non-existent (optional)
await client
. pinChat ( chatId , true , false )
. then ( ( result ) => {
console . log ( 'Result: ' , result ) ; //return object success
} )
. catch ( ( erro ) => {
console . error ( 'Error when sending: ' , erro ) ; //return object error
} ) ;
///mute a contact
await client
. sendMute (
'[email protected]' , //contact mute
30 , //duration of silence, example: 30 minutes
'minutes' ///kind of silence "hours" "minutes" "year"
)
. then ( ( result ) => {
console . log ( 'Result: ' , result ) ; //return object success
} )
. catch ( ( erro ) => {
console . error ( 'Error when sending: ' , erro ) ; //return object error
} ) ;
///unmute contact
await client
. sendMute (
'[email protected]' //contact unmute
)
. then ( ( result ) => {
console . log ( 'Result: ' , result ) ; //return object success
} )
. catch ( ( erro ) => {
console . error ( 'Error when sending: ' , erro ) ; //return object error
} ) ;
// Change the theme
// string types "dark" or "light"
await client . setTheme ( 'dark' ) ;
// Receive the current theme
// returns string light or dark
await client . getTheme ( ) ;
// Delete chat
await client . deleteChat ( '[email protected]' ) ;
// Clear chat messages
await client . clearChatMessages ( '[email protected]' ) ;
// Archive and unarchive chat messages with true or false
await client . archiveChat ( chatId , true ) ;
// Delete message (last parameter: delete only locally)
await client
. deleteMessage ( '[email protected]' , [
'[email protected]_B70847EE89E22D20FB86ECA0C1B11609' ,
'[email protected]_B70847EE89E22D20FB86ECA0C1B11777'
] )
. then ( ( result ) => {
console . log ( 'Result: ' , result ) ; //return object success
} )
. catch ( ( erro ) => {
console . error ( 'Error when sending: ' , erro ) ; //return object error
} ) ;
// Mark chat as not seen (returns true if it works)
await client . markUnseenMessage ( '[email protected]' ) ;
// Blocks a user (returns true if it works)
await client . blockContact ( '[email protected]' ) ;
// Unlocks contacts (returns true if it works)
await client . unblockContact ( '[email protected]' ) ; 有一些技巧可以更好地使用毒液。
// function to detect conflits and change status
// Force it to keep the current session
// Possible state values:
// CONFLICT
// CONNECTED
// DEPRECATED_VERSION
// OPENING
// PAIRING
// PROXYBLOCK
// SMB_TOS_BLOCK
// TIMEOUT
// TOS_BLOCK
// UNLAUNCHED
// UNPAIRED
// UNPAIRED_IDLE
client . onStateChange ( ( state ) => {
console . log ( 'State changed: ' , state ) ;
// force whatsapp take over
if ( 'CONFLICT' . includes ( state ) ) client . useHere ( ) ;
// detect disconnect on whatsapp
if ( 'UNPAIRED' . includes ( state ) ) console . log ( 'logout' ) ;
} ) ;
// DISCONNECTED
// SYNCING
// RESUMING
// CONNECTED
let time = 0 ;
client . onStreamChange ( ( state ) => {
console . log ( 'State Connection Stream: ' + state ) ;
clearTimeout ( time ) ;
if ( state === 'DISCONNECTED' || state === 'SYNCING' ) {
time = setTimeout ( ( ) => {
client . close ( ) ;
} , 80000 ) ;
}
} ) ;
// function to detect incoming call
client . onIncomingCall ( async ( call ) => {
console . log ( call ) ;
client . sendText ( call . peerJid , "Sorry, I still can't answer calls" ) ;
} ) ; 正確關閉會話,以確保在下次登錄時保存會話(因此不會再次要求QR掃描)。因此,代替ctrl+c,
// Catch ctrl+C
process . on ( 'SIGINT' , function ( ) {
client . close ( ) ;
} ) ;
// Try-catch close
try {
...
} catch ( error ) {
client . close ( ) ;
}默認情況下啟用了自動關閉,並且超時設置為60秒。收到以毫秒為單位的時間進行倒計時直至配對。
使用“ Autoclose:0 | false”來禁用自動關閉。
您可以通過傳遞webVersion參數作為毒液選項的一部分來使用WhatsApp Web的緩存版本:
venom . create ( {
session : 'sessionname' , //name of session
headless : false ,
logQR : true ,
webVersion : '2.2402.5'
} )
. then ( ( client ) => {
start ( client ) ;
} ) ;此功能可以使用列表中的任何版本
建築毒液確實很簡單,儘管它包含3個主要項目
> npm run build:wapi > npm run build:middleware
> npm run build:jsQR > npm run build:venom為了構建整個項目
> npm run build需要維護者,我不能獨自保留所有更新。如果您有興趣,請打開拉動請求。
歡迎拉動請求。對於重大更改,請先開設一個問題,以討論您想更改的內容。