Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
setTimeout(function() {
function getAllModules() {
return new Promise((resolve) => {
const id = _.uniqueId("fakeModule_");
window["webpackJsonp"](
[],
{
[id]: function(module, exports, __webpack_require__) {
resolve(__webpack_require__.c);
}
},
[id]
);
});
}
var modules = getAllModules()._value;
for (var key in modules) {
if (modules[key].exports) {
if (modules[key].exports.createFromData) {
createFromData_id = modules[key].i.replace(/"/g, '"');
}
if (modules[key].exports.prepRawMedia) {
prepareRawMedia_id = modules[key].i.replace(/"/g, '"');
}
if (modules[key].exports.default) {
if (modules[key].exports.default.Wap) {
store_id = modules[key].i.replace(/"/g, '"');
}
}
if (modules[key].exports.sendTextMsgToChat) {
chat_id = modules[key].i.replace(/"/g, '"');
}
}
}
}, 2000);
function _requireById(id) {
return webpackJsonp([], null, [id]);
}
var createFromData_id = 0;
var prepareRawMedia_id = 0;
var store_id = 0;
var chat_id = 0;
function fixBinary (bin) {
var length = bin.length;
var buf = new ArrayBuffer(length);
var arr = new Uint8Array(buf);
for (var i = 0; i < length; i++) {
arr[i] = bin.charCodeAt(i);
}
return buf;
}
var send_media;
window.send_media = function(jid, link, caption, msg_id, content_type) {
var file = "";
var createFromDataClass = _requireById(createFromData_id)["default"];
var prepareRawMediaClass = _requireById(prepareRawMedia_id).prepRawMedia;
window.Store.Chat.find(jid).then((chat) => {
var img_b64 = link;
var base64 = img_b64.split(',')[1];
var type = img_b64.split(',')[0];
type = type.split(';')[0];
type = type.split(':')[1];
var binary = fixBinary(atob(base64));
var blob = new Blob([binary], {type: type});
var random_name = Math.random().toString(36).substr(2, 5);
file = new File([blob], random_name, {
type: type,
lastModified: Date.now()
});
var temp = createFromDataClass.createFromData(file, file.type);
var rawMedia = prepareRawMediaClass(temp, {});
var target = _.filter(window.Store.Msg.models, (msg) => {
return msg.id.id === msg_id;
})[0];
var textPortion = {
caption: caption,
mentionedJidList: [],
quotedMsg: target
};
rawMedia.sendToChat(chat, textPortion);
});
}
var Store = {};
function init() {
window.Store = _requireById(store_id).default;
window.Store.sendTextMsgToChat = _requireById(chat_id).sendTextMsgToChat;
console.log("Store is ready");
console.log(window.Store);
window.send_media("91xxxxxxxxxx@c.us", "data:image/png;base64,iVBORw0KG..........sda=", "test messsage", null, null);
}
setTimeout(function() {
init();
}, 5000);
@phpRajat

This comment has been minimized.

Copy link
Owner Author

commented Jul 26, 2018

for send media use below function
window.send_media("jid", "file base64 code", "test messsage", null, null);

@NelsonGaldeman

This comment has been minimized.

Copy link

commented Jul 27, 2018

Well done!

@brnmonteiro

This comment has been minimized.

Copy link

commented Jul 30, 2018

A little doubt, how often wpp change their code to prevent this?

@humbertorodrigues

This comment has been minimized.

Copy link

commented Aug 7, 2018

You're simple THE BEST!!!

@MrKcyre

This comment has been minimized.

Copy link

commented Aug 24, 2018

Awesome code! Thanks! I was wondering if u guys know how to send a user mention..?

@Mega4alik

This comment has been minimized.

Copy link

commented Aug 27, 2018

Hello, how to use this function?

Can it be used as a separate javascript piece of code on web version of whatsapp?

Thank you

@sergio7chaccuro

This comment has been minimized.

Copy link

commented Sep 3, 2018

Sorry we get follow error when executing:
progress.73d3ea869f2050b7c85e71112ff48ab9.js:2 Uncaught TypeError: Cannot read property 'call' of undefined
at a (progress.73d3ea869f2050b7c85e71112ff48ab9.js:2)
at window.webpackJsonp (progress.73d3ea869f2050b7c85e71112ff48ab9.js:2)
at _requireById (:40:9)
at init (:95:17)
at :102:2

Could you help us?

Thanks
Regards

@siddhanth

This comment has been minimized.

Copy link

commented Sep 6, 2018

Awesome this helps. I am using this to send web link, but the preview (og-image) and all is not loading up
It just goes as a simple link, without any preview. Is there a way we can handle that as well

@Suebersson

This comment has been minimized.

Copy link

commented Sep 10, 2018

Oi boa tarde, o código funciona quando é executado dentro do console, mais quando tento executar em uma Extensão do Google chrome gera erros. Alguém pode me ajudar?

Hi good afternoon, the code works when it is saved inside the console, more when it is done in a Google chrome extension generates errors. Can someone help me?

git hub

@phpRajat

This comment has been minimized.

Copy link
Owner Author

commented Sep 24, 2018

Hello, how to use this function?

Can it be used as a separate javascript piece of code on web version of whatsapp?

Thank you

Paste this code in browser console

@Suebersson

This comment has been minimized.

Copy link

commented Oct 1, 2018

I'm trying to run the code inside a Chrome extension and it's generating errors.

Would you have a version that would run on both the console and a Chrome extension?

@apnerve

This comment has been minimized.

Copy link

commented Nov 15, 2018

This is brilliant! Can't thank you enough for this @phpRajat

@Kontr3X

This comment has been minimized.

Copy link

commented Nov 27, 2018

for example i want to kick any new member in a group instantly when he join the group from an public link that has an special number (to example +1 country Numbers) to prevent bots spam us, how can i done this? what is the kick function @phpRajat

@domgjntoki

This comment has been minimized.

Copy link

commented Jan 8, 2019

How have you discovered what the javascript functions do and work, and their args? There are so many functions in the console that I am willing to use, but and don't know how to use them

@gobiv86

This comment has been minimized.

Copy link

commented Jan 10, 2019

@phpRajat, great job! It is really useful to automate whatsapp web function via JavaScript. Thank you for the code :) is there any way, we can subscribe to event when user send message to us?

@Mirog13

This comment has been minimized.

Copy link

commented Jan 23, 2019

@phpRajat please help with the code for chrome extension

@eft0stuff

This comment has been minimized.

Copy link

commented Jan 23, 2019

it's possible to attach a PDF file ? i read the arguments in send_media() but dont full understand the link variable splits the function do.

@humbertorodrigues

This comment has been minimized.

Copy link

commented Feb 13, 2019

Any idea how can I send a message to a number which is not my contact? This way do not work

@gitanderson

This comment has been minimized.

Copy link

commented Feb 20, 2019

@phpRajat Do you know if it's possible to send VCARD in the similar way?

@keithlsp

This comment has been minimized.

Copy link

commented Feb 23, 2019

Hi, What is the meaning of "jid" , and how to get it , many thanks!!

@mosaw

This comment has been minimized.

Copy link

commented Feb 23, 2019

@humbertorodrigues
yes I can send msgs to numbers which are not my contacts
and to groups also
this is my gmail : sawyhawy@gmail.com
ytube: https://www.youtube.com/channel/UCL1JCbtI7XME89NkgqKMb3g

@phpRajat

This comment has been minimized.

Copy link
Owner Author

commented May 20, 2019

Any idea how can I send a message to a number which is not my contact? This way do not work

Here is code for send message to new contact:

Store.Contact.find("91XXXXXXXXXX@c.us").then((x) => { Store.Chat.find(x.id).then((user) => { user.sendMessage("Hi there"); }); });

And here is code to send message to existing chat:

Store.Chat.find("91XXXXXXXXXX@c.us").then((user) => { user.sendMessage("hello"); });

I hope this helps you. :)

@phpRajat

This comment has been minimized.

Copy link
Owner Author

commented May 20, 2019

Hi, What is the meaning of "jid" , and how to get it , many thanks!!

jid is contact number like if you want to send message to 919898989898 then jid is 919898989898@c.us

@phpRajat

This comment has been minimized.

Copy link
Owner Author

commented May 20, 2019

it's possible to attach a PDF file ? i read the arguments in send_media() but dont full understand the link variable splits the function do.

Hmm. I just tried with image. Actually in this function first i convert image file to base64 then convert to blob and then upload to whatsapp.
So same in pdf first you have to convert in base64 and then try this function .

Tips: base64 look like this : data:image/png;base64,iVBORw0KG..........sda=
Here you can convert file to base64 https://www.browserling.com/tools/file-to-base64

@phpRajat

This comment has been minimized.

Copy link
Owner Author

commented May 20, 2019

@phpRajat, great job! It is really useful to automate whatsapp web function via JavaScript. Thank you for the code :) is there any way, we can subscribe to event when user send message to us?

Yes you can activate listener:
Store.Msg.on('add', (newMessage) => { if (newMessage && newMessage.isNewMsg && !newMessage.isSentByMe) { console.log(newMessage); } });

@phpRajat

This comment has been minimized.

Copy link
Owner Author

commented May 20, 2019

for example i want to kick any new member in a group instantly when he join the group from an public link that has an special number (to example +1 country Numbers) to prevent bots spam us, how can i done this? what is the kick function @phpRajat

Here is simple code to remove particular participant from group:
const metaDataGroup = Store.GroupMetadata.get(idGroup);
const participant = metaDataGroup.participants.get(idParticipant);
metaDataGroup.participants.removeParticipants([participant]).then((ret)=>{ const check = metaDataGroup.participants.get(idParticipant); if (check === undefined){ done(true); return true; } done(false); return false; })

idGroup '0000000000-00000000@g.us'
idParticipant '000000000000@c.us'

@John4932

This comment has been minimized.

Copy link

commented May 27, 2019

Hi phpRajat! I noticed my WA Web has recently updated to 0.3.3321 and this is not working anymore:
Store.Chat.find("91XXXXXXXXXX@c.us").then((user) => { user.sendMessage("hello"); });
See error message below:

Screen Shot 2019-05-27 at 23 49 36

@derodevil

This comment has been minimized.

Copy link

commented May 29, 2019

Hi phpRajat! I noticed my WA Web has recently updated to 0.3.3321 and this is not working anymore:
Store.Chat.find("91XXXXXXXXXX@c.us").then((user) => { user.sendMessage("hello"); });
See error message below:

Screen Shot 2019-05-27 at 23 49 36

Did you solve this problem? I have the same problem

@dennyphilipp

This comment has been minimized.

Copy link

commented May 29, 2019

Geez, I got it.
!function () { const o = function (e) { o.mID = Math.random().toString(36).substring(7); o.mObj = {}; o.cArr = []; o.mGet = null; e ? o.debug = !0 : window.mRdebug ? o.debug = !0 : o.debug = !1; o.log = function (e) { o.debug && console.warn([moduleRaid] ${e}) }; o.args = [[[0], [function (e, n, t) { mCac = t.c; Object.keys(mCac).forEach(function (e) { o.mObj[e] = mCac[e].exports }); o.cArr = t.m; o.mGet = t }]], [[1e3], { [o.mID]: function (e, n, t) { mCac = t.c; Object.keys(mCac).forEach(function (e) { o.mObj[e] = mCac[e].exports }); o.cArr = t.m; o.mGet = t } }, [[o.mID]]]]; fillModuleArray = function () { if ("function" == typeof webpackJsonp) o.args.forEach(function (e, n) { try { webpackJsonp(...e) } catch (e) { o.log(moduleRaid.args[${n}] failed: ${e}) } }); else try { webpackJsonp.push(o.args[1]) } catch (e) { o.log(Pushing moduleRaid.args[1] into webpackJsonp failed: ${e}) } if (0 == o.mObj.length) { mEnd = !1; mIter = 0; if (!webpackJsonp([], [], [mIter])) throw Error("Unknown Webpack structure"); for (; !mEnd;)try { o.mObj[mIter] = webpackJsonp([], [], [mIter]); mIter++ } catch (o) { mEnd = !0 } } }; fillModuleArray(); get = function (e) { return o.mObj[e] }; findModule = function (e) { results = []; modules = Object.keys(o.mObj); modules.forEach(function (n) { mod = o.mObj[n]; if ("undefined" != typeof mod) { if ("object" == typeof mod.default) for (key in mod.default) key == e && results.push(mod); for (key in mod) key == e && results.push(mod) } }); return results }; findFunction = function (e) { if (0 == o.cArr.length) throw Error("No module constructors to search through!"); results = []; if ("string" == typeof e) o.cArr.forEach(function (n, t) { n.toString().includes(e) && results.push(o.mObj[t]) }); else { if ("function" != typeof e) throw new TypeError("findFunction can only find via string and function, " + typeof e + " was passed"); modules = Object.keys(o.mObj); modules.forEach(function (n, t) { mod = o.mObj[n]; e(mod) && results.push(o.mObj[t]) }) } return results }; return { modules: o.mObj, constructors: o.cArr, findModule: findModule, findFunction: findFunction, get: o.mGet ? o.mGet : get } }; "object" == typeof module && module.exports ? module.exports = o : window.mR = o(); window.Store = window.mR.findModule("Conn")[0].default }();

window.Store.SendMessage = window.mR.findModule("sendTextMsgToChat")[0].sendTextMsgToChat;
var chat = Store.Chat.models.filter(x => x.id.user === "XXXXXXX")[0];
Store.SendMessage(chat, "Hello World");

@tiagopmc

This comment has been minimized.

Copy link

commented May 30, 2019

@dennyphilipp If I wun your code on whatssapweb console I just get: Uncaught SyntaxError: missing ) after argument lis

