Skip to content

Instantly share code, notes, and snippets.

@yask123
Created January 24, 2015 17:08
Show Gist options
  • Select an option

  • Save yask123/d085d4b7a486d00dd103 to your computer and use it in GitHub Desktop.

Select an option

Save yask123/d085d4b7a486d00dd103 to your computer and use it in GitHub Desktop.
Send messages on whatsapp by Javascript
document.getElementsByClassName("input")[1].innerHTML="This message was written via JS script! "; // Fills the text box message
var input = document.getElementsByClassName("icon btn-icon icon-send");//Grabs the send button
input[0].click();// Clicks the send button
@ai-akash

ai-akash commented Mar 3, 2018

Copy link
Copy Markdown

update::
`function whatsAppText(t) {

window.InputEvent = window.Event || window.InputEvent;
var d = new Date();
var event = new InputEvent('input', {bubbles: true});
var textbox= document.querySelector('#main > footer > div._3oju3 > div._2bXVy > div > div._2S1VP.copyable-text.selectable-text');

textbox.textContent = t;
textbox.dispatchEvent(event);
document.querySelector("#main > footer > div._3oju3 > button > span").click();
}`

@pratik9722

pratik9722 commented Mar 31, 2018

Copy link
Copy Markdown

nothing is happening. it show only undefined

@felipsilva2

Copy link
Copy Markdown

!!!Update!!!

var y = 1;
while( y < 100) { 

	window.InputEvent = window.Event || window.InputEvent;
	var d = new Date();
	var event = new InputEvent('input', {bubbles: true});
	var textbox= document.querySelector('#main > footer > div._3oju3 > div._2bXVy > div > div._2S1VP.copyable-text.selectable-text');

	textbox.textContent = "Test";
	textbox.dispatchEvent(event);
	document.querySelector("#main > footer > div._3oju3 > button > span").click();

	console.log("Send " + i);

    y = y + 1;
}

@DMW007

DMW007 commented Apr 8, 2018

Copy link
Copy Markdown

@felipsilva2 A small logical error: console.log("Send " + i); should be console.log("Send " + y); but after changing this, it works! Thanks for sharing your snippet 👍

@diogosimao

Copy link
Copy Markdown

Hi! How might I integrate this code with WhatsApp API feature?

@wallysonn

Copy link
Copy Markdown

A maneira mais simples de enviar um texto via javascript para WhatsApp WEB é:
Store.Chat.models.find((x) => x.id == "5598911111111@c.us").sendMessage("Sua mensagem aqui");

@ClementWalter

ClementWalter commented May 12, 2018

Copy link
Copy Markdown

@wallysonn so much thanks. Works like a charm. I have used:

Store.Chat.models.find((x) => x.__x_formattedTitle === 'Contact or group name').sendMessage('A message here')

@shyambheda

Copy link
Copy Markdown

How to use this to send message to a new chat/contact no.

example: Store.Chat.models.find((x) => x.id == "919988556655@c.us").sendMessage("testing");

please help. Thanks.

@dennyphilipp

dennyphilipp commented May 25, 2018

Copy link
Copy Markdown

@webglisten @ClementWalter @wallysonn @yask123
Whatsapp web has updated and now the Store is no longer available
Is anyone still able to use the Store?
"Store.Chat.models"

Console Firefox
Store
ReferenceError: Store is not defined[Learn More]

@tinyCoder32

Copy link
Copy Markdown

@dennyphilipp not anymore, is there anyone able to reach the Store data somehow?

@tinyCoder32

Copy link
Copy Markdown

@felipsilva2 it is not working multiple times, it works only for 1 time and then stop, any idea why?

@dennyphilipp

dennyphilipp commented Jun 8, 2018

Copy link
Copy Markdown

@tinyCoder32
Just run
if (window.Store === undefined) {
webpackJsonp([], {"bcihgfbdeb": (x, y, z) => window.Store = z('"bcihgfbdeb"')}, "bcihgfbdeb");
webpackJsonp([], {"iaeeehaci": (x, y, z) => window.Store.Wap = z('"iaeeehaci"')}, "iaeeehaci");
}
console.log(window.Store);

