Readme Updated and bug removed
This commit is contained in:
parent
bfcff8ca35
commit
95458a2bc1
@ -2,29 +2,48 @@ module.exports = function(RED) {
|
|||||||
function WhatsappOut(config) {
|
function WhatsappOut(config) {
|
||||||
RED.nodes.createNode(this,config);
|
RED.nodes.createNode(this,config);
|
||||||
var node = this;
|
var node = this;
|
||||||
this.number = config.number;
|
node.number = config.number;
|
||||||
this.number = this.number.includes('@c.us') ? this.number : `${this.number}@c.us`;
|
node.number = this.number.includes('@c.us') ? this.number : `${this.number}@c.us`;
|
||||||
var whatsappLinkNode = RED.nodes.getNode(config.whatsappLink);
|
var whatsappLinkNode = RED.nodes.getNode(config.whatsappLink);
|
||||||
node.waClient = whatsappLinkNode.client;
|
node.waClient = whatsappLinkNode.client;
|
||||||
var whatsappConnectionStauts = null;
|
|
||||||
|
|
||||||
async function whatsappConnection(){
|
|
||||||
whatsappConnectionStauts = await node.waClient.getState();
|
|
||||||
};
|
|
||||||
|
|
||||||
setInterval(function(){
|
|
||||||
whatsappConnection();
|
|
||||||
if (whatsappConnectionStauts==="CONNECTED"){
|
|
||||||
node.status({fill:"green",shape:"dot",text:"Connected"})
|
|
||||||
} else {
|
|
||||||
node.status({fill:"red",shape:"dot",text:"Not Connected"})
|
|
||||||
}
|
|
||||||
},5000)
|
|
||||||
|
|
||||||
node.on('input', (message)=> {
|
node.on('input', (message)=> {
|
||||||
node.waClient.sendMessage(this.number, message.payload);
|
node.waClient.sendMessage(this.number, message.payload);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
function SetStatus(WAStatus, color){
|
||||||
|
node.status({fill:color,shape:"dot",text:WAStatus});
|
||||||
|
};
|
||||||
|
|
||||||
|
//whatsapp Status Parameters----
|
||||||
|
node.waClient.on('qr', (qr) => {
|
||||||
|
SetStatus("QR Code Generated", "yellow");
|
||||||
|
QRCode.toDataURL(qr, function(err, url){
|
||||||
|
msg = {payload : url};
|
||||||
|
node.send(msg);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
node.waClient.on('auth_failure', () => {
|
||||||
|
SetStatus('Not Connected','red');
|
||||||
|
});
|
||||||
|
|
||||||
|
node.waClient.on('loading_screen', (percentage, topic) => {
|
||||||
|
SetStatus('Connecting...','yellow');
|
||||||
|
msg.payload = percentage;
|
||||||
|
msg.topic = topic;
|
||||||
|
node.send(msg);
|
||||||
|
});
|
||||||
|
|
||||||
|
node.waClient.on('ready', () => {
|
||||||
|
SetStatus('Connected','green');
|
||||||
|
});
|
||||||
|
|
||||||
|
node.waClient.on('disconnected', () => {
|
||||||
|
SetStatus("Disconnected","red");
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
RED.nodes.registerType("whatsapp-out", WhatsappOut);
|
RED.nodes.registerType("whatsapp-out", WhatsappOut);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user