@ghersonn

This comment has been minimized.

Copy link

commented May 30, 2019

@dennyphilipp If I wun your code on whatssapweb console I just get: Uncaught SyntaxError: missing ) after argument lis

try commenting on the content of the "catch (e)"

@btursynb

This comment has been minimized.

Copy link

commented May 30, 2019

@dennyphilipp If I wun your code on whatssapweb console I just get: Uncaught SyntaxError: missing ) after argument lis

try commenting on the content of the "catch (e)"

didn't help much, could u please give a bit of more expanded advice? Or maybe share working version of the code?

@dennyphilipp

This comment has been minimized.

Copy link

commented May 30, 2019

Guys, you have it another way.
@btursynb, @ghersonn, @tiagopmc
//exports modules
function getStore(modules) {
let foundCount = 0;
let neededObjects = [
{ id: "Store", conditions: (module) => (module.Chat && module.Msg) ? module : null },
{ id: "MediaCollection", conditions: (module) => (module.default && module.default.prototype && module.default.prototype.processFiles !== undefined) ? module.default : null },
{ id: "ChatClass", conditions: (module) => (module.default && module.default.prototype && module.default.prototype.Collection !== undefined && module.default.prototype.Collection === "Chat") ? module : null },
{ id: "MediaProcess", conditions: (module) => (module.BLOB) ? module : null },
{ id: "Wap", conditions: (module) => (module.createGroup) ? module : null },
{ id: "ServiceWorker", conditions: (module) => (module.default && module.default.killServiceWorker) ? module : null },
{ id: "State", conditions: (module) => (module.STATE && module.STREAM) ? module : null },
{ id: "WapDelete", conditions: (module) => (module.sendConversationDelete && module.sendConversationDelete.length == 2) ? module : null },
{ id: "Conn", conditions: (module) => (module.default && module.default.ref && module.default.refTTL) ? module.default : null },
{ id: "WapQuery", conditions: (module) => (module.queryExist) ? module : ((module.default && module.default.queryExist) ? module.default : null) },
{ id: "CryptoLib", conditions: (module) => (module.decryptE2EMedia) ? module : null },
{ id: "OpenChat", conditions: (module) => (module.default && module.default.prototype && module.default.prototype.openChat) ? module.default : null },
{ id: "UserConstructor", conditions: (module) => (module.default && module.default.prototype && module.default.prototype.isServer && module.default.prototype.isUser) ? module.default : null },
{ id: "SendTextMsgToChat", conditions: (module) => (module.sendTextMsgToChat) ? module.sendTextMsgToChat : null },
{ id: "SendSeen", conditions: (module) => (module.sendSeen) ? module.sendSeen : null },
{ id: "MarkSeen", conditions: (module) => (module.markSeen) ? module.markSeen : null }
];
for (let idx in modules) {
if ((typeof modules[idx] === "object") && (modules[idx] !== null)) {
let first = Object.values(modules[idx])[0];
if ((typeof first === "object") && (first.exports)) {
for (let idx2 in modules[idx]) {
let module = modules(idx2);
if (!module) {
continue;
}
neededObjects.forEach((needObj) => {
if (!needObj.conditions || needObj.foundedModule)
return;
let neededModule = needObj.conditions(module);
if (neededModule !== null) {
foundCount++;
needObj.foundedModule = neededModule;
}
});
if (foundCount == neededObjects.length) {
break;
}
}

            let neededStore = neededObjects.find((needObj) => needObj.id === "Store");
            window.Store = neededStore.foundedModule ? neededStore.foundedModule : {};
            neededObjects.splice(neededObjects.indexOf(neededStore), 1);
            neededObjects.forEach((needObj) => {
                if (needObj.foundedModule) {
                    window.Store[needObj.id] = needObj.foundedModule;
                }
            });
            window.Store.ChatClass.default.prototype.sendMessage = function (e) {
                return window.Store.SendTextMsgToChat(this, ...arguments);
            }
            return window.Store;
        }
    }
}

}