@tinyCoder32

tinyCoder32 commented Jun 16, 2018

Copy link
Copy Markdown

thanks @dennyphilipp!
But it didn't work from my content script, only from console of browser, it says Error: Permission denied to access property "length", any idea why?

@deviance34

Copy link
Copy Markdown

how to send media ?

.sendMessage('') .sendMedia : )

@13banda

13banda commented Jul 16, 2018

Copy link
Copy Markdown

how can we send image?
because i convert image to data-url but that is not working.

@tinyCoder32

Copy link
Copy Markdown

@dennyphilipp please consider my question, thanks.

@leonanluppi

leonanluppi commented Jul 27, 2018

Copy link
Copy Markdown

For unknow contacts (contacts that I never chatted before). Any advices? This code doesn't work. @dennyphilipp @webglisten

@TonForsaken

TonForsaken commented Jul 27, 2018

Copy link
Copy Markdown

@felipsilva2 - Update!!!

        window.InputEvent = window.Event || window.InputEvent;
	var d = new Date();
	var event = new InputEvent('input', {bubbles: true});
	var textbox= document.querySelector('#main > footer >  div._3pkkz > div._1Plpp > div > div._2S1VP.copyable-text.selectable-text');

	textbox.textContent = "Test";
	textbox.dispatchEvent(event);
	document.querySelector("#main > footer > div._3pkkz > div > button > span").click();

@dennyphilipp

dennyphilipp commented Aug 27, 2018

Copy link
Copy Markdown

@tinyCoder32, @leonanluppi
Sorry for the delay, whats updated how to get the information, follow the correction of the previous script.
Store.Wap I did not find in their JS anymore.
This works via browser console, to use embedded next to some other application is necessary to inject the script together in the whats script, using something to remove the permissions, remembering that your JS needs to be hosted in some domain with https

if (window.Store === undefined) {
webpackJsonp([], {"bcihgfbdeb": (x, y, z) => window.Store = z('"bcihgfbdeb"')}, "bcihgfbdeb");
webpackJsonp([], {"jfefjijii": (x, y, z) => window.Store.Conn = z('"jfefjijii"')}, "jfefjijii");
//webpackJsonp([], {"iaeeehaci": (x, y, z) => window.Store.Wap = z('"iaeeehaci"')}, "iaeeehaci");
}

@saranshdhingra

Copy link
Copy Markdown

The latest solution of @dennyphilipp works perfectly.
I was making an extension which emulates user actions, but this method is way easy.
I wonder if this method is stable though, especially if this changes a lot.

@shyamzzp

Copy link
Copy Markdown

To send multiple just put the for loop

for(var i=0;i<10;i++){ window.InputEvent = window.Event || window.InputEvent;
var d = new Date();
var event = new InputEvent('input', {bubbles: true});
var textbox= document.querySelector('#main > footer > div._3pkkz > div._1Plpp > div > div._2S1VP.copyable-text.selectable-text');

textbox.textContent = "Test";
textbox.dispatchEvent(event);
document.querySelector("#main > footer > div._3pkkz > div > button > span").click();}

worked for me but you have open web.whatsapp for the same.

ghost commented Sep 22, 2018

Copy link
Copy Markdown

@shyamzzp Thank you~ Its worked for me

for(var i=0;i<10;i++){ window.InputEvent = window.Event || window.InputEvent;
var d = new Date();
var event = new InputEvent('input', {bubbles: true});
var textbox= document.querySelector('#main > footer > div._3pkkz > div._1Plpp > div > div._2S1VP.copyable-text.selectable-text');

textbox.textContent = "Test";
textbox.dispatchEvent(event);
document.querySelector("#main > footer > div._3pkkz > div > button > span").click();
}

@SujithReddy2907

Copy link
Copy Markdown

how to select particular group?

@rafaelxavierborges

Copy link
Copy Markdown

UPDATE:

function whatsAppText(t) { window.InputEvent = window.Event || window.InputEvent; var d = new Date(); var event = new InputEvent('input', {bubbles: true}); var textbox = $('div._2S1VP'); textbox.textContent = t; textbox.dispatchEvent(event); $("button._35EW6").click(); }

