Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
function isChatMessage(message) {
if (message.__x_isSentByMe) {
return false;
}
if (message.__x_isNotification) {
return false;
}
if (!message.__x_isUserCreatedType) {
return false;
}
return true;
}
function getUnreadChats() {
var Chats = Store.Chat.models;
var Output = [];
for (chat in Chats) {
if (isNaN(chat)) {
continue;
};
var temp = {};
temp.contact = Chats[chat].__x_formattedTitle;
temp.id = Chats[chat].__x_id;
temp.messages = [];
var messages = Chats[chat].msgs.models;
for (var i = messages.length - 1; i >= 0; i--) {
if (!messages[i].__x_isNewMsg) {
break;
} else {
if (!isChatMessage(messages[i])) {
continue
}
messages[i].__x_isNewMsg = false;
temp.messages.push({
message: messages[i].__x_body,
timestamp: messages[i].__x_t,
type : messages[i].__x_type,
e : messages[i]
});
}
}
if(temp.messages.length > 0) {
Output.push(temp);
}
}
console.log("Unread messages: ", Output);
return Output;
}
function sendMsg (id, text) {
var Chats = Store.Chat.models;
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.search(contact)!=-1 && temp.id.search('g.us')==-1 ){
Chats[chat].sendMessage(message);
return true
}
}
}
@mmoreirasouza

This comment has been minimized.

Copy link

@mmoreirasouza mmoreirasouza commented Feb 21, 2018

Hi!

Do you know how to send media files like image?

Thanks!!

@Julian1104

This comment has been minimized.

Copy link

@Julian1104 Julian1104 commented Feb 23, 2018

Hi, how run in web.whatsapp.com, only paste in console?

@whatsappbot

This comment has been minimized.

Copy link

@whatsappbot whatsappbot commented Mar 27, 2018

yes @Julian1104 just paste the code in console

@qliktap

This comment has been minimized.

Copy link

@qliktap qliktap commented Apr 6, 2018

couple of bugs in the send code
__x__formattedTitle should be __x_formattedTitle
temp.id.search(contact) should be temp.contact.search(contact)

@leowidodo

This comment has been minimized.

Copy link

@leowidodo leowidodo commented May 9, 2018

Hi, can you give example for sending message ? When copy send script to console always "undefined".

@leowidodo

This comment has been minimized.

Copy link

@leowidodo leowidodo commented May 9, 2018

Sorry, I already success to send message from console. But i want to send using my application. Is it possible ?

@kaf3in0

This comment has been minimized.

Copy link

@kaf3in0 kaf3in0 commented May 12, 2018

Is it possible to inject the code from an aplication ?

@ikbalsingh

This comment has been minimized.

Copy link

@ikbalsingh ikbalsingh commented May 12, 2018

Is this a chat-bot? I mean which automatically replies in my name?
The NLP chat bot?

@nicobytes

This comment has been minimized.

Copy link

@nicobytes nicobytes commented May 25, 2018

Store is not defined
https://imgur.com/a/bwAj211

@dennyphilipp

This comment has been minimized.

Copy link

@dennyphilipp dennyphilipp commented May 25, 2018

@nicobytes @sjcotto
Here me too, Store not available, is my Firefox result
Store
ReferenceError: Store is not defined[Learn More]
You have new solution?

@john24alex

This comment has been minimized.

Copy link

@john24alex john24alex commented May 26, 2018

They just've changed all the web framework, so we should try another way, store var doesn't exist anymore.

@akhil7687

This comment has been minimized.

Copy link

@akhil7687 akhil7687 commented Jun 1, 2018

Here is a quick fix for Store is not defined
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");
}
Credit @schgressive

@bkrajendra

This comment has been minimized.

Copy link

@bkrajendra bkrajendra commented Jun 26, 2018

function sendMsg (id, text) {
    
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");
}
var Chats = Store.Chat.models;
    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.search(contact)!=-1 && temp.id.search('g.us')==-1 ){
            Chats[chat].sendMessage(message);
            return true
        }
    }    
}

Usage:

SendMsg(919922907221,"test msg")

@nerdprogrammergm

This comment has been minimized.

Copy link

@nerdprogrammergm nerdprogrammergm commented Jun 28, 2018

The above script read.js was working fine till yesterday, but from today, when I copy paste the code I get this error

progress.6aed375fd354eb3e27018f51e0f252ce.js:2 Uncaught TypeError: Cannot read property 'call' of undefined
at a (progress.6aed375fd354eb3e27018f51e0f252ce.js:2)
at Object.iaeeehaci (:3:64)
at a (progress.6aed375fd354eb3e27018f51e0f252ce.js:2)
at window.webpackJsonp (progress.6aed375fd354eb3e27018f51e0f252ce.js:2)
at :3:1

Also when I paste the code for second time, it works, loads the contents in Store.
But getUnreadChats() do not show anything even when the message is unread.
Please help.

@lucasrdrgs

This comment has been minimized.

Copy link

@lucasrdrgs lucasrdrgs commented Jul 17, 2018

How do you send an image?

@phpRajat

This comment has been minimized.

Copy link

@phpRajat phpRajat commented Jul 19, 2018