webpackJsonp([], { 'parasite': (x, y, z) => getStore(z) }, ['parasite']);
//end exports modules

var chat = Store.Chat.models.filter(x => x.id.user === "XXXXXXX")[0];
Store.SendTextMsgToChat(chat, "Hello World");

@btursynb

This comment has been minimized.

Copy link

commented May 30, 2019

//exports modules
function getStore(modules) {
let foundCount = 0;
let neededObjects = [
{ id: "Store", conditions: (module) => (module.Chat && module.Msg) ? module : null },
{ id: "MediaCollection", conditions: (module) => (module.default && module.default.prototype && module.default.prototype.processFiles !== undefined) ? module.default : null },
{ id: "ChatClass", conditions: (module) => (module.default && module.default.prototype && module.default.prototype.Collection !== undefined && module.default.prototype.Collection === "Chat") ? module : null },
{ id: "MediaProcess", conditions: (module) => (module.BLOB) ? module : null },
{ id: "Wap", conditions: (module) => (module.createGroup) ? module : null },
{ id: "ServiceWorker", conditions: (module) => (module.default && module.default.killServiceWorker) ? module : null },
{ id: "State", conditions: (module) => (module.STATE && module.STREAM) ? module : null },
{ id: "WapDelete", conditions: (module) => (module.sendConversationDelete && module.sendConversationDelete.length == 2) ? module : null },
{ id: "Conn", conditions: (module) => (module.default && module.default.ref && module.default.refTTL) ? module.default : null },
{ id: "WapQuery", conditions: (module) => (module.queryExist) ? module : ((module.default && module.default.queryExist) ? module.default : null) },
{ id: "CryptoLib", conditions: (module) => (module.decryptE2EMedia) ? module : null },
{ id: "OpenChat", conditions: (module) => (module.default && module.default.prototype && module.default.prototype.openChat) ? module.default : null },
{ id: "UserConstructor", conditions: (module) => (module.default && module.default.prototype && module.default.prototype.isServer && module.default.prototype.isUser) ? module.default : null },
{ id: "SendTextMsgToChat", conditions: (module) => (module.sendTextMsgToChat) ? module.sendTextMsgToChat : null },
{ id: "SendSeen", conditions: (module) => (module.sendSeen) ? module.sendSeen : null },
{ id: "MarkSeen", conditions: (module) => (module.markSeen) ? module.markSeen : null }
];
for (let idx in modules) {
if ((typeof modules[idx] === "object") && (modules[idx] !== null)) {
let first = Object.values(modules[idx])[0];
if ((typeof first === "object") && (first.exports)) {
for (let idx2 in modules[idx]) {
let module = modules(idx2);
if (!module) {
continue;
}
neededObjects.forEach((needObj) => {
if (!needObj.conditions || needObj.foundedModule)
return;
let neededModule = needObj.conditions(module);
if (neededModule !== null) {
foundCount++;
needObj.foundedModule = neededModule;
}
});
if (foundCount == neededObjects.length) {
break;
}
}

            let neededStore = neededObjects.find((needObj) => needObj.id === "Store");
            window.Store = neededStore.foundedModule ? neededStore.foundedModule : {};
            neededObjects.splice(neededObjects.indexOf(neededStore), 1);
            neededObjects.forEach((needObj) => {
                if (needObj.foundedModule) {
                    window.Store[needObj.id] = needObj.foundedModule;
                }
            });
            window.Store.ChatClass.default.prototype.sendMessage = function (e) {
                return window.Store.SendTextMsgToChat(this, ...arguments);
            }
            return window.Store;
        }
    }
}

}