@igormuba

Copy link
Copy Markdown

UPDATE + SPAM SEND EVERY X SECONDS + MORE LEGIBLE CODE (credits to rafaelxavierborges for the skeleton of the code)
Tested on Google Chrome = does not work
Tested on Firefox = works

var t=0;                             //This is the counter, where the counting starts
var messageToSendEveryXTime;  //the is the variable that holds the message to send
messageToSendEveryXTime = t;   //in my case I want to spam counting numbers starting at zero
                                                     //if you want to send something else change here
                                                     //for example you migh want to send "I love you every second" every second

setInterval(function(){
	window.InputEvent = window.Event || window.InputEvent; 
	var d = new Date(); 
	var event = new InputEvent('input', {bubbles: true}); 
	var textbox = $('div._2S1VP'); 
	textbox.textContent = messageToSendEveryXTime;   //inserts the message in the textbox
	textbox.dispatchEvent(event); $("button._35EW6").click(); //sends the message
	t++;         //increments the counter
}, 1000); //interval to send messages, 1000= 1 second
             //choose the delay in seconds times 1000, example, 5 seconds is 5000

@igormuba

Copy link
Copy Markdown

If you are looking for a whatsapp spammer bot, I have updated it with instructions and working 29 september 2018
https://gist.github.com/igormuba/f37b8630cadbb511c53e7765de34bc6c

@fercomunello

Copy link
Copy Markdown
/**
 * 1) Open a contact or group on Whatsapp Web;
 * 2) Copy the Javascript code below;
 * 3) Open the developer tools: CTRL + SHIFT + I;
 * 4) Go to the "Console" tab and paste the code;
 * 5) The function was added on the page;
 * 6) Now, still on the console, type: spam ();
 * 7) A pop-up will be displayed requesting the spam message and
 * how many messages you want to send per second (I recommend placing 2 to 5).
 */

function spam() {
    let prompt1 = prompt("Enter the spam message", "");
    const prompt2 = prompt("Send how many messages per second?", 1);

    const input = document.getElementsByClassName("_3FRCZ")[1];
    window.InputEvent = window.Event || window.InputEvent;

    let count = 0;

    if (prompt1 === "") {
        prompt1 = "&#8203;";
    }

    console.log("Spam started ...");

    window.setInterval(function() {
        count++;

        input.innerHTML = prompt1;

        input.dispatchEvent(new InputEvent("input", {
            bubbles: true
        }));

        let enviar = document.getElementsByClassName("_1U1xa")[0];
        enviar.click();

        console.log('Messasages sent: ' + count);
    }, 1000 / prompt2);
}

@YogeshSharma01

Copy link
Copy Markdown
/**
 * 1) Open a contact or group on Whatsapp Web;
 * 2) Copy the Javascript code below;
 * 3) Open the developer tools: CTRL + SHIFT + I;
 * 4) Go to the "Console" tab and paste the code;
 * 5) The function was added on the page;
 * 6) Now, still on the console, type: spam ();
 * 7) A pop-up will be displayed requesting the spam message and
 * how many messages you want to send per second (I recommend placing 2 to 5).
 */

function spam() {
    let prompt1 = prompt("Enter the spam message", "");
    const prompt2 = prompt("Send how many messages per second?", 1);

    const input = document.getElementsByClassName("_3FRCZ")[1];
    window.InputEvent = window.Event || window.InputEvent;

    let count = 0;

    if (prompt1 === "") {
        prompt1 = "&#8203;";
    }

    console.log("Spam started ...");

    window.setInterval(function() {
        count++;

        input.innerHTML = prompt1;

        input.dispatchEvent(new InputEvent("input", {
            bubbles: true
        }));

        let enviar = document.getElementsByClassName("_1U1xa")[0];
        enviar.click();

        console.log('Messasages sent: ' + count);
    }, 1000 / prompt2);
}

It shows
Uncaught TypeError: Cannot set property 'innerHTML' of undefined
at :19:25

@a4amin

a4amin commented Mar 24, 2021

Copy link
Copy Markdown

How to send with media ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment