mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-18 19:59:20 +00:00
Added state monitor to wwebjs
This commit is contained in:
40
backend/controllers/wbotMonitor.js
Normal file
40
backend/controllers/wbotMonitor.js
Normal file
@@ -0,0 +1,40 @@
|
||||
const Contact = require("../models/Contact");
|
||||
const Message = require("../models/Message");
|
||||
const wbotMessageListener = require("./wbotMessageListener");
|
||||
|
||||
const path = require("path");
|
||||
const fs = require("fs");
|
||||
|
||||
const { getIO } = require("../socket");
|
||||
const { getWbot, init } = require("./wbot");
|
||||
|
||||
const wbotMonitor = () => {
|
||||
const io = getIO();
|
||||
const wbot = getWbot();
|
||||
|
||||
wbot.on("change_state", newState => {
|
||||
console.log(newState);
|
||||
});
|
||||
|
||||
wbot.on("change_battery", batteryInfo => {
|
||||
// Battery percentage for attached device has changed
|
||||
const { battery, plugged } = batteryInfo;
|
||||
console.log(`Battery: ${battery}% - Charging? ${plugged}`);
|
||||
});
|
||||
|
||||
wbot.on("disconnected", reason => {
|
||||
console.log("disconnected", reason);
|
||||
wbot.destroy();
|
||||
setTimeout(() =>
|
||||
init()
|
||||
.then(res => wbotMessageListener(), 2000)
|
||||
.catch(err => console.log(err))
|
||||
);
|
||||
});
|
||||
|
||||
// setInterval(() => {
|
||||
// wbot.resetState();
|
||||
// }, 20000);
|
||||
};
|
||||
|
||||
module.exports = wbotMonitor;
|
||||
Reference in New Issue
Block a user