webpackJsonp([], { 'parasite': (x, y, z) => getStore(z) }, ['parasite']);
//end exports modules

var chat = Store.Chat.models.filter(x => x.id.user === "XXXXXXX")[0];
Store.SendTextMsgToChat(chat, "Hello World");

Thank u very much!!! But I've already used the previous version. Is there any difference between these two in terms of performance?

@filipewan

This comment has been minimized.

Copy link

commented May 30, 2019

Hi everyone,

Is not working for me.

Uncaught TypeError: Cannot read property 'replace' of undefined
    at <anonymous>:29:32

The error is in this line:

		if (modules[key].exports.default) {
			if (modules[key].exports.default.Wap) {
				store_id = modules[key].id.replace(/"/g, '"');   <<-----------
			}
		}

A few days ago works just removing de replace function.... buto now dont work more!!!

Can help me?

@tinyCoder32

This comment has been minimized.

Copy link

commented May 31, 2019

for example i want to kick any new member in a group instantly when he join the group from an public link that has an special number (to example +1 country Numbers) to prevent bots spam us, how can i done this? what is the kick function @phpRajat

Here is simple code to remove particular participant from group:
const metaDataGroup = Store.GroupMetadata.get(idGroup);
const participant = metaDataGroup.participants.get(idParticipant);
metaDataGroup.participants.removeParticipants([participant]).then((ret)=>{ const check = metaDataGroup.participants.get(idParticipant); if (check === undefined){ done(true); return true; } done(false); return false; })

idGroup '0000000000-00000000@g.us'
idParticipant '000000000000@c.us'

Thanks for sharing this, how can I get the groupInviteLink please?

@phpRajat

This comment has been minimized.

Copy link
Owner Author

commented May 31, 2019

Here is my second published script and its working fine.
https://gist.github.com/phpRajat/84c0f16f9d13f362bbd73328f5a29f84

@filipewan

This comment has been minimized.

Copy link

commented May 31, 2019

Here is my second published script and its working fine.
https://gist.github.com/phpRajat/84c0f16f9d13f362bbd73328f5a29f84

Tks so much... u are the man!!!!!

but to send image is not working more?

@gresaggr

This comment has been minimized.

Copy link

commented May 31, 2019

If is it possible, please fix image sending.

@phpRajat

This comment has been minimized.

Copy link
Owner Author

commented Jun 1, 2019

@filipewan and @gresaggr

I updated my whatsapp.js file which is working fine for send image and send text message.

@gresaggr

This comment has been minimized.

Copy link

commented Jun 1, 2019

@filipewan and @gresaggr

I updated my whatsapp.js file which is working fine for send image and send text message.

Thanks! It's work perfect!

@tinyCoder32

This comment has been minimized.

Copy link

commented Jun 1, 2019

for example i want to kick any new member in a group instantly when he join the group from an public link that has an special number (to example +1 country Numbers) to prevent bots spam us, how can i done this? what is the kick function @phpRajat

Here is simple code to remove particular participant from group:
const metaDataGroup = Store.GroupMetadata.get(idGroup);
const participant = metaDataGroup.participants.get(idParticipant);
metaDataGroup.participants.removeParticipants([participant]).then((ret)=>{ const check = metaDataGroup.participants.get(idParticipant); if (check === undefined){ done(true); return true; } done(false); return false; })

idGroup '0000000000-00000000@g.us'
idParticipant '000000000000@c.us'

Hello, thank you again! is there a chance that you teach us how do we get the groupInviteLink please?

@phpRajat

This comment has been minimized.

Copy link
Owner Author

commented Jun 1, 2019

for example i want to kick any new member in a group instantly when he join the group from an public link that has an special number (to example +1 country Numbers) to prevent bots spam us, how can i done this? what is the kick function @phpRajat

Here is simple code to remove particular participant from group:
const metaDataGroup = Store.GroupMetadata.get(idGroup);
const participant = metaDataGroup.participants.get(idParticipant);
metaDataGroup.participants.removeParticipants([participant]).then((ret)=>{ const check = metaDataGroup.participants.get(idParticipant); if (check === undefined){ done(true); return true; } done(false); return false; })
idGroup '0000000000-00000000@g.us'
idParticipant '000000000000@c.us'

Hello, thank you again! is there a chance that you teach us how do we get the groupInviteLink please?

I hope so this helps u.
Store.GroupMetadata.find("0000000000-00000000@g.us").then((x) => { console.log(x.groupInviteLink); });

@Manjit2003

This comment has been minimized.

Copy link

commented Jun 1, 2019

Sir, can you please help me to use this script in a chrome extension?
Also can you please tell me how to check that if a mobile number is registered on whatsapp or no??

@derodevil

This comment has been minimized.

Copy link

commented Jun 1, 2019

Do you implement logout function?

@Manjit2003

This comment has been minimized.

Copy link

commented Jun 2, 2019

How can we send a video??

@JackieMond

This comment has been minimized.

Copy link

commented Jun 2, 2019

Hello everyone, thanks for the help so far.

I have a question, is it possible to add new contacts through the web client using the store object ?

My goal is to add a contact to the web list so i can search his Presence or status without having to add him to the phone contact list.
for my understanding it is not possible to search for a contact which is not in your contact list.
Can someone prove me wrong ?

I saw there is Store.Contact.add but i don't know the signature of the function and the parameters needed, i couldn't even monitor it since it wasn't triggered with all my tests.

I really appreciate your help

@Manjit2003

This comment has been minimized.

Copy link

commented Jun 2, 2019

Hello @JackieMond it is possible to search the presence or the status of a user.
It can be done by following these steps :

  1. Bring back the Store function :

sigalor/whatsapp-web-reveng#45 (comment)

  1. Now fetch the status of user :

var nr = 918483900678; Store.Wap.statusFind(nr + '@c.us').then(function(r){console.log(r)})

  1. Now find the presence of user :

var nr = 918483900678; Store.Presence.find(nr + '@c.us').then(function(r){console.log(r)})

Hope this might help :)

