WebWhatsapp-Wrapper
WebWhatsapp-Wrapper copied to clipboard
WAPI.sendMessageToID does not work
please help me, why sendMessageToID not work? , i can't send messages to the new number??
please help me..
same issue.
// use this code window.WAPI.sendMessageToID2 = function (id, message, done) { try { // Create user var idx = new window.Store.UserConstructor(id, {intentionallyUsePrivateConstructor: true}); // Get chat var chat = window.Store.Chat.find(idx); // Send message chat._value.sendMessage(message); } catch (e) { return false;
}
if (done !== undefined) done(false);
return false;
}; //window.WAPI.sendMessageToID2 ('[email protected]','oi');
// use this code window.WAPI.sendMessageToID2 = function (id, message, done) { try { // Create user var idx = new window.Store.UserConstructor(id, {intentionallyUsePrivateConstructor: true}); // Get chat var chat = window.Store.Chat.find(idx); // Send message chat._value.sendMessage(message); } catch (e) { return false;
} if (done !== undefined) done(false); return false;
}; //window.WAPI.sendMessageToID2 ('[email protected]','oi');
not sending on new number on which there is no chat history
// use this code window.WAPI.sendMessageToID2 = function (id, message, done) { try { // Create user var idx = new window.Store.UserConstructor(id, {intentionallyUsePrivateConstructor: true}); // Get chat var chat = window.Store.Chat.find(idx); // Send message chat._value.sendMessage(message); } catch (e) { return false;
} if (done !== undefined) done(false); return false;
}; //window.WAPI.sendMessageToID2 ('[email protected]','oi');
this was the solution I found, and the sending to new numbers is working
// use this code window.WAPI.sendMessageToID2 = function (id, message, done) { try { // Create user var idx = new window.Store.UserConstructor(id, {intentionallyUsePrivateConstructor: true}); // Get chat var chat = window.Store.Chat.find(idx); // Send message chat._value.sendMessage(message); } catch (e) { return false;
} if (done !== undefined) done(false); return false;
}; //window.WAPI.sendMessageToID2 ('[email protected]','oi');
this was the solution I found, and the sending to new numbers is working
getting this error javascript error: Unexpected token 'if'
@duzaq Please share latest wapi.js
@duzaq Please share latest wapi.js
just add below line in WAPI.sendMessageToID in try quote
var chat = window.Store.Chat.find(id); if(chat._value.sendMessage(message)){done(true);return true;}
no need of WAPI.sendMessageToID2
// use this code window.WAPI.sendMessageToID2 = function (id, message, done) { try { // Create user var idx = new window.Store.UserConstructor(id, {intentionallyUsePrivateConstructor: true}); // Get chat var chat = window.Store.Chat.find(idx); // Send message chat._value.sendMessage(message); } catch (e) { return false;
} if (done !== undefined) done(false); return false;
}; //window.WAPI.sendMessageToID2 ('[email protected]','oi');
this was the solution I found, and the sending to new numbers is working
getting this error javascript error: Unexpected token 'if'
just add below line in WAPI.sendMessageToID in try quote
var chat = window.Store.Chat.find(id); if(chat._value.sendMessage(message)){done(true);return true;}
no need of WAPI.sendMessageToID2
just add below line in WAPI.sendMessageToID in try quote
var chat = window.Store.Chat.find(id); if(chat._value.sendMessage(message)){done(true);return true;}
no need of WAPI.sendMessageToID2
this worked for me.
just add below line in WAPI.sendMessageToID in try quote
var chat = window.Store.Chat.find(id); if(chat._value.sendMessage(message)){done(true);return true;}
no need of WAPI.sendMessageToID2
It doesn't work on New id.How to resolve it?
@fly2012 I have the same problem, do u solve it?
Hello, with the code bellow i can send messages to new ids without problem. There's just one weird thing about this function that its always returns "false". But the message is sent successfuly.
window.WAPI.sendMessageToID = function (id, message, done) {
try {
window.getContact = (id) => {
return Store.WapQuery.queryExist(id);
}
window.getContact(id).then(contact => {
if (contact.status === 404) {
done(true);
} else {
if(typeof contact.jid === 'undefined') {
contact.jid = {
'_serialized' : id,
'server' : '@' + id.split('@')[1],
'user' : id.split('@')[0]
}
}
Store.FindChat.findChat(contact.jid).then(chat => {
chat.sendMessage(message);
return true;
}).catch(reject => {
if (WAPI.sendMessage(id, message)) {
done(true);
return true;
}else{
done(false);
return false;
}
});
}
});
} catch (e) {
if (window.Store.Chat.length === 0)
return false;
firstChat = Store.Chat.models[0];
var originalID = firstChat.id;
firstChat.id = typeof originalID === "string" ? id : new window.Store.UserConstructor(id, { intentionallyUsePrivateConstructor: true });
if (done !== undefined) {
firstChat.sendMessage(message).then(function () {
firstChat.id = originalID;
done(true);
});
return true;
} else {
firstChat.sendMessage(message);
firstChat.id = originalID;
return true;
}
}
if (done !== undefined) done(false);
return false;
}
Hi @ruanduarte, did u check it in whatsapp business multidevice version? Because it doesn't work to me
@santirlopez1124, no, I didn't. I'm using the normal version without multidevice. :/
I solved like this:
- Add the line with FindChat in neededObjects
if (!window.Store) {
(function () {
function getStore(modules) {
let foundCount = 0;
let neededObjects = [
...,
{ id: "FindChat", conditions: (module) => module.findChat ? module : module.default && module.default.findChat ? module.default : null }
]
....
- Replace your getChat implementation with this one
window.WAPI.getChat = function (id, done) {
// New version WhatsApp Beta Multi Device
if (WAPI.isMultiDeviceVersion()) {
let chat = window.Store.Chat.get(id);
if (chat) {
if (chat.sendMessage) {
if (done) done(chat);
return chat;
} else {
if (done) done(chat._value);
return chat._value;
}
} else {
// Create user
var idx = new window.Store.UserConstructor(id, { intentionallyUsePrivateConstructor: true });
window.Store.FindChat.findChat(idx).then(chat => {
if (done) done(chat);
}).catch(e => {
if (done) done(null);
})
return undefined;
}
} else
// Old version
{
id = typeof id == "string" ? id : id._serialized;
const found = window.Store.Chat.get(id);
found.sendMessage = (found.sendMessage) ? found.sendMessage : function () { return window.Store.sendMessage.apply(this, arguments); };
if (done !== undefined) done(found);
return found;
}
}
- This is my isMultiDeviceVersion method
window.WAPI.isMultiDeviceVersion = function () {
try {
let resp = window.Store.FeatureChecker.GK.features['MD_BACKEND'];
return resp;
} catch {
return false;
}
}
- My sendMessageToID method
window.WAPI.sendMessageToID = function (id, message, done) {
try {
// New version WhatsApp Beta
if (WAPI.isMultiDeviceVersion()) {
WAPI.getChat(id, chat => {
if (chat) {
chat.sendMessage(message);
done(true);
return true;
} else {
done(false);
return false;
}
});
} else {
// Old version of WhatsApp
try {
window.getContact = (id) => {
return Store.WapQuery.queryExist(id);
}
window.getContact(id).then(contact => {
if (contact.status === 404) {
done(true);
} else {
Store.Chat.find(contact.jid).then(chat => {
chat.sendMessage(message);
done(true);
return true;
}).catch(reject => {
if (WAPI.sendMessage(id, message)) {
done(true);
return true;
} else {
done(false);
return false;
}
});
}
});
} catch (e) {
if (window.Store.Chat.length === 0) {
done(false);
return false;
}
firstChat = Store.Chat.models[0];
var originalID = firstChat.id;
firstChat.id = typeof originalID === "string" ? id : new window.Store.UserConstructor(id, { intentionallyUsePrivateConstructor: true });
if (done !== undefined) {
firstChat.sendMessage(message).then(function () {
firstChat.id = originalID;
done(true);
});
return true;
} else {
firstChat.sendMessage(message);
firstChat.id = originalID;
done(true);
return true;
}
}
}
} catch (e) {
done(false);
return false;
}
}
Vilson ney, It worked for me! Tk you very much for your solution Did you have had any number banned after send message to new Id?
@vilsonei, hello! I tried to use the algorithm that you suggest, but I came across the fact that in all cases a message is sent, even if the number is not registered in WA. Is this how it should be, or did I make some mistake?
Vilson ney, It worked for me! Tk you very much for your solution Did you have had any number banned after send message to new Id?
Not yet! I believe that WhatsApp has lowered the sensitivity of robots in the latest version.
@vilsonei, hello! I tried to use the algorithm that you suggest, but I came across the fact that in all cases a message is sent, even if the number is not registered in WA. Is this how it should be, or did I make some mistake?
I do like this:
BWAPI.enviarMensagem = (numero, msg, resolve) => {
WAPI.checkNumberStatus(numero, data => {
// Se o status é 200 envia a mensagem
// if (data.status === 200) {
if (data && data.status === 200) {
numero = data.id._serialized;
WAPI.sendMessageToID(numero, msg, data => {
resolve(true);
})
} else
// Caso contrário tente utilizar com o nono digito
if ( numero.length < 18 ) {
let numeroNonoDigito = window.BWAPI.addNonoDigito(numero);
window.BWAPI.enviarMensagem(numeroNonoDigito, msg, resolve)
} else {
resolve(false);
}
});
}
BWAPI.addNonoDigito = (numero) => {
return numero.substring(0,4) + '9' + numero.substring(4, numero.length);
}
Vilsonei, wich version do you use as base from your script?
If is possible, could you share your complete wapi.js?
I'm trying make your changes but I thing my initial version is not the same.
Vilsonei, wich version do you use as base from your script?
If is possible, could you share your complete wapi.js?
I'm trying make your changes but I thing my initial version is not the same.
This is my lasted customized version: Link for download
There are some test codes I forgot to remove 😅
@vilsonei How can I check whether the WA account exists using this script? "Store.QueryExist.queryExist("[email protected]")" is no wrok
Receving this message when calling sendMessage sendMessage JavaScript stack: TypeError: Cannot read properties of undefined (reading 'then') at Object.window.WAPI.sendMessage (eval at executeScript
@vilsonei How can I check whether the WA account exists using this script? "Store.QueryExist.queryExist("[email protected]")" is no wrok
Yes! Try this using my custom script:
WAPI.checkNumberStatus(numero, data => {
// if status 200 send message
// if (data.status === 200) {
if (data && data.status === 200) {
numero = data.id._serialized;
WAPI.sendMessageToID(numero, msg, data => {
resolve(true);
})
} else {
resolve(false);
}
});
Receving this message when calling sendMessage sendMessage JavaScript stack: TypeError: Cannot read properties of undefined (reading 'then') at Object.window.WAPI.sendMessage (eval at executeScript
Are you using this script? See script
Hi @vilsonei I merged your script into mine, and tried to use it with multi-devices,
For some reason, after scanning the QR code, I get an error asking me if my computer has internet. I'm running it from Azure, and if I'm trying to go to another website it's obviously working.
Do you have any idea what can be the error?
Hi @vilsonei I merged your script into mine, and tried to use it with multi-devices,
For some reason, after scanning the QR code, I get an error asking me if my computer has internet. I'm running it from Azure, and if I'm trying to go to another website it's obviously working.
Do you have any idea what can be the error?
Do you see any errors in the browser's debug console?
No. I now noticed that if I delete the local storage and rescan the QR, it works, but after a restart, it happens again.
No. I now noticed that if I delete the local storage and rescan the QR, it works, but after a restart, it happens again.
You should analyze the moment you are injecting WAPI.js
WAPI.js should only be injected after WhatsApp is fully loaded so that the context variables are not lost or injected incorrectly.