function sendMsg (id, text) {

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");
}
var Chats = Store.Chat.models;
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.search(contact)!=-1 && temp.id.search('g.us')==-1 ){
Chats[chat].sendMessage(message);
return true
}
}
}
SendMsg(91**********,"test msg")

this above code working perfectly if i send message to existing chat contact number
But if i put new mobile number which is not exist in my whatsapp chat contact list then < SendMsg(new_number,"test msg") > not working
Please help, Thank You
Thank you for sharing above code :)

@naanzitos

This comment has been minimized.

Copy link

@naanzitos naanzitos commented Jul 19, 2018

New solution:

setTimeout(function() {
// Returns promise that resolves to all installed modules
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;

//  Automatically locate modules
for (var key in modules) {
 if (modules[key].exports) {
        if (modules[key].exports.default) {
            if (modules[key].exports.default.Wap) {
                store_id = modules[key].id.replace(/"/g, '"');
            }
        }
    }
 }

}, 5000);

function _requireById(id) {
return webpackJsonp([], null, [id]);
}
// Module IDs
var store_id = 0;
var Store = {};

function init() {
 Store = _requireById(store_id).default;
 console.log("Store is ready" + Store);
}

setTimeout(function() {
 init();
}, 7000);
@phpRajat

This comment has been minimized.

Copy link

@phpRajat phpRajat commented Jul 26, 2018

For send media like image this code working for me https://gist.github.com/phpRajat/a6422922efae32914f4dbd1082f3f412

@siddhanth

This comment has been minimized.

Copy link

@siddhanth siddhanth 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

@arianpasquali

This comment has been minimized.

Copy link

@arianpasquali arianpasquali commented Nov 28, 2018

Awesome. Good job.
But how do you integrate this code with an external service?
I wrote a python server that handles input messages and answers like a bot, later I wrote an ajax call in this code to make the remote call.
However, I keep having tons of problems regarding security.
I have already tried all possible workaround I can think of with no success yet.

How do you integrate this with external sources?

@domgjntoki

This comment has been minimized.

Copy link

@domgjntoki domgjntoki commented Jan 11, 2019

If anyone is having trouble trying to remove a message for everyone in a chat, I made a script for that:
Use: deleteMessage("5************-15********@g.us", "I will be deleted")

// The chat_id is in chat.__x_id._serialized; 
window.deleteMessage = function(chat_id, msg_str) {
    if (window.Store === undefined) {
        try {  // Often this cause the error "Cannot read property 'call' of undefined" but works anyway
            webpackJsonp([], {"bcihgfbdeb": (x, y, z) => window.Store = z('"bcihgfbdeb"')}, "bcihgfbdeb");
            webpackJsonp([], {"iaeeehaci": (x, y, z) => window.Store.Wap = z('"iaeeehaci"')}, "iaeeehaci");
        } catch (e) {}
    }
    Chats = Store.Chat.models
    for(chat in Chats) {
        if (isNaN(chat)) {
            continue;
        };
        temp_id = Chats[chat].__x_id._serialized;
        if(temp_id.search(chat_id) != -1){
            messages = Chats[chat].msgs.models
            for(message in messages) {
                temp_msg = messages[message]
                if(temp_msg.__x_text == msg_str && temp_msg.canRevoke()) {
                    temp_msg.sendRevoke(temp_msg)
                    return true;
                }
            }
        }
    }
}
@techashish12

This comment has been minimized.

Copy link

@techashish12 techashish12 commented Jan 15, 2019

Temp.id.search is not a function

@thEpisode

This comment has been minimized.

Copy link

@thEpisode thEpisode commented Jan 24, 2019

Here is a quick fix for Store is not defined
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");
}
Credit @schgressive

A little update:

if (window.Store === undefined) {
    webpackJsonp([], { "bcihgfbdeb": (x, y, z) => window.Store = z('"bcihgfbdeb"') }, "bcihgfbdeb");
    webpackJsonp([], { "cbagcefdge": (x, y, z) => window.Store.Wap = z('"cbagcefdge"') }, "cbagcefdge");
  }
@Zibri

This comment has been minimized.

Copy link

@Zibri Zibri commented Feb 18, 2019

A better fix to find the Store Object:
https://github.com/Zibri/WhatsAppWebApi/blob/master/zstore.js

@Zibri

This comment has been minimized.

Copy link

@Zibri Zibri commented Feb 18, 2019

but the script errors out saying:
Uncaught TypeError: temp.id.search is not a function

@mclabman

This comment has been minimized.

Copy link

@mclabman mclabman commented Feb 20, 2019

Uncaught TypeError: temp.id.search is not a function
Change to temp.id = Chats[chat].__x_id.user;

@mclabman

This comment has been minimized.

Copy link

@mclabman mclabman commented Feb 20, 2019

And how to get received message event?

@domgjntoki

This comment has been minimized.

Copy link

@domgjntoki domgjntoki commented Jun 13, 2019

The sendMessage function in the Store.Chat.models[i].sendMessage has disappeared, has someone successfully fixed that?
The error
M433:1 Uncaught TypeError: Store.Chat.models[0].sendMessage is not a function

@sureshsarak

This comment has been minimized.

Copy link

@sureshsarak sureshsarak commented Jun 5, 2020

Store.Chat.models
Uncaught TypeError: Cannot read property 'models' of undefined

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.