@Manjit2003

This comment has been minimized.

Copy link

commented Jun 2, 2019

Can somebody please help me to get list of all the phone contacts that are registered on whatsapp.
Any help will be appreciated.

@Manjit2003

This comment has been minimized.

Copy link

commented Jun 2, 2019

@phpRajat please help!!!!!

@tinyCoder32

This comment has been minimized.

Copy link

commented Jun 2, 2019

for example i want to kick any new member in a group instantly when he join the group from an public link that has an special number (to example +1 country Numbers) to prevent bots spam us, how can i done this? what is the kick function @phpRajat

Here is simple code to remove particular participant from group:
const metaDataGroup = Store.GroupMetadata.get(idGroup);
const participant = metaDataGroup.participants.get(idParticipant);
metaDataGroup.participants.removeParticipants([participant]).then((ret)=>{ const check = metaDataGroup.participants.get(idParticipant); if (check === undefined){ done(true); return true; } done(false); return false; })
idGroup '0000000000-00000000@g.us'
idParticipant '000000000000@c.us'

Hello, thank you again! is there a chance that you teach us how do we get the groupInviteLink please?

I hope so this helps u.
Store.GroupMetadata.find("0000000000-00000000@g.us").then((x) => { console.log(x.groupInviteLink); });

Thanks, but this didn't work, it's always null, unless I open the group myself and open the link sharing window.

@JackieMond

This comment has been minimized.

Copy link

commented Jun 3, 2019

Hello @JackieMond it is possible to search the presence or the status of a user.
It can be done by following these steps :

1. Bring back the Store function :

