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].id.replace(/"/g, '"');
}
if (modules[key].exports.prepRawMedia) {
prepareRawMedia_id = modules[key].id.replace(/"/g, '"');
}
if (modules[key].exports.default) {
if (modules[key].exports.default.Wap) {
store_id = modules[key].id.replace(/"/g, '"');
}
}
}
}
}, 2000);
function _requireById(id) {
return webpackJsonp([], null, [id]);
}
var createFromData_id = 0;
var prepareRawMedia_id = 0;
var store_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) => {
chat.markComposing();
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;
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

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.