mirror of
https://github.com/cheveguerra/whatsapp-web.js.git
synced 2026-04-20 04:29:15 +00:00
feat : Check if the given number is a whatsapp number (#54)
* feat : Check if the given number is a whatsapp number - Avoids sending message to non whatsapp number - Gets the id of the user from whatsapp server rather than generating on client
This commit is contained in:
2
package-lock.json
generated
2
package-lock.json
generated
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "whatsapp-web.js",
|
"name": "whatsapp-web.js",
|
||||||
"version": "0.3.2-post",
|
"version": "1.0.2-post",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|||||||
@@ -277,12 +277,16 @@ class Client extends EventEmitter {
|
|||||||
let msg;
|
let msg;
|
||||||
if (!chat) { // The chat is not available in the previously chatted list
|
if (!chat) { // The chat is not available in the previously chatted list
|
||||||
|
|
||||||
//todo : Check if the number is a whatsapp enabled. Whatsapp web sends query exists via ws.
|
let newChatId = await window.WWebJS.getNumberId(chatId);
|
||||||
chat = window.Store.Chat.models[0]; //get the topmost chat object and assign the new chatId to it
|
if (newChatId) {
|
||||||
let originalChatObjId = chat.id;
|
//get the topmost chat object and assign the new chatId to it .
|
||||||
chat.id = typeof originalChatObjId === 'string' ? chatId : new window.Store.UserConstructor(chatId, { intentionallyUsePrivateConstructor: true });
|
//This is just a workaround.May cause problem if there are no chats at all. Need to dig in and emulate how whatsapp web does
|
||||||
msg = await window.WWebJS.sendMessage(chat, message, options);
|
let chat = window.Store.Chat.models[0];
|
||||||
chat.id = originalChatObjId; //replace the chat with its original id
|
let originalChatObjId = chat.id;
|
||||||
|
chat.id = newChatId;
|
||||||
|
msg = await window.WWebJS.sendMessage(chat, message, options);
|
||||||
|
chat.id = originalChatObjId; //replace the chat with its original id
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
msg = await window.WWebJS.sendMessage(chat, message, options);
|
msg = await window.WWebJS.sendMessage(chat, message, options);
|
||||||
|
|||||||
@@ -25,7 +25,13 @@ exports.ExposeStore = (moduleRaidStr) => {
|
|||||||
|
|
||||||
exports.LoadUtils = () => {
|
exports.LoadUtils = () => {
|
||||||
window.WWebJS = {};
|
window.WWebJS = {};
|
||||||
|
window.WWebJS.getNumberId = async (id) => {
|
||||||
|
|
||||||
|
let result = await window.Store.Wap.queryExist(id);
|
||||||
|
if (result.jid === undefined)
|
||||||
|
throw 'The number provided is not a registered whatsapp user';
|
||||||
|
return result.jid;
|
||||||
|
};
|
||||||
window.WWebJS.sendMessage = async (chat, content, options = {}) => {
|
window.WWebJS.sendMessage = async (chat, content, options = {}) => {
|
||||||
let attOptions = {};
|
let attOptions = {};
|
||||||
if (options.attachment) {
|
if (options.attachment) {
|
||||||
|
|||||||
Reference in New Issue
Block a user