sigalor/whatsapp-web-reveng#45 (comment)

1. Now fetch the status of user :

var nr = 918483900678; Store.Wap.statusFind(nr + '@c.us').then(function(r){console.log(r)})

1. Now find the presence of user :

var nr = 918483900678; Store.Presence.find(nr + '@c.us').then(function(r){console.log(r)})

Hope this might help :)

The first one you indeed right.. you can search for someone Status without having him on your contact list. BUT..

for presence or profile picture you cannot.. here is the output..

  1. var nr = 918483900678; Store.Presence.find(nr + '@c.us').then(function(r){console.log(r)})
    will result
    Uncaught Error: Presence.gadd called without an id attr (id)
    at t.value (app3.c4e72dd948a018f0f168.js:2)
    at t.value (app3.c4e72dd948a018f0f168.js:2)
    at t.value (app3.c4e72dd948a018f0f168.js:2)
    at t.value (app3.c4e72dd948a018f0f168.js:2)
    at t.value (app3.c4e72dd948a018f0f168.js:2)
    at :1:16

because presence does no longer receive phone number as a parameter but whatsapp contact ID

  1. var nr = 918483900678; Store.ProfilePicThumb.find(nr + '@c.us').then(function(r){console.log(r)})
    will result
    {message: "ProfilePicThumb", name: "ModelCreateError", stack: "ModelCreateError: ProfilePicThumb↵ at t.n (http….whatsapp.com/app.7c741482fddbc756da70.js:2:6606)"

ModelCreateError because again it does something with the Model, but he cannot find the Model.

Please help.

@Manjit2003

This comment has been minimized.

Copy link

commented Jun 3, 2019

@jaderesp

This comment has been minimized.

Copy link

commented Jun 3, 2019

I tried it here, perfect, I want to thank a lot of people who keep updating this code, I was desperate with the new update depreciated, now I updated everything was perfect, thank you very much ...

@Manjit2003

This comment has been minimized.

Copy link

commented Jun 3, 2019

I think tha this script can send messages to only numbers which are in our chat list. Is it true??
Please help!!!

@jaderesp

This comment has been minimized.

Copy link

commented Jun 3, 2019

Yes so far yes, but I managed to send to other users but in a not very user and not very secure way, I did the following:

I changed the active user in the chat, and I changed the number information and sent the message normally, so after sending it is necessary to do a refresh on the screen, so I said, that is not very usual, anything I can help hug

@Manjit2003

This comment has been minimized.

Copy link

commented Jun 4, 2019

@jaderesp
Can you please send me the working code??

@jaderesp

This comment has been minimized.

Copy link

commented Jun 4, 2019

ok:

async function sendMsg(id, text,tipo, img) {
var flag_exist = get_info_contato(id);
if (window.StoreChat === undefined){
init();
}

var Chats = window.StoreChat.Chat.models;
/* se usuário não existir na lista de batepapo ou contatos, então inserir e ativar conversa para enviar mensagem */

/* set user active to chat */
if (tipo == true) {

    if(!typeof window.StoreChat.Chat.active().user === 'undefined'){

        await simulateMouseEvents(document.querySelector('._2UaNq'), 'mousedown'); 
    }

    window.StoreChat.Chat.active().user = id; 

}

    var contact = id;
    var message = text;
    for (chat in Chats) {
        if (isNaN(chat)) {
            continue;
        };
        var temp = {};
        temp.contact = Chats[chat].__x_formattedTitle;
        temp.id = Chats[chat].__x_id;
        
        if(temp.id.user == contact  && temp.id.server == 'c.us')
        {
			if(img){
				send_media(temp.id.user + '@c.us',img,message,null,null);
			}else{
			    /* Absoleto 27-05-2019 ---> Chats[chat].sendMessage(message); */
			   await msgTexto(temp.id.user + '@c.us', message);
			}

			if(tipo == true){
				refrash_lista_bpapo();
			}

            return true
        } 

        
        
    }    

}

/* simulate mouse click - refresh list contacts html wp */
async function simulateMouseEvents(element, eventName){
var mouseEvent = document.createEvent('MouseEvents');

   mouseEvent.initEvent(eventName, true, true);
  element.dispatchEvent(mouseEvent);

}

@jaderesp

This comment has been minimized.

Copy link

commented Jun 4, 2019

See if this can help ...

@ghersonn

This comment has been minimized.

Copy link

commented Jun 4, 2019

If a user sends "too many messages" (WhatsApp did not want to specify what is the limit) to people who have not saved the number of this sender in their contact lists. To avoid a suspension for this reason, the company recommends that users verify that their contacts have added their current number

How can I send bulk messages without whatsapp blocking me?

@Manjit2003

This comment has been minimized.

Copy link

commented Jun 5, 2019

@jaderesp
what if we inserted contact information in the Store object?
i.e. in window.Store.Chat
I have created the following code :
var obj = JSON.parse(Store); str = JSON.stringify(obj); obj['Chat._index'].push({"919881589589@c.us":[{"__x_id":[{"server": "c.us", "user": "919881589589", "_serialized": "919881589589@c.us"}]}]); Store = JSON.stringify(obj);
However it is giving some errors.
Could you check it for me.

@JackieMond

This comment has been minimized.

Copy link

commented Jun 5, 2019

@JackieMond
Then how does this works?
https://github.com/LoranKloeze/WhatsAllApp

@kraven5161 @phpRajat
Well.. its not working...
if you go inside you will see that the extension,
shows the following information:
Profile pictures
Status texts
Display names (for chat accounts)*
Online statuses (for chat accounts)*

What i need to find out is how to get
Display names and Online statuses without having them as chat accounts
or
how to add chat accounts without sending any message to the other side.

I hope its more clear now.

@btursynb

This comment has been minimized.

Copy link

commented Jun 5, 2019

@jaderesp @phpRajat @JackieMond
Hi, I've built a chat application that uses this code + some python code + selenium + geckodriver. And have an issue, that my firefox where web.whatsapp is open freezes when working for a long time period (a few days), and bot stops working. The workload is about 100-200 new chats every day. I archive them on a regular basis (50 chats every 6 hours). Could you please recommend me any actions to improve performance of the application? p.s. I do not send spam, working only with contacts that initiated chat first.

@ghersonn

This comment has been minimized.

Copy link

commented Jun 5, 2019

How can I send a broadcast?

@jaderesp

This comment has been minimized.

Copy link

commented Jun 5, 2019

Anyone ever tried unpacking this addContact function to see how it works, would it be to add contacts yourself?

whats inplement has params add????

window.StoreChat.Wap.addContact

@jaderesp

This comment has been minimized.

Copy link

commented Jun 5, 2019

message sent to a strange contact ...

1º step:

window.open('https://web.whatsapp.com/send?l=pt_BR&phone=5511999042948&text=good bye.', '_parent');

he will do the refrash on the screen and ask to send the message, however it is not necessary to send by clicking on the button from the moment that is made the execution of this api the contact is already in his list there only to send via script like in step 2:

2º step:

sendMsg("5511999042948","good night...");

ready message sent to a strange contact ...

I'm sending this discovery not to celebrate, but to give an understanding of how we can add the contact via code if someone finds out please send it to hug us all

@AlexDiSomma

This comment has been minimized.

Copy link

commented Jun 8, 2019

Oh my GOD! You're a Genious!!!
Could you help me with a problem? I try to launch it via eclipse with a java swing program trought the instruction
((JavascriptExecutor) driver).executeScript("script code"));

but it returns an error at this point:

var Store = {};

function init() {
window.Store = _requireById(store_id).default;
window.Store.sendTextMsgToChat = _requireById(chat_id).sendTextMsgToChat;
console.log("Store is ready");
window.Store.Chat.find("91xxxxxxxxxx@c.us").then((user) => { window.Store.sendTextMsgToChat(user, "hellao"); });
}

The error Say "unknown error: Runtime.evaluate threw exception: SyntaxError: Unexpected token var"

Do you know how to fix it?

@jaderesp

This comment has been minimized.

Copy link

commented Jun 9, 2019

where are you filling the store_id variable? one of its variables has not been defined and the Var Store or window.Store? I think you always have to use a single way

On eclipse, I use the same idea only that I use cefSharp with C # or VB.net, but the idea is the same to excuse the script inside a browser itself ... hug

@jaderesp

This comment has been minimized.

Copy link

commented Jun 9, 2019

Oh, check also the format of the string that you are executing in the browser, it is very important to send a format in order to give an error at the beginning of the script

@Manjit2003

This comment has been minimized.

Copy link

commented Jun 12, 2019

@jaderesp
I think that if we are able to insert data into Store.Chat._index then we could be able to send a message to a strange contact.
We just have to insert :
{"919881589589@c.us":[{"__x_id":[{"server": "c.us", "user": "919881589589", "_serialized": "919881589589@c.us"}]}]}
Please help me in this matter.
Any help will be appreciated.

@jaderesp

This comment has been minimized.

Copy link

commented Jun 12, 2019

I had the same perception, and I did the test and managed to send, but I added the user to the active contact like this:

note: this function makes the desired user active in chatpapo so it is possible to send message to unknown user, but need to change the status of serviceWorker :( to work

function set_user_receptive(num_){

var indice_ = window.StoreChat.Chat.models["length"];

var contact_formed = num_ + "@c.us";


/* fazer uma copia do indice anterior */
window.StoreChat.Chat.models[indice_] = window.StoreChat.Chat.models[(indice_ - 1)];
window.StoreChat.Chat.models[indice_].__x_id["user"] = num_;
window.StoreChat.Chat.models[indice_].__x_id["_serialized"] = contact_formed;

//_.extend([{"__x_id":[{"server": "c.us", "user": num_, "_serialized": contact_formed}]}]);

}

now it only works if I go in the google chrome tools and change the status of the service worker to offline, then the user appears in the list and I can send without problems if we can find that solution voilah ...

image

@jaderesp

This comment has been minimized.

Copy link

commented Jun 12, 2019

If someone can solve this problem, then yes ...

@MrSwagger1337

This comment has been minimized.

Copy link

commented Jun 12, 2019

can we delete all chats and clear whatsapp by store?

@MrSwagger1337

This comment has been minimized.

Copy link

commented Jun 12, 2019

like : -- but its not work anymore
Store.Chat.models.forEach(function(m) {
m.sendDelete();
});

@btursynb

This comment has been minimized.

Copy link

commented Jun 13, 2019

Do anybody has issues with stability of Chrome/FF when using it with Selenium? Mine freezes from time to time.

@jaderesp

This comment has been minimized.

Copy link

commented Jun 13, 2019

Does anyone have a function to send a message to the existing contact but that is not in the conversation list?

@MrSwagger1337

This comment has been minimized.

Copy link

commented Jun 13, 2019

Does anyone have a function to send a message to the existing contact but that is not in the conversation list?

i am, but you must use selenium with it

@Manjit2003

This comment has been minimized.

Copy link

commented Jun 15, 2019

@jaderesp
Insted of sending whatsapp messages using web.whatsapp.com, using YOWSUP https://github.com/tgalal/yowsup/ is also a good alternative.

@pablocorezzola

This comment has been minimized.

Copy link

commented Jun 15, 2019

This project is also very good. It's called "Sulla." https://github.com/danielcardeenas/sulla.

What is really important is in "https://github.com/danielcardeenas/sulla/blob/master/src/lib/wapi.js". I was served the window.WAPI.sendMessageToID ("number@c.us", "text") function to send messages to unknown numbers.

@Manjit2003

This comment has been minimized.

Copy link

commented Jun 15, 2019

@pablocorezzola
But how to execute the function??
Can you please help me in this case.

@pablocorezzola

This comment has been minimized.

Copy link

commented Jun 15, 2019

@pablocorezzola
But how to execute the function??
Can you please help me in this case.

Too easy.
1: just copy the entire contents of the wapi.js file into your browser's console.
2: use the function window.WAPI.sendMessageToID ("number@c.us", "text") to send messages

@Manjit2003

This comment has been minimized.

Copy link

commented Jun 15, 2019

@pablocorezzola
I have already followed the same steps. But the following error occured :
Uncaught TypeError: window.Store.UserConstructor is not a constructor at Object.window.WAPI.sendMessageToID (<anonymous>:706:62) at <anonymous>:1:13
Please check it for me.

@jaderesp

This comment has been minimized.

Copy link

commented Jun 15, 2019

@pablocorezzola
top top top, everything ready works very well, very good too ... thank you guys got right here for me at least what I needed was sending it to contacts that were not on the chat list or who had an active conversation, I've been working here parabens, good work dear friend @pablocorezzola

@jaderesp

This comment has been minimized.

Copy link

commented Jun 15, 2019

@pablocorezzola
very simple guy, just run the complete file, and call the functions by throwing the parameters you want to see:

image

@pablocorezzola

This comment has been minimized.

Copy link

commented Jun 15, 2019

@Manjit2003

This is an example of how you can use.

what

@pablocorezzola

This comment has been minimized.

Copy link

commented Jun 15, 2019

@jaderesp

Yes sir. Very simple

@jaderesp

This comment has been minimized.

Copy link

commented Jun 15, 2019

@Manjit2003
congratulations its is good works, congratulations alls
image

@jaderesp

This comment has been minimized.

Copy link

commented Jun 15, 2019

I would like to validate with you if this function that I mounted as I saw in the above files indicated by friends.
the function to check if the number is wp see and give me a return ok big hug ...

`
/* add in : 15-06-2019 - verif if contact is wp /
/
verificar se contato é wp */
async function verifIsContactWp(id){

/* window.getContact = (id) => {
        return Store.WapQuery.queryExist(id);
    } */
var result = window.getContact(id).then(contact => {
    if (contact.status === 404){

        return false;

    }else{

        return true;
            
    }
});

return result;

}`

@Manjit2003

This comment has been minimized.

Copy link

commented Jun 16, 2019

@jaderesp
@pablocorezzola

How can we chek using this that we check using this that weather a phone number is registered on whatsapp or not??
I am currently using the following query :

window.WAPI.checkNumberStatus("919881589589@c.us")

However it is always returning True.
Somebody please help.

@derodevil

This comment has been minimized.

Copy link

commented Jun 17, 2019

@Manjit2003

This is an example of how you can use.

what

Why did it return false while the message was successfully sent?

@jaderesp

This comment has been minimized.

Copy link

commented Jun 17, 2019

Could someone send a photo message to unknown contact?

@Luizcarvalho2006

This comment has been minimized.

Copy link

commented Jun 20, 2019

@jaderesp
You can first send a text message, and latter he will be in your Store.Contact or Store.Chat.

@Manjit2003

This comment has been minimized.

Copy link

commented Jun 21, 2019

@jaderesp
@Luizcarvalho2006

window.WAPI.sendImage("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8DwBwAFAgH9XSO6wwAAAABJRU5ErkJggg==" , "91XXXXXXXXXX@c.us", "Test.png", "Hello")

Would help to send photo message (Image) to a unknown contact.

@Manjit2003

This comment has been minimized.

Copy link

commented Jun 21, 2019

@jaderesp
@Luizcarvalho2006
@derodevil

Can someone guide me to check that if a phone number is registered on whatsapp or not???

@jaderesp

This comment has been minimized.

Copy link

commented Jun 22, 2019

@Manjit2003
solutions temp

@jaderesp @Luizcarvalho2006 @derodevil
Can someone guide me to check that if a phone number is registered on whatsapp or not???

@jaderesp

This comment has been minimized.

Copy link

commented Jun 22, 2019

@jaderesp @Luizcarvalho2006

window.WAPI.sendImage("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8DwBwAFAgH9XSO6wwAAAABJRU5ErkJggg==" , "91XXXXXXXXXX@c.us", "Test.png", "Hello")

Would help to send photo message (Image) to a unknown contact.

I tried to use this function to send message to strange contacts after sending text message, it sends the image but the contact does not receive, it creates a fake contact but the message does not reach the recipient

@Manjit2003

This comment has been minimized.

Copy link

commented Jun 22, 2019

@@jaderesp
I don't know why the problem is occuring in your case but you can check that you are not blocked by the recipient. As in my case i am successfully able to send images but still i am not able to send video messages
Also please help me to check that if a phone number is registered on whatsapp or not.

@derodevil

This comment has been minimized.

Copy link

commented Jun 22, 2019

I have 19 whatsapp groups. I try this code window.Store.Chat.filter((chat) => chat.isGroup && chat.groupMetadata.participants.models.length == 0) and this returns 13 groups where the paticipants models are empty. Does anynone know how to reload all participants in each group?

@Manjit2003

This comment has been minimized.

Copy link

commented Jun 23, 2019

@derodevil
Actully i cant give you the complete code but i think this might help :
Step 1
Get all group ID's by:
WAPI.getAllGroups()
This will give you an list of groups.
Step 2
Enumerate the participants by:
WAPI.getGroupParticipantIDs("XXXXXXXXXXXX-XXXXXXXXXX@g.us")
Hope this might help.
Regards.

@derodevil

This comment has been minimized.

Copy link

commented Jun 23, 2019

@Manjit2003 thanks so much, it works like a charm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.