Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Sending messages programmatically on web.whatsapp.com
// this allows to send arbitrary messages. The chat conversation you want to send messages to has to be open.
// just run this in the JS console
// http://stackoverflow.com/a/39165137/1249001
function findReactComponent(dom) {
for (var key in dom)
if (key.startsWith("__reactInternalInstance$")) {
var compInternals = dom[key]._currentElement;
var compWrapper = compInternals._owner;
var comp = compWrapper._instance;
return comp;
}
return null;
};
var inputComponent = findReactComponent(document.getElementsByClassName('block-compose')[0]); // get the react component for the chat input
var chat = inputComponent.props.chat;
chat.sendMessage('this is a hacky message')
@Sigurd922

This comment has been minimized.

Copy link

@Sigurd922 Sigurd922 commented May 25, 2017

THANKS! Perfect!

@Vibe6

This comment has been minimized.

Copy link

@Vibe6 Vibe6 commented Aug 8, 2017

How I will run this code?

@sevetseh28

This comment has been minimized.

Copy link

@sevetseh28 sevetseh28 commented Sep 6, 2017

Hey thanks! Btw, how can you mark the messages as seen?

@Bonke2017

This comment has been minimized.

Copy link

@Bonke2017 Bonke2017 commented Oct 14, 2017

How can i open a new chat box?

@ghost

This comment has been minimized.

Copy link

@ghost ghost commented Jan 6, 2018

how should i run this

@sevetseh28

This comment has been minimized.

Copy link

@sevetseh28 sevetseh28 commented Jan 14, 2018

Doesnt work anymore, getting Uncaught TypeError: Cannot read property '_owner' of undefined

@sayhicoelho

This comment has been minimized.

Copy link

@sayhicoelho sayhicoelho commented May 4, 2018

Does not work anymore. Getting: Uncaught TypeError: Cannot read property 'props' of null

@tinyCoder32

This comment has been minimized.

Copy link

@tinyCoder32 tinyCoder32 commented Jun 16, 2018

Hello, please is there any update for this?

@hamrammi

This comment has been minimized.

Copy link

@hamrammi hamrammi commented Aug 14, 2018

For those looking for the actual code, follow this link https://gist.github.com/nthrnth/940509123b7fe39aebc7c2942ebe227b

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