Is this WAPI still working after WhatsApp Web Updated 27-29 May?
it works:
webpackJsonp([], {
"\x70\x61\x72\x61\x73\x69\x74\x65": (_0x29cax2, _0x29cax3, _0x29cax4) => window['waboxcli']['getStore'](_0x29cax4)
}, ['parasite']);
what happened with the updated ?
It's not working for me

facing the same here
with the following traceback
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python3.7/dist-packages/webwhatsapi-2.0.3-py3.7.egg/webwhatsapi/__init__.py", line 564, in send_message_to_id
return self.wapi_functions.sendMessageToID(recipient, message)
File "/usr/local/lib/python3.7/dist-packages/webwhatsapi-2.0.3-py3.7.egg/webwhatsapi/wapi_js_wrapper.py", line 44, in __getattr__
wapi_functions = dir(self)
File "/usr/local/lib/python3.7/dist-packages/webwhatsapi-2.0.3-py3.7.egg/webwhatsapi/wapi_js_wrapper.py", line 67, in __dir__
self.driver.execute_script(script.read())
File "/usr/local/lib/python3.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 636, in execute_script
'args': converted_args})['value']
File "/usr/local/lib/python3.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python3.7/dist-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.JavascriptException: Message: TypeError: e[o] is undefined
Not working here either, Store not found
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37-32\lib\site-packages\webwhatsapi-2.0.3-py3.7.egg\webwhatsapi\__init__.py", line 712, in get_battery_level
return self.wapi_functions.getBatteryLevel()
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37-32\lib\site-packages\webwhatsapi-2.0.3-py3.7.egg\webwhatsapi\wapi_js_wrapper.py", line 44, in __getattr__
wapi_functions = dir(self)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37-32\lib\site-packages\webwhatsapi-2.0.3-py3.7.egg\webwhatsapi\wapi_js_wrapper.py", line 67, in __dir__
self.driver.execute_script(script.read())
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium-4.0.0a1-py3.7.egg\selenium\webdriver\remote\webdriver.py", line 669, in execute_script
'args': converted_args})['value']
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium-4.0.0a1-py3.7.egg\selenium\webdriver\remote\webdriver.py", line 318, in execute
self.error_handler.check_response(response)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium-4.0.0a1-py3.7.egg\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.JavascriptException: Message: TypeError: window.Store is undefined
Some times throws that window.Store is undefined here too
When I try to copy wapi.js to offical web.whatsapp.com, this error is appear

A discord was set up the last time, I've just made a new invite link (former admin gone)
https://discord.gg/TF92XdJ
Add new module:
{
id: 'MessageSender',
conditions: (_0x29cax8) => (_0x29cax8['sendTextMsgToChat']) ? _0x29cax8 : null
}
And use to send message.
window.waboxstore.MessageSender.sendTextMsgToChat(chat, message);
It's still not working use your code.
Try this wapi.js file.
https://github.com/Theblood/Wapi_NEW/blob/master/wapi.js
Thanks @enomineCN I'm testing your version. The good news is that sendMessage works! But read messages or check number is not working.
@enomineCN my fault check_number_status is working too!
What are the arguments of the SendTextMsgToChat method?
window.Store.ChatClass.default.prototype.sendMessage = function (message) {
window.Store.SendTextMsgToChat(this, ..arguments);
};
@Elintondm Hello, I just updated my repository, adding the reading of new messages, if you like you can try
Tell me how to use sendseen ?
Try this wapi.js file.
https://github.com/Theblood/Wapi_NEW/blob/master/wapi.js
I have another problem.
New Wapi receives all messages.
I want to get the unread messages.
With this https://github.com/Theblood/Wapi_NEW/blob/master/wapi.js get_unread work, check_number_status and send_message. But SendSeen no.
Error:
TypeError: chat.sendSeen is not a function
Anyone knows how to define this function?
It's how to make sendSeen work
let neededObjects = [
...
{id: "SendSeen", conditions: (module) => (module.sendSeen) ? module.sendSeen : null}
];
and look at window.WAPI.sendSeen function and replace all code inside the function to this code
window.WAPI.sendSeen = function (id, done) {
var chat = window.WAPI.getChat(id);
if (chat !== undefined) {
if (done !== undefined) {
window.Store.SendSeen(chat, false);
return true;
} else {
window.Store.SendSeen(chat, false);
return true;
}
}
if (done !== undefined) done();
return false;
}
Hi, Guys. How send a message to a new chat. I did this:
Store.Chat.add({ id: new window.Store.UserConstructor(UserId)}, { merge: true, add: true, });
chtemp = Store.Chat.get(UserId);
chtemp.sendMessage("Hi");
And now how do that?
On the send message method is now returning only false. before the update, it would return true if the message was successfully sent, but now only throws false even if the message was sent on the device
promoteParticipantAdminGroup doesn't work as well...
@sidikhanrei with your code sendSeen dont work too.
For me everything works with @enomineCN wapi.js execept for sendSeen
@sidikhanrei with your code sendSeen dont work too.
For me everything works with @enomineCN wapi.js execept for sendSeen
Did you follow my instructions?
window.WAPI.sendSeen = function (id, done) {
var chat = window.WAPI.getChat(id);
if (chat !== undefined) {
if (done !== undefined) {
window.Store.SendSeen(chat, false);
return true;
} else {
window.Store.SendSeen(chat, false);
return true;
}
}
if (done !== undefined) done();
return false;
}
function sendImageFromDatabasePicBot doesn't work:
the line "msgWithImg.collection.send(msgWithImg)" return a error: Uncaught TypeError: msgWithImg.collection.send is not a function
This is the full code from @enomineCN that I modified
/* eslint-disable */
/**
* This script contains WAPI functions that need to be run in the context of the webpage
*/
/**
* Auto discovery the webpack object references of instances that contains all functions used by the WAPI
* functions and creates the Store object.
*/
/**
Repaired the function to send by id
//OLD
//var idUser = new window.Store.UserConstructor(id);
//NEW
//var idUser = new window.Store.UserConstructor(id, {intentionallyUsePrivateConstructor: true});
Filter WhatsApp
jid:user:553496802962
Status:200 Exist
window.Store.WapQuery.queryExist("[email protected]");
Status:404 Not Exist
window.Store.WapQuery.queryExist("[email protected]");
*/
if (!window.Store) {
(function () {
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}
];
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']);
})();
}
window.WAPI = {
lastRead: {}
};
window.WAPI._serializeRawObj = (obj) => {
if (obj) {
return obj.toJSON();
}
return {}
};
/**
* Serializes a chat object
*
* @param rawChat Chat object
* @returns {{}}
*/
window.WAPI._serializeChatObj = (obj) => {
if (obj == undefined) {
return null;
}
return Object.assign(window.WAPI._serializeRawObj(obj), {
kind: obj.kind,
isGroup: obj.isGroup,
contact: obj['contact'] ? window.WAPI._serializeContactObj(obj['contact']) : null,
groupMetadata: obj["groupMetadata"] ? window.WAPI._serializeRawObj(obj["groupMetadata"]) : null,
presence: obj["presence"] ? window.WAPI._serializeRawObj(obj["presence"]) : null,
msgs: null
});
};
window.WAPI._serializeContactObj = (obj) => {
if (obj == undefined) {
return null;
}
return Object.assign(window.WAPI._serializeRawObj(obj), {
formattedName: obj.formattedName,
isHighLevelVerified: obj.isHighLevelVerified,
isMe: obj.isMe,
isMyContact: obj.isMyContact,
isPSA: obj.isPSA,
isUser: obj.isUser,
isVerified: obj.isVerified,
isWAContact: obj.isWAContact,
profilePicThumbObj: obj.profilePicThumb ? WAPI._serializeProfilePicThumb(obj.profilePicThumb) : {},
statusMute: obj.statusMute,
msgs: null
});
};
window.WAPI._serializeMessageObj = (obj) => {
if (obj == undefined) {
return null;
}
return Object.assign(window.WAPI._serializeRawObj(obj), {
id: obj.id._serialized,
sender: obj["senderObj"] ? WAPI._serializeContactObj(obj["senderObj"]) : null,
timestamp: obj["t"],
content: obj["body"],
isGroupMsg: obj.isGroupMsg,
isLink: obj.isLink,
isMMS: obj.isMMS,
isMedia: obj.isMedia,
isNotification: obj.isNotification,
isPSA: obj.isPSA,
type: obj.type,
chat: WAPI._serializeChatObj(obj['chat']),
chatId: obj.id.remote,
quotedMsgObj: WAPI._serializeMessageObj(obj['_quotedMsgObj']),
mediaData: window.WAPI._serializeRawObj(obj['mediaData'])
});
};
window.WAPI._serializeNumberStatusObj = (obj) => {
if (obj == undefined) {
return null;
}
return Object.assign({}, {
id: obj.jid,
status: obj.status,
isBusiness: (obj.biz === true),
canReceiveMessage: (obj.status === 200)
});
};
window.WAPI._serializeProfilePicThumb = (obj) => {
if (obj == undefined) {
return null;
}
return Object.assign({}, {
eurl: obj.eurl,
id: obj.id,
img: obj.img,
imgFull: obj.imgFull,
raw: obj.raw,
tag: obj.tag
});
}
window.WAPI.createGroup = function (name, contactsId) {
if (!Array.isArray(contactsId)) {
contactsId = [contactsId];
}
return window.Store.Wap.createGroup(name, contactsId);
};
window.WAPI.leaveGroup = function(groupId) {
groupId = typeof groupId == "string" ? groupId : groupId._serialized;
var group = window.Store.Chat.get(groupId);
return group.sendExit()
};
window.WAPI.getAllContacts = function (done) {
const contacts = window.Store.Contact.map((contact) => WAPI._serializeContactObj(contact));
if (done !== undefined) done(contacts);
return contacts;
};
/**
* Fetches all contact objects from store, filters them
*
* @param done Optional callback function for async execution
* @returns {Array|*} List of contacts
*/
window.WAPI.getMyContacts = function (done) {
const contacts = window.Store.Contact.filter((contact) => contact.isMyContact === true).map((contact) => WAPI._serializeContactObj(contact));
if (done !== undefined) done(contacts);
return contacts;
};
/**
* Fetches contact object from store by ID
*
* @param id ID of contact
* @param done Optional callback function for async execution
* @returns {T|*} Contact object
*/
window.WAPI.getContact = function (id, done) {
const found = window.Store.Contact.get(id);
if (done !== undefined) done(window.WAPI._serializeContactObj(found))
return window.WAPI._serializeContactObj(found);
};
/**
* Fetches all chat objects from store
*
* @param done Optional callback function for async execution
* @returns {Array|*} List of chats
*/
window.WAPI.getAllChats = function (done) {
const chats = window.Store.Chat.map((chat) => WAPI._serializeChatObj(chat));
if (done !== undefined) done(chats);
return chats;
};
window.WAPI.haveNewMsg = function (chat) {
return chat.unreadCount > 0;
};
window.WAPI.getAllChatsWithNewMsg = function (done) {
const chats = window.Store.Chat.filter(window.WAPI.haveNewMsg).map((chat) => WAPI._serializeChatObj(chat));
if (done !== undefined) done(chats);
return chats;
};
/**
* Fetches all chat IDs from store
*
* @param done Optional callback function for async execution
* @returns {Array|*} List of chat id's
*/
window.WAPI.getAllChatIds = function (done) {
const chatIds = window.Store.Chat.map((chat) => chat.id._serialized || chat.id);
if (done !== undefined) done(chatIds);
return chatIds;
};
/**
* Fetches all groups objects from store
*
* @param done Optional callback function for async execution
* @returns {Array|*} List of chats
*/
window.WAPI.getAllGroups = function (done) {
const groups = window.Store.Chat.filter((chat) => chat.isGroup);
if (done !== undefined) done(groups);
return groups;
};
/**
* Fetches chat object from store by ID
*
* @param id ID of chat
* @param done Optional callback function for async execution
* @returns {T|*} Chat object
*/
window.WAPI.getChat = function (id, done) {
id = typeof id == "string" ? id : id._serialized;
const found = window.Store.Chat.get(id);
if (done !== undefined) done(found);
return found;
}
window.WAPI.getChatByName = function (name, done) {
const found = window.Store.Chat.find((chat) => chat.name === name);
if (done !== undefined) done(found);
return found;
};
window.WAPI.sendImageFromDatabasePicBot = function (picId, chatId, caption) {
var chatDatabase = window.WAPI.getChatByName('DATABASEPICBOT');
var msgWithImg = chatDatabase.msgs.find((msg) => msg.caption == picId);
if (msgWithImg === undefined) {
return false;
}
var chatSend = WAPI.getChat(chatId);
if (chatSend === undefined) {
return false;
}
const oldCaption = msgWithImg.caption;
msgWithImg.id.id = window.WAPI.getNewId();
msgWithImg.id.remote = chatId;
msgWithImg.t = Math.ceil(new Date().getTime() / 1000);
msgWithImg.to = chatId;
if (caption !== undefined && caption !== '') {
msgWithImg.caption = caption;
} else {
msgWithImg.caption = '';
}
msgWithImg.collection.send(msgWithImg).then(function (e) {
msgWithImg.caption = oldCaption;
});
return true;
};
window.WAPI.sendMessageWithThumb = function (thumb, url, title, description, chatId,done) {
var chatSend = WAPI.getChat(chatId);
if (chatSend === undefined) {
if(done!==undefined) done(false);
return false;
}
var linkPreview = {canonicalUrl: url,
description: description,
matchedText: url,
title: title,
thumbnail: thumb};
chatSend.sendMessage(url, {linkPreview: linkPreview, mentionedJidList: [], quotedMsg: null, quotedMsgAdminGroupJid: null});
if(done!==undefined) done(true);
return true;
};
window.WAPI.getNewId = function () {
var text = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for (var i = 0; i < 20; i++)
text += possible.charAt(Math.floor(Math.random() * possible.length));
return text;
};
window.WAPI.getChatById = function (id, done) {
let found = window.WAPI.getChat(id);
if (found) {
found = WAPI._serializeChatObj(found);
} else {
found = false;
}
if (done !== undefined) done(found);
return found;
};
/**
* I return all unread messages from an asked chat and mark them as read.
*
* :param id: chat id
* :type id: string
*
* :param includeMe: indicates if user messages have to be included
* :type includeMe: boolean
*
* :param includeNotifications: indicates if notifications have to be included
* :type includeNotifications: boolean
*
* :param done: callback passed by selenium
* :type done: function
*
* :returns: list of unread messages from asked chat
* :rtype: object
*/
window.WAPI.getUnreadMessagesInChat = function (id, includeMe, includeNotifications, done) {
// get chat and its messages
let chat = WAPI.getChat(id);
let messages = chat.msgs.models;
// initialize result list
let output = [];
// look for unread messages, newest is at the end of array
for (let i = messages.length - 1; i >= 0; i--)
{
// system message: skip it
if (i === "remove") {
continue;
}
// get message
let messageObj = messages[i];
// found a read message: stop looking for others
if (typeof (messageObj.__x_isUnreadType) !== "boolean" || messageObj.__x_isUnreadType === false) {
continue;
} else {
messageObj.__x_isUnreadType = false;
// process it
let message = WAPI.processMessageObj(messageObj,
includeMe,
includeNotifications);
// save processed message on result list
if (message)
output.push(message);
}
}
// callback was passed: run it
if (done !== undefined) done(output);
// return result list
return output;
}
;
/**
* Load more messages in chat object from store by ID
*
* @param id ID of chat
* @param done Optional callback function for async execution
* @returns None
*/
window.WAPI.loadEarlierMessages = function (id, done) {
const found = window.WAPI.getChat(id);
if (done !== undefined) {
found.loadEarlierMsgs().then(function () {
done()
});
} else {
found.loadEarlierMsgs();
}
};
/**
* Load more messages in chat object from store by ID
*
* @param id ID of chat
* @param done Optional callback function for async execution
* @returns None
*/
window.WAPI.loadAllEarlierMessages = function (id, done) {
const found = window.WAPI.getChat(id);
x = function () {
if (!found.msgs.msgLoadState.noEarlierMsgs) {
found.loadEarlierMsgs().then(x);
} else if (done) {
done();
}
};
x();
};
window.WAPI.asyncLoadAllEarlierMessages = function (id, done) {
done();
window.WAPI.loadAllEarlierMessages(id);
};
window.WAPI.areAllMessagesLoaded = function (id, done) {
const found = window.WAPI.getChat(id);
if (!found.msgs.msgLoadState.noEarlierMsgs) {
if (done) done(false);
return false
}
if (done) done(true);
return true
};
/**
* Load more messages in chat object from store by ID till a particular date
*
* @param id ID of chat
* @param lastMessage UTC timestamp of last message to be loaded
* @param done Optional callback function for async execution
* @returns None
*/
window.WAPI.loadEarlierMessagesTillDate = function (id, lastMessage, done) {
const found = window.WAPI.getChat(id);
x = function () {
if (found.msgs.models[0].t > lastMessage) {
found.loadEarlierMsgs().then(x);
} else {
done();
}
};
x();
};
/**
* Fetches all group metadata objects from store
*
* @param done Optional callback function for async execution
* @returns {Array|*} List of group metadata
*/
window.WAPI.getAllGroupMetadata = function (done) {
const groupData = window.Store.GroupMetadata.map((groupData) => groupData.all);
if (done !== undefined) done(groupData);
return groupData;
};
/**
* Fetches group metadata object from store by ID
*
* @param id ID of group
* @param done Optional callback function for async execution
* @returns {T|*} Group metadata object
*/
window.WAPI.getGroupMetadata = async function (id, done) {
let output = window.Store.GroupMetadata.get(id);
if (output !== undefined) {
if (output.stale) {
await output.update();
}
}
if (done !== undefined) done(output);
return output;
};
/**
* Fetches group participants
*
* @param id ID of group
* @returns {Promise.<*>} Yields group metadata
* @private
*/
window.WAPI._getGroupParticipants = async function (id) {
const metadata = await WAPI.getGroupMetadata(id);
return metadata.participants;
};
/**
* Fetches IDs of group participants
*
* @param id ID of group
* @param done Optional callback function for async execution
* @returns {Promise.<Array|*>} Yields list of IDs
*/
window.WAPI.getGroupParticipantIDs = async function (id, done) {
const output = (await WAPI._getGroupParticipants(id))
.map((participant) => participant.id);
if (done !== undefined) done(output);
return output;
};
window.WAPI.getGroupAdmins = async function (id, done) {
const output = (await WAPI._getGroupParticipants(id))
.filter((participant) => participant.isAdmin)
.map((admin) => admin.id);
if (done !== undefined) done(output);
return output;
};
/**
* Gets object representing the logged in user
*
* @returns {Array|*|$q.all}
*/
window.WAPI.getMe = function (done) {
const rawMe = window.Store.Contact.get(window.Store.Conn.me);
if (done !== undefined) done(rawMe.all);
return rawMe.all;
};
window.WAPI.isLoggedIn = function (done) {
// Contact always exists when logged in
const isLogged = window.Store.Contact && window.Store.Contact.checksum !== undefined;
if (done !== undefined) done(isLogged);
return isLogged;
};
window.WAPI.processMessageObj = function (messageObj, includeMe, includeNotifications) {
if (messageObj.isNotification) {
if (includeNotifications)
return WAPI._serializeMessageObj(messageObj);
else
return;
// System message
// (i.e. "Messages you send to this chat and calls are now secured with end-to-end encryption...")
} else if (messageObj.id.fromMe === false || includeMe) {
return WAPI._serializeMessageObj(messageObj);
}
return;
};
window.WAPI.getAllMessagesInChat = function (id, includeMe, includeNotifications, done) {
const chat = WAPI.getChat(id);
let output = [];
const messages = chat.msgs.models;
for (const i in messages) {
if (i === "remove") {
continue;
}
const messageObj = messages[i];
let message = WAPI.processMessageObj(messageObj, includeMe, includeNotifications)
if (message)
output.push(message);
}
if (done !== undefined) done(output);
return output;
};
window.WAPI.getAllMessageIdsInChat = function (id, includeMe, includeNotifications, done) {
const chat = WAPI.getChat(id);
let output = [];
const messages = chat.msgs.models;
for (const i in messages) {
if ((i === "remove")
|| (!includeMe && messages[i].isMe)
|| (!includeNotifications && messages[i].isNotification)) {
continue;
}
output.push(messages[i].id._serialized);
}
if (done !== undefined) done(output);
return output;
};
window.WAPI.getMessageById = function (id, done) {
let result = false;
try {
let msg = window.Store.Msg.get(id);
if (msg) {
result = WAPI.processMessageObj(msg, true, true);
}
} catch (err) { }
if (done !== undefined) {
done(result);
} else {
return result;
}
};
window.WAPI.ReplyMessage = function (idMessage, message, done) {
var messageObject = window.Store.Msg.get(idMessage);
if (messageObject === undefined) {
if (done !== undefined) done(false);
return false;
}
messageObject = messageObject.value();
const chat = window.Store.Chat.get(messageObject.chat.id)
if (chat !== undefined){
if (done !== undefined) {
chat.sendMessage(message, null, messageObject).then(function () {
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
var trials = 0;
function check() {
for (let i = chat.msgs.models.length - 1; i >= 0; i--) {
let msg = chat.msgs.models[i];
if (!msg.senderObj.isMe || msg.body != message) {
continue;
}
done(WAPI._serializeMessageObj(msg));
return True;
}
trials += 1;
console.log(trials);
if (trials > 30) {
done(true);
return;
}
sleep(500).then(check);
}
check();
});
return true;
} else {
chat.sendMessage(message, null, messageObject);
return true;
}
} else {
if (done !== undefined) done(false);
return false;
}
};
window.WAPI.sendMessageToID = function (id, message, done) {
try {
//OLD
//var idUser = new window.Store.UserConstructor(id);
//NEW
var idUser = new window.Store.UserConstructor(id, {intentionallyUsePrivateConstructor: true});
// create new chat
// return Store.Chat.find(idUser).then((chat) => {
// if (done !== undefined) {
// chat.sendMessage(message).then(function () {
// done(true);
// });
// return true;
//} else {
// chat.sendMessage(message);
// return true;
// }
window.getContact = ( id ) => {
return Store.WapQuery.queryExist(id)
}
window.getContact(id).then(contact => {
if(contact.status === 404){
done(true);
}else {
Store.Chat.find(contact.jid).then(chat => {
chat.sendMessage(message);
return true;
}).catch(reject => {
done(true);
});
}
});
} catch (e) {
if (window.Store.Chat.length === 0)
return false;
firstChat = Store.Chat.models[0];
var originalID = firstChat.id;
firstChat.id = typeof originalID === "string" ? id : new window.Store.UserConstructor(id, {intentionallyUsePrivateConstructor: true});
if (done !== undefined) {
firstChat.sendMessage(message).then(function () {
firstChat.id = originalID;
done(true);
});
return true;
} else {
firstChat.sendMessage(message);
firstChat.id = originalID;
return true;
}
}
if (done !== undefined) done(false);
return false;
}
window.WAPI.sendMessage = function (id, message, done) {
var chat = window.WAPI.getChat(id);
if (chat !== undefined) {
if (done !== undefined) {
chat.sendMessage(message).then(function () {
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
var trials = 0;
function check() {
for (let i = chat.msgs.models.length - 1; i >= 0; i--) {
let msg = chat.msgs.models[i];
if (!msg.senderObj.isMe || msg.body != message) {
continue;
}
done(WAPI._serializeMessageObj(msg));
return True;
}
trials += 1;
console.log(trials);
if (trials > 30) {
done(true);
return;
}
sleep(500).then(check);
}
check();
});
return true;
} else {
chat.sendMessage(message);
return true;
}
} else {
if (done !== undefined) done(false);
return false;
}
};
window.WAPI.sendMessage2 = function (id, message, done) {
var chat = window.WAPI.getChat(id);
if (chat !== undefined) {
try {
if (done !== undefined) {
chat.sendMessage(message).then(function () {
done(true);
});
} else {
chat.sendMessage(message);
}
return true;
} catch (error) {
if (done !== undefined) done(false)
return false;
}
}
if (done !== undefined) done(false)
return false;
};
window.WAPI.sendSeen = function (id, done) {
// @sidikhanrei version
var chat = window.WAPI.getChat(id);
if (chat !== undefined) {
if (done !== undefined) {
window.Store.SendSeen(chat, false);
return true;
} else {
window.Store.SendSeen(chat, false);
return true;
}
}
if (done !== undefined) done();
return false;
};
function isChatMessage(message) {
if (message.isSentByMe) {
return false;
}
if (message.isNotification) {
return false;
}
if (!message.isUserCreatedType) {
return false;
}
return true;
}
window.WAPI.getUnreadMessages = function (includeMe, includeNotifications, use_unread_count, done) {
const chats = window.Store.Chat.models;
let output = [];
for (let chat in chats) {
if (isNaN(chat)) {
continue;
}
let messageGroupObj = chats[chat];
let messageGroup = WAPI._serializeChatObj(messageGroupObj);
messageGroup.messages = [];
const messages = messageGroupObj.msgs._models;
for (let i = messages.length - 1; i >= 0; i--) {
let messageObj = messages[i];
if (typeof (messageObj.__x_isUnreadType) != "boolean" || messageObj.__x_isUnreadType === false) {
continue;
} else {
messageObj.__x_isUnreadType = false;
let message = WAPI.processMessageObj(messageObj, includeMe, includeNotifications);
if (message) {
messageGroup.messages.push(message);
}
}
}
if (messageGroup.messages.length > 0) {
output.push(messageGroup);
} else { // no messages with isNewMsg true
if (use_unread_count) {
let n = messageGroupObj.unreadCount; // will use unreadCount attribute to fetch last n messages from sender
for (let i = messages.length - 1; i >= 0; i--) {
let messageObj = messages[i];
if (n > 0) {
if (!messageObj.isSentByMe) {
let message = WAPI.processMessageObj(messageObj, includeMe, includeNotifications);
messageGroup.messages.unshift(message);
n -= 1;
}
} else if (n === -1) { // chat was marked as unread so will fetch last message as unread
if (!messageObj.isSentByMe) {
let message = WAPI.processMessageObj(messageObj, includeMe, includeNotifications);
messageGroup.messages.unshift(message);
break;
}
} else { // unreadCount = 0
break;
}
}
if (messageGroup.messages.length > 0) {
messageGroupObj.unreadCount = 0; // reset unread counter
output.push(messageGroup);
}
}
}
}
if (done !== undefined) {
done(output);
}
return output;
};
window.WAPI.getGroupOwnerID = async function (id, done) {
const output = (await WAPI.getGroupMetadata(id)).owner.id;
if (done !== undefined) {
done(output);
}
return output;
};
window.WAPI.getCommonGroups = async function (id, done) {
let output = [];
groups = window.WAPI.getAllGroups();
for (let idx in groups) {
try {
participants = await window.WAPI.getGroupParticipantIDs(groups[idx].id);
if (participants.filter((participant) => participant == id).length) {
output.push(groups[idx]);
}
} catch (err) {
console.log("Error in group:");
console.log(groups[idx]);
console.log(err);
}
}
if (done !== undefined) {
done(output);
}
return output;
};
window.WAPI.getProfilePicSmallFromId = function(id, done) {
window.Store.ProfilePicThumb.find(id).then(function(d) {
if(d.img !== undefined) {
window.WAPI.downloadFileWithCredentials(d.img, done);
} else {
done(false);
}
}, function(e) {
done(false);
})
};
window.WAPI.getProfilePicFromId = function(id, done) {
window.Store.ProfilePicThumb.find(id).then(function(d) {
if(d.imgFull !== undefined) {
window.WAPI.downloadFileWithCredentials(d.imgFull, done);
} else {
done(false);
}
}, function(e) {
done(false);
})
};
window.WAPI.downloadFileWithCredentials = function (url, done) {
let xhr = new XMLHttpRequest();
xhr.onload = function () {
if (xhr.readyState == 4) {
if (xhr.status == 200) {
let reader = new FileReader();
reader.readAsDataURL(xhr.response);
reader.onload = function (e) {
done(reader.result.substr(reader.result.indexOf(',') + 1))
};
} else {
console.error(xhr.statusText);
}
} else {
console.log(err);
done(false);
}
};
xhr.open("GET", url, true);
xhr.withCredentials = true;
xhr.responseType = 'blob';
xhr.send(null);
};
window.WAPI.downloadFile = function (url, done) {
let xhr = new XMLHttpRequest();
xhr.onload = function () {
if (xhr.readyState == 4) {
if (xhr.status == 200) {
let reader = new FileReader();
reader.readAsDataURL(xhr.response);
reader.onload = function (e) {
done(reader.result.substr(reader.result.indexOf(',') + 1))
};
} else {
console.error(xhr.statusText);
}
} else {
console.log(err);
done(false);
}
};
xhr.open("GET", url, true);
xhr.responseType = 'blob';
xhr.send(null);
};
window.WAPI.getBatteryLevel = function (done) {
if (window.Store.Conn.plugged) {
if (done !== undefined) {
done(100);
}
return 100;
}
output = window.Store.Conn.battery;
if (done !== undefined) {
done(output);
}
return output;
};
window.WAPI.deleteConversation = function (chatId, done) {
let userId = new window.Store.UserConstructor(chatId, {intentionallyUsePrivateConstructor: true});
let conversation = window.Store.Chat.get(userId);
if(!conversation) {
if(done !== undefined) {
done(false);
}
return false;
}
conversation.sendDelete().then(() => {
if (done !== undefined) {
done(true);
}
}).catch(() => {
if (done !== undefined) {
done(false);
}
});
return true;
};
window.WAPI.deleteMessage = function (chatId, messageArray, revoke=false, done) {
let userId = new window.Store.UserConstructor(chatId, {intentionallyUsePrivateConstructor: true});
let conversation = window.Store.Chat.get(userId);
if(!conversation) {
if(done !== undefined) {
done(false);
}
return false;
}
if (!Array.isArray(messageArray)) {
messageArray = [messageArray];
}
if(revoke){
conversation.sendRevokeMsgs(messageArray, conversation);
}else{
conversation.sendDeleteMsgs(messageArray, conversation);
}
if (done !== undefined) {
done(true);
}
return true;
};
window.WAPI.checkNumberStatus = function(id, done) {
window.Store.WapQuery.queryExist(id).then((result) => {
if(done !== undefined) {
if(result.jid === undefined) throw 404;
done(window.WAPI._serializeNumberStatusObj(result));
}
}).catch((e) => {
if(done !== undefined) {
done(window.WAPI._serializeNumberStatusObj({
status: e,
jid: id
}));
}
});
return true;
};
/**
* New messages observable functions.
*/
window.WAPI._newMessagesQueue = [];
window.WAPI._newMessagesBuffer = (sessionStorage.getItem('saved_msgs') != null) ?
JSON.parse(sessionStorage.getItem('saved_msgs')) : [];
window.WAPI._newMessagesDebouncer = null;
window.WAPI._newMessagesCallbacks = [];
window.Store.Msg.off('add');
sessionStorage.removeItem('saved_msgs');
window.WAPI._newMessagesListener = window.Store.Msg.on('add', (newMessage) => {
if (newMessage && newMessage.__x_isUnreadType && !newMessage.isSentByMe) {
let message = window.WAPI.processMessageObj(newMessage, false, false);
if (message) {
window.WAPI._newMessagesQueue.push(message);
window.WAPI._newMessagesBuffer.push(message);
}
// Starts debouncer time to don't call a callback for each message if more than one message arrives
// in the same second
if(!window.WAPI._newMessagesDebouncer && window.WAPI._newMessagesQueue.length > 0) {
window.WAPI._newMessagesDebouncer = setTimeout(() => {
window.WAPI._newMessagesDebouncer = null;
let queuedMessages = window.WAPI._newMessagesQueue;
window.WAPI._newMessagesQueue = [];
let removeCallbacks = [];
window.WAPI._newMessagesCallbacks.forEach(function(callbackObj) {
if(callbackObj.callback !== undefined) {
callbackObj.callback(queuedMessages);
}
if(callbackObj.rmAfterUse === true) {
removeCallbacks.push(callbackObj);
}
});
// Remove removable callbacks.
removeCallbacks.forEach(function(rmCallbackObj) {
let callbackIndex = window.WAPI._newMessagesCallbacks.indexOf(rmCallbackObj);
window.WAPI._newMessagesCallbacks.splice(callbackIndex, 1);
});
}, 1000);
}
}
});
window.WAPI._unloadInform = (event) => {
// Save in the buffer the ungot unreaded messages
window.WAPI._newMessagesBuffer.forEach((message) => {
Object.keys(message).forEach(key => message[key] === undefined ? delete message[key] : '');
});
sessionStorage.setItem("saved_msgs", JSON.stringify(window.WAPI._newMessagesBuffer));
// Inform callbacks that the page will be reloaded.
window.WAPI._newMessagesCallbacks.forEach(function(callbackObj) {
if(callbackObj.callback !== undefined) {
callbackObj.callback({status: -1, message: 'page will be reloaded, wait and register callback again.'});
}
});
};
window.addEventListener("unload", window.WAPI._unloadInform, false);
window.addEventListener("beforeunload", window.WAPI._unloadInform, false);
window.addEventListener("pageunload", window.WAPI._unloadInform, false);
/**
* Registers a callback to be called when a new message arrives the WAPI.
* @param rmCallbackAfterUse - Boolean - Specify if the callback need to be executed only once
* @param done - function - Callback function to be called when a new message arrives.
* @returns {boolean}
*/
window.WAPI.waitNewMessages = function(rmCallbackAfterUse = true, done) {
window.WAPI._newMessagesCallbacks.push({callback: done, rmAfterUse: rmCallbackAfterUse});
return true;
};
/**
* Reads buffered new messages.
* @param done - function - Callback function to be called contained the buffered messages.
* @returns {Array}
*/
window.WAPI.getBufferedNewMessages = function(done) {
let bufferedMessages = window.WAPI._newMessagesBuffer;
window.WAPI._newMessagesBuffer = [];
if(done !== undefined) {
done(bufferedMessages);
}
return bufferedMessages;
};
/** End new messages observable functions **/
window.WAPI.sendImage = function (imgBase64, chatid, filename, caption, done) {
//var idUser = new window.Store.UserConstructor(chatid);
var idUser = new window.Store.UserConstructor(chatid, {intentionallyUsePrivateConstructor: true});
// create new chat
return Store.Chat.find(idUser).then((chat) => {
var mediaBlob = window.WAPI.base64ImageToFile(imgBase64, filename);
var mc = new Store.MediaCollection();
mc.processFiles([mediaBlob], chat, 1).then(() => {
var media = mc.models[0];
media.sendToChat(chat, {caption: caption});
if (done !== undefined) done(true);
});
});
}
window.WAPI.base64ImageToFile = function (b64Data, filename) {
var arr = b64Data.split(','), mime = arr[0].match(/:(.*?);/)[1],
bstr = atob(arr[1]), n = bstr.length, u8arr = new Uint8Array(n);
while (n--) {
u8arr[n] = bstr.charCodeAt(n);
}
return new File([u8arr], filename, {type: mime});
};
/**
* Send contact card to a specific chat using the chat ids
*
* @param {string} to '[email protected]'
* @param {string|array} contact '[email protected]' | ['[email protected]', '[email protected], ... '[email protected]']
*/
window.WAPI.sendContact = function(to, contact) {
if (!Array.isArray(contact)) {
contact = [contact];
}
contact = contact.map((c) => {
return window.WAPI.getChat(c).__x_contact;
});
if (contact.length > 1) {
window.WAPI.getChat(to).sendContactList(contact);
} else if (contact.length === 1) {
window.WAPI.getChat(to).sendContact(contact[0]);
}
};
/**
* Create an chat ID based in a cloned one
*
* @param {string} chatId '[email protected]'
*/
window.WAPI.getNewMessageId = function(chatId) {
var newMsgId = Store.Msg.models[0].id.clone();
newMsgId.fromMe = true;
newMsgId.id = WAPI.getNewId().toUpperCase();
newMsgId.remote = chatId;
newMsgId._serialized = `${newMsgId.fromMe}_${newMsgId.remote}_${newMsgId.id}`
return newMsgId;
};
/**
* Send Customized VCard without the necessity of contact be a Whatsapp Contact
*
* @param {string} chatId '[email protected]'
* @param {object|array} vcard { displayName: 'Contact Name', vcard: 'BEGIN:VCARD\nVERSION:3.0\nN:;Contact Name;;;\nEND:VCARD' } | [{ displayName: 'Contact Name 1', vcard: 'BEGIN:VCARD\nVERSION:3.0\nN:;Contact Name 1;;;\nEND:VCARD' }, { displayName: 'Contact Name 2', vcard: 'BEGIN:VCARD\nVERSION:3.0\nN:;Contact Name 2;;;\nEND:VCARD' }]
*/
window.WAPI.sendVCard = function(chatId, vcard) {
var chat = Store.Chat.get(chatId);
var tempMsg = Object.create(Store.Msg.models.filter(msg => msg.__x_isSentByMe)[0]);
var newId = window.WAPI.getNewMessageId(chatId);
var extend = {
ack: 0,
id: newId,
local: !0,
self: "out",
t: parseInt(new Date().getTime() / 1000),
to: chatId,
__x_isUnreadType: !0,
};
if (Array.isArray(vcard)) {
Object.assign(extend, {
type: "multi_vcard",
vcardList: vcard
});
delete extend.body;
} else {
Object.assign(extend, {
type: "vcard",
subtype: vcard.displayName,
body: vcard.vcard
});
delete extend.vcardList;
}
Object.assign(tempMsg, extend);
chat.addAndSendMsg(tempMsg);
};
/**
* Block contact
* @param {string} id '[email protected]'
* @param {*} done - function - Callback function to be called when a new message arrives.
*/
window.WAPI.contactBlock = function(id, done){
const contact = window.Store.Contact.get(id);
if (contact !== undefined){
contact.setBlock(!0);
done(true);
return true;
}
done(false);
return false;
}
/**
* unBlock contact
* @param {string} id '[email protected]'
* @param {*} done - function - Callback function to be called when a new message arrives.
*/
window.WAPI.contactUnblock = function(id, done){
const contact = window.Store.Contact.get(id);
if (contact !== undefined){
contact.setBlock(!1);
done(true);
return true;
}
done(false);
return false;
}
/**
* Remove participant of Group
* @param {*} idGroup '[email protected]'
* @param {*} idParticipant '[email protected]'
* @param {*} done - function - Callback function to be called when a new message arrives.
*/
window.WAPI.removeParticipantGroup = function(idGroup, idParticipant, done){
const metaDataGroup = window.Store.GroupMetadata.get(idGroup);
if (metaDataGroup === undefined){
done(false); return false;
}
const participant = metaDataGroup.participants.get(idParticipant);
if (participant === undefined){
done(false); return false;
}
metaDataGroup.participants.removeParticipants([participant]).then((ret)=>{
const check = metaDataGroup.participants.get(idParticipant);
if (check === undefined){ done(true); return true; }
done(false); return false;
})
}
/**
* Promote Participant to Admin in Group
* @param {*} idGroup '[email protected]'
* @param {*} idParticipant '[email protected]'
* @param {*} done - function - Callback function to be called when a new message arrives.
*/
window.WAPI.promoteParticipantAdminGroup = function(idGroup, idParticipant, done){
const metaDataGroup = window.Store.GroupMetadata.get(idGroup);
if (metaDataGroup === undefined){
done(false); return false;
}
const participant = metaDataGroup.participants.get(idParticipant);
if (participant === undefined){
done(false); return false;
}
metaDataGroup.participants.promoteParticipants([participant]).then(()=>{
const checkParticipant = metaDataGroup.participants.get(idParticipant);
if (checkParticipant !== undefined){
if (checkParticipant.__x_isAdmin){
done(true); return true;
}
}
done(false); return false;
})
}
/**
* Demote Admin of Group
* @param {*} idGroup '[email protected]'
* @param {*} idParticipant '[email protected]'
* @param {*} done - function - Callback function to be called when a new message arrives.
*/
window.WAPI.demoteParticipantAdminGroup = function(idGroup, idParticipant, done){
const metaDataGroup = window.Store.GroupMetadata.get(idGroup);
if (metaDataGroup === undefined){
done(false); return false;
}
const participant = metaDataGroup.participants.get(idParticipant);
if (participant === undefined){
done(false); return false;
}
metaDataGroup.participants.demoteParticipants([participant]).then(()=>{
const checkParticipant = metaDataGroup.participants.get(idParticipant);
if (checkParticipant !== undefined && checkParticipant.__x_isAdmin){
done(false); return false;
}
done(true); return true;
})
}
sendSeen does not work, I already updated the code as they said it, but when using the function it is giving a timeout in the others, wait 8min.
@erickmourasilva the same to me
sendSeen does not work, I already updated the code as they said it, but when using the function it is giving a timeout in the others, wait 8min.
@erickmourasilva the same to me
Can you show the code?
@sidikhanrei
Validation code
if self.auth_count < 1:
status = self.driver.get_status()
else:
status = self.driver.is_logged_in()
#status = self.driver.get_status()
if status:
status = "LoggedIn"
else:
status = "Unknown"
def on_message_received(self, new_messages):
for message in new_messages:
try:
phone_rcp_id = message.sender.id['_serialized']
getMessage(message.content)
driver.chat_send_seen(phone_rcp_id)
are the parts necessary to understand the operation.
the seen is sent, but freezes the code later.
Error in function deleteConversation (javascript error: conversation.sendDelete is not a function
Thank you @sidikhanrei !
Everything works but the get_unread() method returns he recent today messages (not unread).
I also got the file error.
Does anyone familiar with the following error (it happens while trying to reply to a message ?
Message: Error: You should use WidFactory.createWid() instead of the Wid constructor. If you absolutely must use the constructor, pass {intentionallyUsePrivateConstructor: true} as a second parameter.
Message: Error: You should use WidFactory.createWid() instead of the Wid constructor. If you absolutely must use the constructor, pass {intentionallyUsePrivateConstructor: true} as a second parameter.
@noamb3 what function did you execute?
@sidikhanrei any fix for sendSeen?
@erickmourasilva You can try my wapi.js => https://github.com/Theblood/Wapi_NEW/blob/master/wapi.js
@Theblood, Yes, give this error.
Error in function sendSeen (javascript error: chat.sendSeen is not a function
The send_message_to_id function is always returning False, even the message being sent, before it returned True when it succeeded.
Anyone with this problem?
I also got the file error.
Does anyone familiar with the following error (it happens while trying to reply to a message ?Message: Error: You should use WidFactory.createWid() instead of the Wid constructor. If you absolutely must use the constructor, pass {intentionallyUsePrivateConstructor: true} as a second parameter.
Message: Error: You should use WidFactory.createWid() instead of the Wid constructor. If you absolutely must use the constructor, pass {intentionallyUsePrivateConstructor: true} as a second parameter.
Try to chage your code for this functions
window.WAPI.sendMessageToID = function (id, message, done) {
try {
var idUser = new window.Store.UserConstructor(id, {
intentionallyUsePrivateConstructor: true
});
// create new chat
return Store.Chat.find(idUser).then((chat) => {
if (done !== undefined) {
chat.sendMessage(message).then(function () {
done(true);
});
return true;
} else {
chat.sendMessage(message);
return true;
}
});
} catch (e) {
if (window.Store.Chat.length === 0)
return false;
firstChat = Store.Chat.models[0];
var originalID = firstChat.id;
firstChat.id = typeof originalID === "string" ? id : new window.Store.UserConstructor(id, {
intentionallyUsePrivateConstructor: true
});
if (done !== undefined) {
firstChat.sendMessage(message).then(function () {
firstChat.id = originalID;
done(true);
});
return true;
} else {
firstChat.sendMessage(message);
firstChat.id = originalID;
return true;
}
}
if (done !== undefined) done(false);
return false;
}
@sidikhanrei any fix for sendSeen?
@erickmourasilva I use this API with difference, the code is perfectly working on me. I don't know how to explain.
Pleace @sidikhanrei share all your code! I can solve it!
you can all my codes above
https://github.com/mukulhase/WebWhatsapp-Wrapper/issues/631#issuecomment-496943624
you can all my codes above
@sidikhanrei
What do you call the function? Well I'm using your wapi.js, however the error is continuing. Could you demonstrate how you are calling in python?
I'm not using in Python, I'm directly use and try it at Web.WhatsApp.com
And my applications working perfectly. I'm develop GUI Version on my own.
promoteParticipantAdminGroupdoesn't work as well...
See PR #639 for a possible solution. The API was moved to the Wap module..
Error in function deleteConversation (javascript error: conversation.sendDelete is not a function
Any Fix? Not possible to delete chats
send message to group are not working
send message to group are not working
I have no problem with it, what error shown?
Error in function deleteConversation (javascript error: conversation.sendDelete is not a function
Any Fix? Not possible to delete chats
We have to solve that!
@sidikhanrei error Showing False
Message also not Delivered to group
[email protected] this is the my group id format
WAPI.sendMessage('[email protected]', 'test')
is that code working for you? (try using real Group ID)
Using below wapi:
https://raw.githubusercontent.com/Theblood/Wapi_NEW/master/wapi.js
Error:
Traceback (most recent call last):
File "echo_observer.py", line 26, in
contact.chat.send_seen()
File "/usr/local/lib/python2.7/dist-packages/webwhatsapi-2.0.3-py2.7.egg/webwhatsapi/objects/whatsapp_object.py", line 18, in wrapped
return func(self, *args)
File "/usr/local/lib/python2.7/dist-packages/webwhatsapi-2.0.3-py2.7.egg/webwhatsapi/objects/chat.py", line 36, in send_seen
return self.driver.chat_send_seen(self.id)
File "/usr/local/lib/python2.7/dist-packages/webwhatsapi-2.0.3-py2.7.egg/webwhatsapi/__init__.py", line 602, in chat_send_seen
return self.wapi_functions.sendSeen(chat_id)
File "/usr/local/lib/python2.7/dist-packages/webwhatsapi-2.0.3-py2.7.egg/webwhatsapi/wapi_js_wrapper.py", line 137, in __call__
raise JsException("Error in function {0} ({1}). Command: {2}".format(self.function_name, e.msg, command))
webwhatsapi.wapi_js_wrapper.JsException: Error in function sendSeen (TypeError: chat.sendSeen is not a function). Command: return WAPI.sendSeen('[email protected]', arguments[0])
@sidikhanrei thanks its work
@sidikhanrei how i solve delete chat error?
@sidikhanrei
Validation code
if self.auth_count < 1: status = self.driver.get_status() else: status = self.driver.is_logged_in() #status = self.driver.get_status() if status: status = "LoggedIn" else: status = "Unknown"def on_message_received(self, new_messages):
for message in new_messages:
try:
phone_rcp_id = message.sender.id['_serialized']
getMessage(message.content)
driver.chat_send_seen(phone_rcp_id)are the parts necessary to understand the operation.
the seen is sent, but freezes the code later.
Same here, the code is freeze after sendSeen.
The sendSeen method doesn't work anymore, the wapi.js file calls sendSeen on a window.Store.Chat object and apparently this method was removed from the Chat object.
window.WAPI.sendSeen = function (id, done) {
var chat = window.WAPI.getChat(id);
if (chat !== undefined) {
if (done !== undefined) {
chat.sendSeen(false).then(function () {
done(true);
});
return true;
} else {
chat.sendSeen(false);
return true;
}
}
if (done !== undefined) done();
return false;
};
The
sendSeenmethod doesn't work anymore, the wapi.js file calls sendSeen on a window.Store.Chat object and apparently this method was removed from the Chat object.window.WAPI.sendSeen = function (id, done) { var chat = window.WAPI.getChat(id); if (chat !== undefined) { if (done !== undefined) { chat.sendSeen(false).then(function () { done(true); }); return true; } else { chat.sendSeen(false); return true; } } if (done !== undefined) done(); return false; };
This is the fix, replace for this function:
window.WAPI.sendSeen = function (id, done) {
var chat = window.WAPI.getChat(id);
if (chat !== undefined) {
if (done !== undefined) {
Store.SendSeen(Store.Chat.models[0], false).then(function () {
done(true);
});
return true;
} else {
Store.SendSeen(Store.Chat.models[0], false);
return true;
}
}
if (done !== undefined) done();
return false;
};
@kaykyr you have a fix to delete conversations?
Algumas das soluções acima ja reslveu problema por completo meu ainda não Loga com QR code
Please Guys, some solution to fix window.WAPI.sendImageFromDatabasePicBot?
window.WAPI.sendSeen = function (id, done) {
var chat = window.WAPI.getChat(id);
if (chat !== undefined) {
if (done !== undefined) {
Store.SendSeen(Store.Chat.models[0], false).then(function () {
done(true);
});
return true;
} else {
Store.SendSeen(Store.Chat.models[0], false);
return true;
}
}
if (done !== undefined) done();
return false;
};
I think better to use this code to select chat dynamically using id
window.WAPI.sendSeen = function (id, done) {
var chat = window.WAPI.getChat(id);
if (chat !== undefined) {
if (done !== undefined) {
Store.SendSeen(chat, false).then(function () {
done(true);
});
return true;
} else {
Store.SendSeen(chat, false);
return true;
}
}
if (done !== undefined) done();
return false;
};
window.WAPI.sendSeen = function (id, done) {
var chat = window.WAPI.getChat(id);
if (chat !== undefined) {
if (done !== undefined) {
Store.SendSeen(Store.Chat.models[0], false).then(function () {
done(true);
});
return true;
} else {
Store.SendSeen(Store.Chat.models[0], false);
return true;
}
}
if (done !== undefined) done();
return false;
};I think better to use this code to select chat dynamically using id
window.WAPI.sendSeen = function (id, done) { var chat = window.WAPI.getChat(id); if (chat !== undefined) { if (done !== undefined) { Store.SendSeen(chat, false).then(function () { done(true); }); return true; } else { Store.SendSeen(chat, false); return true; } } if (done !== undefined) done(); return false; };
Correct! This is better!
@kaykyr you have a fix to delete conversations?
Have you ever tried this?
window.WAPI.deleteMessage = function (chatId, messageArray, revoke=false, done) {
let userId = new window.Store.UserConstructor(chatId, {intentionallyUsePrivateConstructor: true});
let conversation = window.Store.Chat.get(userId);
if(!conversation) {
if(done !== undefined) {
done(false);
}
return false;
}
if (!Array.isArray(messageArray)) {
messageArray = [messageArray];
}
if(revoke){
conversation.sendRevokeMsgs(messageArray, conversation);
}else{
conversation.sendDeleteMsgs(messageArray, conversation);
}
if (done !== undefined) {
done(true);
}
return true;
};
window.WAPI.deleteMessage = function (chatId, messageArray, revoke=false, done) { let userId = new window.Store.UserConstructor(chatId, {intentionallyUsePrivateConstructor: true}); let conversation = window.Store.Chat.get(userId); if(!conversation) { if(done !== undefined) { done(false); } return false; } if (!Array.isArray(messageArray)) { messageArray = [messageArray]; } if(revoke){ conversation.sendRevokeMsgs(messageArray, conversation); }else{ conversation.sendDeleteMsgs(messageArray, conversation); } if (done !== undefined) { done(true); } return true; };
@kaykyr this delete messages, not chat
This complete js file is on this pull request: #641
This complete js file is on this pull request: #641
This complete js file is on this pull request: #641
I have this complete js file, but give error: Error in function deleteConversation (javascript error: conversation.sendDelete is not a function
I used the complete js file, but I have this new issue now:
nERROR: Message: Cyclic object value
Anybody else with problem for sending messages?
Has anyone else noticed that get_unread now returns all messages instead of just new unread ones?
I've switched to adding a 'sendSeen' but I'm getting this error when doing that:
=> driver.chat_send_seen(message.chat_id)
JsException: Error in function sendSeen (SyntaxError: missing : after property id). Command: return WAPI.sendSeen({u'user': u'xxxxx', u'_serialized': u'[email protected]', u'server': u'c.us'}, arguments[0])
@Skowt you are right. I have noticed too.
Now get_unread return all messages and this is a problem for my aplication.
Anyone fixed deleteConversation?
Updated with the latest PR and still having problem with send message.he sends the message, but returns false.i cant confirm if the message was sent and get the id.
Please Guys, some solution to fix window.WAPI.createGroup?
@Elintondm Testing my wapi.js => https://github.com/Theblood/Wapi_NEW/blob/master/wapi.js
createGroup return this error:
app.383a0543b86498c5919e.js:2 Uncaught TypeError: Cannot read property 'map' of undefined
at r (app.383a0543b86498c5919e.js:2)
at Object.i [as createGroup] (app.383a0543b86498c5919e.js:2)
at Object.window.WAPI.createGroup (
at
I`ve fixed it!


Error in function deleteConversation (javascript error: conversation.sendDelete is not a function
Any Fix? Not possible to delete chats
Fixed!
Send message to id always return false, i need som help please!
I`ve fixed it!
Can you make a pull request with the solution?
@Skowt you are right. I have noticed too.
Now get_unread return all messages and this is a problem for my aplication.
Any idea how to fix it guys ?
I also found unstable behavior regarding the get_unread function
Thanks
FIXED by Theblood. Thanks a lot!
I`ve fixed it!
Can you make a pull request with the solution?
mm, the solution throws me this error, I have a question, what is wpp?
I`ve fixed it!
Can you make a pull request with the solution?
mm, the solution throws me this error, I have a question, what is wpp?
I have a custom aplication.
The FT.Wpp.Store is my JavaScript var.
Change it to window.Store.sendDelete(conversation, false)
I`ve fixed it!
Can you make a pull request with the solution?
mm, the solution throws me this error, I have a question, what is wpp?
I have a custom aplication.
The FT.Wpp.Store is my JavaScript var.
Change it to window.Store.sendDelete(conversation, false)
This delete chat in web only, not in app
I`ve fixed it!
Can you make a pull request with the solution?
mm, the solution throws me this error, I have a question, what is wpp?
I have a custom aplication.
The FT.Wpp.Store is my JavaScript var.
Change it to window.Store.sendDelete(conversation, false)This delete chat in web only, not in app
For me it worked well.
Deleted the conversations from web and app.
I`ve fixed it!
Can you make a pull request with the solution?
mm, the solution throws me this error, I have a question, what is wpp?
I have a custom aplication.
The FT.Wpp.Store is my JavaScript var.
Change it to window.Store.sendDelete(conversation, false)This delete chat in web only, not in app
For me it worked well.
Deleted the conversations from web and app.
Works for me too! Can you share the complete code?
I`ve fixed it!
Can you make a pull request with the solution?
mm, the solution throws me this error, I have a question, what is wpp?
the solution works fine for me, thanks
testing Delete Update Wapi.js => https://github.com/Theblood/Wapi_NEW/blob/master/wapi.js
testing Delete Update Wapi.js => https://github.com/Theblood/Wapi_NEW/blob/master/wapi.js
I'm getting:
Cannot read property 'sendDelete' of undefined
when I call WAPI.deleteConversation(id)
testing Delete Update Wapi.js => https://github.com/Theblood/Wapi_NEW/blob/master/wapi.js
I'm getting:
Cannot read property 'sendDelete' of undefined
when I call WAPI.deleteConversation(id)
Chang function deleteConversation on your code. This will work fine!
window.WAPI.deleteConversation = function (chatId, done) {
let userId = new window.Store.UserConstructor(chatId, {intentionallyUsePrivateConstructor: true});
let conversation = window.Store.Chat.get(userId);
if(!conversation) {
if(done !== undefined) {
done(false);
}
return false;
}
window.Store.sendDelete(conversation, false).then(() => {
if (done !== undefined) {
done(true);
}
}).catch(() => {
if (done !== undefined) {
done(false);
}
});
return true;
};
testing Delete Update Wapi.js => https://github.com/Theblood/Wapi_NEW/blob/master/wapi.js
I'm getting:
Cannot read property 'sendDelete' of undefined
when I call WAPI.deleteConversation(id)Chang function deleteConversation on your code. This will work fine!
window.WAPI.deleteConversation = function (chatId, done) {
let userId = new window.Store.UserConstructor(chatId, {intentionallyUsePrivateConstructor: true});
let conversation = window.Store.Chat.get(userId);if(!conversation) { if(done !== undefined) { done(false); } return false; } window.Store.sendDelete(conversation, false).then(() => { if (done !== undefined) { done(true); } }).catch(() => { if (done !== undefined) { done(false); } }); return true; };Same error =/
i modified that function, take a look:
` window.WAPI.deleteConversation = function (chatId, done) {
let userId = new window.Store.UserConstructor(chatId, {intentionallyUsePrivateConstructor: true});
let conversation = window.Store.Chat.get(userId);
if(!conversation) {
if(done !== undefined) {
done(false);
}
return false;
}
window.Store.sendDelete(conversation, false).then(() => {
if (done !== undefined) {
done(true);
}
}).catch(() => {
if (done !== undefined) {
done(false);
}
});
return true;
};
`
window.WAPI.deleteConversation = function (chatId, done) {
let userId = new window.Store.UserConstructor(chatId, {intentionallyUsePrivateConstructor: true});
let conversation = window.Store.Chat.get(userId);if(!conversation) { if(done !== undefined) { done(false); } return false; } window.Store.sendDelete(conversation, false).then(() => { if (done !== undefined) { done(true); } }).catch(() => { if (done !== undefined) { done(false); } }); return true; };
Update wapi.js #650
window.WAPI.deleteConversation = function (chatId, done) {
let userId = new window.Store.UserConstructor(chatId, {intentionallyUsePrivateConstructor: true});
let conversation = window.Store.Chat.get(userId);if(!conversation) { if(done !== undefined) { done(false); } return false; } window.Store.sendDelete(conversation, false).then(() => { if (done !== undefined) { done(true); } }).catch(() => { if (done !== undefined) { done(false); } }); return true; };
Sorry my fault.
window.WAPI.deleteConversation = function (chatId, done) {
let userId = new window.Store.UserConstructor(chatId, {intentionallyUsePrivateConstructor: true});
let conversation = window.Store.Chat.get(userId);
if(!conversation) {
if(done !== undefined) {
done(false);
}
return false;
}
window.Store.SendDelete(conversation, false).then(() => {
if (done !== undefined) {
done(true);
}
}).catch(() => {
if (done !== undefined) {
done(false);
}
});
return true;
};
window.WAPI.deleteConversation = function (chatId, done) {
let userId = new window.Store.UserConstructor(chatId, {intentionallyUsePrivateConstructor: true});
let conversation = window.Store.Chat.get(userId);if(!conversation) { if(done !== undefined) { done(false); } return false; } window.Store.SendDelete(conversation, false).then(() => { if (done !== undefined) { done(true); } }).catch(() => { if (done !== undefined) { done(false); } }); return true;};
WORKEDD! THANKS!
What was wrong? Can't see
Hello, addAndSendMsg its not working?
Uncaught TypeError: chat.addAndSendMsg is not a function
at Object.window.WAPI.sendVCard
Anyone know what changed?
Thanks..
About send messages to id, have any idea to solve?
El jue., 30 may 2019 4:03 p. m., Humberto Rodrigues <
[email protected]> escribió:
window.WAPI.deleteConversation = function (chatId, done) {
let userId = new window.Store.UserConstructor(chatId,
{intentionallyUsePrivateConstructor: true});
let conversation = window.Store.Chat.get(userId);if(!conversation) {
if(done !== undefined) {
done(false);
}
return false;
}window.Store.SendDelete(conversation, false).then(() => {
if (done !== undefined) {
done(true);
}
}).catch(() => {
if (done !== undefined) {
done(false);
}
});return true;
};
WORKEDD! THANKS!
What was wrong? Can't see—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/mukulhase/WebWhatsapp-Wrapper/issues/631?email_source=notifications&email_token=AK7HBYJHBOUG5Z5XSLH5YS3PYA6JVA5CNFSM4HQHL6TKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODWTQLFI#issuecomment-497485205,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AK7HBYPJ7VWE4LXO4PNVK7DPYA6JVANCNFSM4HQHL6TA
.
The operation of Group participants like: removeParticipants, promoteParticipants and demoteParticipants are all expired.
Anyone know how to fix it?
Update:
window.Store.WapQuery.addParticipants(group.id, [contact.id])
window.Store.WapQuery.removeParticipants(group.id, [participant.id])
window.Store.WapQuery.promoteParticipants(group.id, [participant.id])
window.Store.WapQuery.demoteParticipants(group.id, [participant.id])
Hey, if I past the content of this js file into my Whatsapp Web console, should it work? I am facing this error when I do that:
ReferenceError: webpackJsonp is not defined
@biscoitin
use that
Hey, if I past the content of this js file into my Whatsapp Web console, should it work? I am facing this error when I do that:
ReferenceError: webpackJsonp is not defined
@biscoitin
Hello @aldomonteiro, use this one Update wapi.js #650
Hello Folks,
I know that my question to be outside of the context about this topic, but someone would answer me?
when I use driver.get_unread_message_in_chat(id, args...args...) I've received the messages uncomplete.
Someone would help me?
The issue is: #647
About send messages to id, have any idea to solve? El jue., 30 may 2019 4:03 p. m., Humberto Rodrigues < [email protected]> escribió:
…
window.WAPI.deleteConversation = function (chatId, done) { let userId = new window.Store.UserConstructor(chatId, {intentionallyUsePrivateConstructor: true}); let conversation = window.Store.Chat.get(userId); if(!conversation) { if(done !== undefined) { done(false); } return false; } window.Store.SendDelete(conversation, false).then(() => { if (done !== undefined) { done(true); } }).catch(() => { if (done !== undefined) { done(false); } }); return true; }; WORKEDD! THANKS! What was wrong? Can't see — You are receiving this because you commented. Reply to this email directly, view it on GitHub <#631?email_source=notifications&email_token=AK7HBYJHBOUG5Z5XSLH5YS3PYA6JVA5CNFSM4HQHL6TKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODWTQLFI#issuecomment-497485205>, or mute the thread https://github.com/notifications/unsubscribe-auth/AK7HBYPJ7VWE4LXO4PNVK7DPYA6JVANCNFSM4HQHL6TA .
function chat_send_message is working but send_message_to_id always return error 500
Anyone getting this error when using getUnreadMessages?
Checking for more messages
Traceback (most recent call last):
File "echo.py", line 14, in
for contact in driver.get_unread():
File "/usr/local/lib/python2.7/dist-packages/webwhatsapi-2.0.3-py2.7.egg/webwhatsapi/__init__.py", line 359, in get_unread
raw_message_groups = self.wapi_functions.getUnreadMessages(include_me, include_notifications, use_unread_count)
File "/usr/local/lib/python2.7/dist-packages/webwhatsapi-2.0.3-py2.7.egg/webwhatsapi/wapi_js_wrapper.py", line 44, in __getattr__
wapi_functions = dir(self)
File "/usr/local/lib/python2.7/dist-packages/webwhatsapi-2.0.3-py2.7.egg/webwhatsapi/wapi_js_wrapper.py", line 69, in __dir__
result = self.driver.execute_script("return window.WAPI")
File "/home/gustavo.jota/.local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 636, in execute_script
'args': converted_args})['value']
File "/home/gustavo.jota/.local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/home/gustavo.jota/.local/lib/python2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.JavascriptException: Message: Cyclic object value
I have taken latest pull and seeing below error.
Traceback (most recent call last):
File "echo_observer.py", line 24, in
for contact in driver.get_unread(include_me=False, include_notifications=True, use_unread_count=True):
File "/home/mobilenxt-server2/.local/lib/python2.7/site-packages/webwhatsapi/__init__.py", line 348, in get_unread
raw_message_groups = self.wapi_functions.getUnreadMessages(include_me, include_notifications, use_unread_count)
File "/home/mobilenxt-server2/.local/lib/python2.7/site-packages/webwhatsapi/wapi_js_wrapper.py", line 44, in __getattr__
wapi_functions = dir(self)
File "/home/mobilenxt-server2/.local/lib/python2.7/site-packages/webwhatsapi/wapi_js_wrapper.py", line 67, in __dir__
self.driver.execute_script(script.read())
File "/home/mobilenxt-server2/.local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 636, in execute_script
'args': converted_args})['value']
File "/home/mobilenxt-server2/.local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/home/mobilenxt-server2/.local/lib/python2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.JavascriptException: Message: TypeError: e[o] is undefined
I am sorry as it seems new wapi.js from "https://raw.githubusercontent.com/Theblood/Wapi_NEW/master/wapi.js" is working. I just uninstalled package (pip uninstall webwhatsapi) and installed again and now it is working.
@tapankumar - Remember that the Pip package is not always as up to date as the GitHub repo. E.g. look at the release history, the last release shows as May 28th while the latest WAPI versions from TheBlood and in this repo are after then.
@nsperic - The text you're looking at in your logs is the actual notification you would've seen on your phone. What variable are you using to log the message? You should be using something like message.content to get the full message details. You can also try using json.dumps(message.get_js_obj(), indent=4) which will dump the full payload and you can then choose different fields.
@gustavojotar - Your error is related to the Firefox version you're using. Refer to https://github.com/mukulhase/WebWhatsapp-Wrapper/issues/404 for the fix.
@Skowt I used driver.get_unread_messages_in_chat(chat_id, include_me=False, include_notifications=False).
The documentation doesn't show other ways.
I need to get unread messages for chat_id.
Also the CSS Selectors for QRCode changed.
'qrCodePlain': "._2EZ_m",
'QRReloader': '._2EZ_m > span > div'
changed to
'qrCodePlain': "._1pw2F",
'QRReloader': '._1pw2F > span > div'
Hello, about sendVCard? its not working, anyone know why?
Uncaught TypeError: chat.addAndSendMsg is not a function
at Object.window.WAPI.sendVCard
Thanks.
Hello, i need help, i can't know if messages was delivered, i have the latest wapi.js this is the log:
`[2019-06-03 10:50:17,984] ERROR in app: Exception on /chats/[email protected]/messages [POST]
Traceback (most recent call last):
File "C:Program FilesPython37libsite-packagesflaskapp.py", line 1974, in make_response
rv = self.response_class.force_type(rv, request.environ)
File "C:Program FilesPython37libsite-packageswerkzeugwrappersbase_response.py", line 269, in force_type
response = BaseResponse(*_run_wsgi_app(response, environ))
File "C:Program FilesPython37libsite-packageswerkzeugtest.py", line 1118, in run_wsgi_app
app_rv = app(environ, start_response)
TypeError: 'bool' object is not callable
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:Program FilesPython37libsite-packagesflaskapp.py", line 2292, in wsgi_app
response = self.full_dispatch_request()
File "C:Program FilesPython37libsite-packagesflaskapp.py", line 1816, in full_dispatch_request
return self.finalize_request(rv)
File "C:Program FilesPython37libsite-packagesflaskapp.py", line 1831, in finalize_request
response = self.make_response(rv)
File "C:Program FilesPython37libsite-packagesflaskapp.py", line 1982, in make_response
reraise(TypeError, new_error, sys.exc_info()[2])
File "C:Program FilesPython37libsite-packagesflask_compat.py", line 34, in reraise
raise value.with_traceback(tb)
File "C:Program FilesPython37libsite-packagesflaskapp.py", line 1974, in make_response
rv = self.response_class.force_type(rv, request.environ)
File "C:Program FilesPython37libsite-packageswerkzeugwrappersbase_response.py", line 269, in force_type
response = BaseResponse(_run_wsgi_app(response, environ))
File "C:Program FilesPython37libsite-packageswerkzeugtest.py", line 1118, in run_wsgi_app
app_rv = app(environ, start_response)
TypeError: 'bool' object is not callable
The view function did not return a valid response. The return type must be a string, tuple, Response instance, or WSGI callable, but it was a bool.
127.0.0.1 - - [03/Jun/2019 10:50:17] "POST /chats/[email protected]/messages?auth-key=b1b1d9d48977&client_id=b1b1d9d48977 HTTP/1.1" 500 -
Error on request:
Traceback (most recent call last):
File "C:Program FilesPython37libsite-packagesflaskapp.py", line 1974, in make_response
rv = self.response_class.force_type(rv, request.environ)
File "C:Program FilesPython37libsite-packageswerkzeugwrappersbase_response.py", line 269, in force_type
response = BaseResponse(_run_wsgi_app(response, environ))
File "C:Program FilesPython37libsite-packageswerkzeugtest.py", line 1118, in run_wsgi_app
app_rv = app(environ, start_response)
TypeError: 'bool' object is not callable
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:Program FilesPython37libsite-packageswerkzeugserving.py", line 302, in run_wsgi
execute(self.server.app)
File "C:Program FilesPython37libsite-packageswerkzeugserving.py", line 290, in execute
application_iter = app(environ, start_response)
File "C:Program FilesPython37libsite-packagesflaskapp.py", line 2309, in __call__
return self.wsgi_app(environ, start_response)
File "C:Program FilesPython37libsite-packagesflaskapp.py", line 2295, in wsgi_app
response = self.handle_exception(e)
File "C:Program FilesPython37libsite-packagesflaskapp.py", line 1748, in handle_exception
return self.finalize_request(handler(e), from_error_handler=True)
File "C:whatssampleflaskwebapi.py", line 472, in on_bad_internal_server_error
raise e
File "C:Program FilesPython37libsite-packagesflaskapp.py", line 2292, in wsgi_app
response = self.full_dispatch_request()
File "C:Program FilesPython37libsite-packagesflaskapp.py", line 1816, in full_dispatch_request
return self.finalize_request(rv)
File "C:Program FilesPython37libsite-packagesflaskapp.py", line 1831, in finalize_request
response = self.make_response(rv)
File "C:Program FilesPython37libsite-packagesflaskapp.py", line 1982, in make_response
reraise(TypeError, new_error, sys.exc_info()[2])
File "C:Program FilesPython37libsite-packagesflask_compat.py", line 34, in reraise
raise value.with_traceback(tb)
File "C:Program FilesPython37libsite-packagesflaskapp.py", line 1974, in make_response
rv = self.response_class.force_type(rv, request.environ)
File "C:Program FilesPython37libsite-packageswerkzeugwrappersbase_response.py", line 269, in force_type
response = BaseResponse(*_run_wsgi_app(response, environ))
File "C:Program FilesPython37libsite-packageswerkzeugtest.py", line 1118, in run_wsgi_app
app_rv = app(environ, start_response)
TypeError: 'bool' object is not callable
The view function did not return a valid response. The return type must be a string, tuple, Response instance, or WSGI callable, but it was a bool.`
createGroup not working
i am getting TypeError: webpackJsonp is not a function ? how can i fix this ?
i am getting TypeError: webpackJsonp is not a function ? how can i fix this ?
@ramz30011 see #856
Fix webpackJsonp : https://github.com/Theblood/Wapi_NEW/blob/master/wapi.js
El vie., 27 mar. 2020 21:05, felippeefreire notifications@github.com
escribió:
i am getting TypeError: webpackJsonp is not a function ? how can i fix
this ?
@ramz30011 https://github.com/ramz30011 see #856
https://github.com/mukulhase/WebWhatsapp-Wrapper/issues/856—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/mukulhase/WebWhatsapp-Wrapper/issues/631#issuecomment-605292186,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AAVMMGCVG42ZSLQ7SKYT4GTRJUBIXANCNFSM4HQHL6TA
.
i am getting TypeError: webpackJsonp is not a function ? how can i fix this ? in javascript
Please help
@suresh-ums see #856
selenium.common.exceptions.JavascriptException: Message: TypeError: webpackJsonp is not a function
Para quem ainda tiver esse problema. instala o selenium na versao mais atual, e instala o six na versao==1.10.0 e o python-dateutil na versao==2.6.0 parece que não ta aceitando eles na versao mais atual, no meu caso resolveu
This is the full code from @enomineCN that I modified
/* eslint-disable */ /** * This script contains WAPI functions that need to be run in the context of the webpage */ /** * Auto discovery the webpack object references of instances that contains all functions used by the WAPI * functions and creates the Store object. */ /** Repaired the function to send by id //OLD //var idUser = new window.Store.UserConstructor(id); //NEW //var idUser = new window.Store.UserConstructor(id, {intentionallyUsePrivateConstructor: true}); Filter WhatsApp jid:user:553496802962 Status:200 Exist window.Store.WapQuery.queryExist("[email protected]"); Status:404 Not Exist window.Store.WapQuery.queryExist("[email protected]"); */ if (!window.Store) { (function () { 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} ]; 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']); })(); } window.WAPI = { lastRead: {} }; window.WAPI._serializeRawObj = (obj) => { if (obj) { return obj.toJSON(); } return {} }; /** * Serializes a chat object * * @param rawChat Chat object * @returns {{}} */ window.WAPI._serializeChatObj = (obj) => { if (obj == undefined) { return null; } return Object.assign(window.WAPI._serializeRawObj(obj), { kind: obj.kind, isGroup: obj.isGroup, contact: obj['contact'] ? window.WAPI._serializeContactObj(obj['contact']) : null, groupMetadata: obj["groupMetadata"] ? window.WAPI._serializeRawObj(obj["groupMetadata"]) : null, presence: obj["presence"] ? window.WAPI._serializeRawObj(obj["presence"]) : null, msgs: null }); }; window.WAPI._serializeContactObj = (obj) => { if (obj == undefined) { return null; } return Object.assign(window.WAPI._serializeRawObj(obj), { formattedName: obj.formattedName, isHighLevelVerified: obj.isHighLevelVerified, isMe: obj.isMe, isMyContact: obj.isMyContact, isPSA: obj.isPSA, isUser: obj.isUser, isVerified: obj.isVerified, isWAContact: obj.isWAContact, profilePicThumbObj: obj.profilePicThumb ? WAPI._serializeProfilePicThumb(obj.profilePicThumb) : {}, statusMute: obj.statusMute, msgs: null }); }; window.WAPI._serializeMessageObj = (obj) => { if (obj == undefined) { return null; } return Object.assign(window.WAPI._serializeRawObj(obj), { id: obj.id._serialized, sender: obj["senderObj"] ? WAPI._serializeContactObj(obj["senderObj"]) : null, timestamp: obj["t"], content: obj["body"], isGroupMsg: obj.isGroupMsg, isLink: obj.isLink, isMMS: obj.isMMS, isMedia: obj.isMedia, isNotification: obj.isNotification, isPSA: obj.isPSA, type: obj.type, chat: WAPI._serializeChatObj(obj['chat']), chatId: obj.id.remote, quotedMsgObj: WAPI._serializeMessageObj(obj['_quotedMsgObj']), mediaData: window.WAPI._serializeRawObj(obj['mediaData']) }); }; window.WAPI._serializeNumberStatusObj = (obj) => { if (obj == undefined) { return null; } return Object.assign({}, { id: obj.jid, status: obj.status, isBusiness: (obj.biz === true), canReceiveMessage: (obj.status === 200) }); }; window.WAPI._serializeProfilePicThumb = (obj) => { if (obj == undefined) { return null; } return Object.assign({}, { eurl: obj.eurl, id: obj.id, img: obj.img, imgFull: obj.imgFull, raw: obj.raw, tag: obj.tag }); } window.WAPI.createGroup = function (name, contactsId) { if (!Array.isArray(contactsId)) { contactsId = [contactsId]; } return window.Store.Wap.createGroup(name, contactsId); }; window.WAPI.leaveGroup = function(groupId) { groupId = typeof groupId == "string" ? groupId : groupId._serialized; var group = window.Store.Chat.get(groupId); return group.sendExit() }; window.WAPI.getAllContacts = function (done) { const contacts = window.Store.Contact.map((contact) => WAPI._serializeContactObj(contact)); if (done !== undefined) done(contacts); return contacts; }; /** * Fetches all contact objects from store, filters them * * @param done Optional callback function for async execution * @returns {Array|*} List of contacts */ window.WAPI.getMyContacts = function (done) { const contacts = window.Store.Contact.filter((contact) => contact.isMyContact === true).map((contact) => WAPI._serializeContactObj(contact)); if (done !== undefined) done(contacts); return contacts; }; /** * Fetches contact object from store by ID * * @param id ID of contact * @param done Optional callback function for async execution * @returns {T|*} Contact object */ window.WAPI.getContact = function (id, done) { const found = window.Store.Contact.get(id); if (done !== undefined) done(window.WAPI._serializeContactObj(found)) return window.WAPI._serializeContactObj(found); }; /** * Fetches all chat objects from store * * @param done Optional callback function for async execution * @returns {Array|*} List of chats */ window.WAPI.getAllChats = function (done) { const chats = window.Store.Chat.map((chat) => WAPI._serializeChatObj(chat)); if (done !== undefined) done(chats); return chats; }; window.WAPI.haveNewMsg = function (chat) { return chat.unreadCount > 0; }; window.WAPI.getAllChatsWithNewMsg = function (done) { const chats = window.Store.Chat.filter(window.WAPI.haveNewMsg).map((chat) => WAPI._serializeChatObj(chat)); if (done !== undefined) done(chats); return chats; }; /** * Fetches all chat IDs from store * * @param done Optional callback function for async execution * @returns {Array|*} List of chat id's */ window.WAPI.getAllChatIds = function (done) { const chatIds = window.Store.Chat.map((chat) => chat.id._serialized || chat.id); if (done !== undefined) done(chatIds); return chatIds; }; /** * Fetches all groups objects from store * * @param done Optional callback function for async execution * @returns {Array|*} List of chats */ window.WAPI.getAllGroups = function (done) { const groups = window.Store.Chat.filter((chat) => chat.isGroup); if (done !== undefined) done(groups); return groups; }; /** * Fetches chat object from store by ID * * @param id ID of chat * @param done Optional callback function for async execution * @returns {T|*} Chat object */ window.WAPI.getChat = function (id, done) { id = typeof id == "string" ? id : id._serialized; const found = window.Store.Chat.get(id); if (done !== undefined) done(found); return found; } window.WAPI.getChatByName = function (name, done) { const found = window.Store.Chat.find((chat) => chat.name === name); if (done !== undefined) done(found); return found; }; window.WAPI.sendImageFromDatabasePicBot = function (picId, chatId, caption) { var chatDatabase = window.WAPI.getChatByName('DATABASEPICBOT'); var msgWithImg = chatDatabase.msgs.find((msg) => msg.caption == picId); if (msgWithImg === undefined) { return false; } var chatSend = WAPI.getChat(chatId); if (chatSend === undefined) { return false; } const oldCaption = msgWithImg.caption; msgWithImg.id.id = window.WAPI.getNewId(); msgWithImg.id.remote = chatId; msgWithImg.t = Math.ceil(new Date().getTime() / 1000); msgWithImg.to = chatId; if (caption !== undefined && caption !== '') { msgWithImg.caption = caption; } else { msgWithImg.caption = ''; } msgWithImg.collection.send(msgWithImg).then(function (e) { msgWithImg.caption = oldCaption; }); return true; }; window.WAPI.sendMessageWithThumb = function (thumb, url, title, description, chatId,done) { var chatSend = WAPI.getChat(chatId); if (chatSend === undefined) { if(done!==undefined) done(false); return false; } var linkPreview = {canonicalUrl: url, description: description, matchedText: url, title: title, thumbnail: thumb}; chatSend.sendMessage(url, {linkPreview: linkPreview, mentionedJidList: [], quotedMsg: null, quotedMsgAdminGroupJid: null}); if(done!==undefined) done(true); return true; }; window.WAPI.getNewId = function () { var text = ""; var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; for (var i = 0; i < 20; i++) text += possible.charAt(Math.floor(Math.random() * possible.length)); return text; }; window.WAPI.getChatById = function (id, done) { let found = window.WAPI.getChat(id); if (found) { found = WAPI._serializeChatObj(found); } else { found = false; } if (done !== undefined) done(found); return found; }; /** * I return all unread messages from an asked chat and mark them as read. * * :param id: chat id * :type id: string * * :param includeMe: indicates if user messages have to be included * :type includeMe: boolean * * :param includeNotifications: indicates if notifications have to be included * :type includeNotifications: boolean * * :param done: callback passed by selenium * :type done: function * * :returns: list of unread messages from asked chat * :rtype: object */ window.WAPI.getUnreadMessagesInChat = function (id, includeMe, includeNotifications, done) { // get chat and its messages let chat = WAPI.getChat(id); let messages = chat.msgs.models; // initialize result list let output = []; // look for unread messages, newest is at the end of array for (let i = messages.length - 1; i >= 0; i--) { // system message: skip it if (i === "remove") { continue; } // get message let messageObj = messages[i]; // found a read message: stop looking for others if (typeof (messageObj.__x_isUnreadType) !== "boolean" || messageObj.__x_isUnreadType === false) { continue; } else { messageObj.__x_isUnreadType = false; // process it let message = WAPI.processMessageObj(messageObj, includeMe, includeNotifications); // save processed message on result list if (message) output.push(message); } } // callback was passed: run it if (done !== undefined) done(output); // return result list return output; } ; /** * Load more messages in chat object from store by ID * * @param id ID of chat * @param done Optional callback function for async execution * @returns None */ window.WAPI.loadEarlierMessages = function (id, done) { const found = window.WAPI.getChat(id); if (done !== undefined) { found.loadEarlierMsgs().then(function () { done() }); } else { found.loadEarlierMsgs(); } }; /** * Load more messages in chat object from store by ID * * @param id ID of chat * @param done Optional callback function for async execution * @returns None */ window.WAPI.loadAllEarlierMessages = function (id, done) { const found = window.WAPI.getChat(id); x = function () { if (!found.msgs.msgLoadState.noEarlierMsgs) { found.loadEarlierMsgs().then(x); } else if (done) { done(); } }; x(); }; window.WAPI.asyncLoadAllEarlierMessages = function (id, done) { done(); window.WAPI.loadAllEarlierMessages(id); }; window.WAPI.areAllMessagesLoaded = function (id, done) { const found = window.WAPI.getChat(id); if (!found.msgs.msgLoadState.noEarlierMsgs) { if (done) done(false); return false } if (done) done(true); return true }; /** * Load more messages in chat object from store by ID till a particular date * * @param id ID of chat * @param lastMessage UTC timestamp of last message to be loaded * @param done Optional callback function for async execution * @returns None */ window.WAPI.loadEarlierMessagesTillDate = function (id, lastMessage, done) { const found = window.WAPI.getChat(id); x = function () { if (found.msgs.models[0].t > lastMessage) { found.loadEarlierMsgs().then(x); } else { done(); } }; x(); }; /** * Fetches all group metadata objects from store * * @param done Optional callback function for async execution * @returns {Array|*} List of group metadata */ window.WAPI.getAllGroupMetadata = function (done) { const groupData = window.Store.GroupMetadata.map((groupData) => groupData.all); if (done !== undefined) done(groupData); return groupData; }; /** * Fetches group metadata object from store by ID * * @param id ID of group * @param done Optional callback function for async execution * @returns {T|*} Group metadata object */ window.WAPI.getGroupMetadata = async function (id, done) { let output = window.Store.GroupMetadata.get(id); if (output !== undefined) { if (output.stale) { await output.update(); } } if (done !== undefined) done(output); return output; }; /** * Fetches group participants * * @param id ID of group * @returns {Promise.<*>} Yields group metadata * @private */ window.WAPI._getGroupParticipants = async function (id) { const metadata = await WAPI.getGroupMetadata(id); return metadata.participants; }; /** * Fetches IDs of group participants * * @param id ID of group * @param done Optional callback function for async execution * @returns {Promise.<Array|*>} Yields list of IDs */ window.WAPI.getGroupParticipantIDs = async function (id, done) { const output = (await WAPI._getGroupParticipants(id)) .map((participant) => participant.id); if (done !== undefined) done(output); return output; }; window.WAPI.getGroupAdmins = async function (id, done) { const output = (await WAPI._getGroupParticipants(id)) .filter((participant) => participant.isAdmin) .map((admin) => admin.id); if (done !== undefined) done(output); return output; }; /** * Gets object representing the logged in user * * @returns {Array|*|$q.all} */ window.WAPI.getMe = function (done) { const rawMe = window.Store.Contact.get(window.Store.Conn.me); if (done !== undefined) done(rawMe.all); return rawMe.all; }; window.WAPI.isLoggedIn = function (done) { // Contact always exists when logged in const isLogged = window.Store.Contact && window.Store.Contact.checksum !== undefined; if (done !== undefined) done(isLogged); return isLogged; }; window.WAPI.processMessageObj = function (messageObj, includeMe, includeNotifications) { if (messageObj.isNotification) { if (includeNotifications) return WAPI._serializeMessageObj(messageObj); else return; // System message // (i.e. "Messages you send to this chat and calls are now secured with end-to-end encryption...") } else if (messageObj.id.fromMe === false || includeMe) { return WAPI._serializeMessageObj(messageObj); } return; }; window.WAPI.getAllMessagesInChat = function (id, includeMe, includeNotifications, done) { const chat = WAPI.getChat(id); let output = []; const messages = chat.msgs.models; for (const i in messages) { if (i === "remove") { continue; } const messageObj = messages[i]; let message = WAPI.processMessageObj(messageObj, includeMe, includeNotifications) if (message) output.push(message); } if (done !== undefined) done(output); return output; }; window.WAPI.getAllMessageIdsInChat = function (id, includeMe, includeNotifications, done) { const chat = WAPI.getChat(id); let output = []; const messages = chat.msgs.models; for (const i in messages) { if ((i === "remove") || (!includeMe && messages[i].isMe) || (!includeNotifications && messages[i].isNotification)) { continue; } output.push(messages[i].id._serialized); } if (done !== undefined) done(output); return output; }; window.WAPI.getMessageById = function (id, done) { let result = false; try { let msg = window.Store.Msg.get(id); if (msg) { result = WAPI.processMessageObj(msg, true, true); } } catch (err) { } if (done !== undefined) { done(result); } else { return result; } }; window.WAPI.ReplyMessage = function (idMessage, message, done) { var messageObject = window.Store.Msg.get(idMessage); if (messageObject === undefined) { if (done !== undefined) done(false); return false; } messageObject = messageObject.value(); const chat = window.Store.Chat.get(messageObject.chat.id) if (chat !== undefined){ if (done !== undefined) { chat.sendMessage(message, null, messageObject).then(function () { function sleep(ms) { return new Promise(resolve => setTimeout(resolve, ms)); } var trials = 0; function check() { for (let i = chat.msgs.models.length - 1; i >= 0; i--) { let msg = chat.msgs.models[i]; if (!msg.senderObj.isMe || msg.body != message) { continue; } done(WAPI._serializeMessageObj(msg)); return True; } trials += 1; console.log(trials); if (trials > 30) { done(true); return; } sleep(500).then(check); } check(); }); return true; } else { chat.sendMessage(message, null, messageObject); return true; } } else { if (done !== undefined) done(false); return false; } }; window.WAPI.sendMessageToID = function (id, message, done) { try { //OLD //var idUser = new window.Store.UserConstructor(id); //NEW var idUser = new window.Store.UserConstructor(id, {intentionallyUsePrivateConstructor: true}); // create new chat // return Store.Chat.find(idUser).then((chat) => { // if (done !== undefined) { // chat.sendMessage(message).then(function () { // done(true); // }); // return true; //} else { // chat.sendMessage(message); // return true; // } window.getContact = ( id ) => { return Store.WapQuery.queryExist(id) } window.getContact(id).then(contact => { if(contact.status === 404){ done(true); }else { Store.Chat.find(contact.jid).then(chat => { chat.sendMessage(message); return true; }).catch(reject => { done(true); }); } }); } catch (e) { if (window.Store.Chat.length === 0) return false; firstChat = Store.Chat.models[0]; var originalID = firstChat.id; firstChat.id = typeof originalID === "string" ? id : new window.Store.UserConstructor(id, {intentionallyUsePrivateConstructor: true}); if (done !== undefined) { firstChat.sendMessage(message).then(function () { firstChat.id = originalID; done(true); }); return true; } else { firstChat.sendMessage(message); firstChat.id = originalID; return true; } } if (done !== undefined) done(false); return false; } window.WAPI.sendMessage = function (id, message, done) { var chat = window.WAPI.getChat(id); if (chat !== undefined) { if (done !== undefined) { chat.sendMessage(message).then(function () { function sleep(ms) { return new Promise(resolve => setTimeout(resolve, ms)); } var trials = 0; function check() { for (let i = chat.msgs.models.length - 1; i >= 0; i--) { let msg = chat.msgs.models[i]; if (!msg.senderObj.isMe || msg.body != message) { continue; } done(WAPI._serializeMessageObj(msg)); return True; } trials += 1; console.log(trials); if (trials > 30) { done(true); return; } sleep(500).then(check); } check(); }); return true; } else { chat.sendMessage(message); return true; } } else { if (done !== undefined) done(false); return false; } }; window.WAPI.sendMessage2 = function (id, message, done) { var chat = window.WAPI.getChat(id); if (chat !== undefined) { try { if (done !== undefined) { chat.sendMessage(message).then(function () { done(true); }); } else { chat.sendMessage(message); } return true; } catch (error) { if (done !== undefined) done(false) return false; } } if (done !== undefined) done(false) return false; }; window.WAPI.sendSeen = function (id, done) { // @sidikhanrei version var chat = window.WAPI.getChat(id); if (chat !== undefined) { if (done !== undefined) { window.Store.SendSeen(chat, false); return true; } else { window.Store.SendSeen(chat, false); return true; } } if (done !== undefined) done(); return false; }; function isChatMessage(message) { if (message.isSentByMe) { return false; } if (message.isNotification) { return false; } if (!message.isUserCreatedType) { return false; } return true; } window.WAPI.getUnreadMessages = function (includeMe, includeNotifications, use_unread_count, done) { const chats = window.Store.Chat.models; let output = []; for (let chat in chats) { if (isNaN(chat)) { continue; } let messageGroupObj = chats[chat]; let messageGroup = WAPI._serializeChatObj(messageGroupObj); messageGroup.messages = []; const messages = messageGroupObj.msgs._models; for (let i = messages.length - 1; i >= 0; i--) { let messageObj = messages[i]; if (typeof (messageObj.__x_isUnreadType) != "boolean" || messageObj.__x_isUnreadType === false) { continue; } else { messageObj.__x_isUnreadType = false; let message = WAPI.processMessageObj(messageObj, includeMe, includeNotifications); if (message) { messageGroup.messages.push(message); } } } if (messageGroup.messages.length > 0) { output.push(messageGroup); } else { // no messages with isNewMsg true if (use_unread_count) { let n = messageGroupObj.unreadCount; // will use unreadCount attribute to fetch last n messages from sender for (let i = messages.length - 1; i >= 0; i--) { let messageObj = messages[i]; if (n > 0) { if (!messageObj.isSentByMe) { let message = WAPI.processMessageObj(messageObj, includeMe, includeNotifications); messageGroup.messages.unshift(message); n -= 1; } } else if (n === -1) { // chat was marked as unread so will fetch last message as unread if (!messageObj.isSentByMe) { let message = WAPI.processMessageObj(messageObj, includeMe, includeNotifications); messageGroup.messages.unshift(message); break; } } else { // unreadCount = 0 break; } } if (messageGroup.messages.length > 0) { messageGroupObj.unreadCount = 0; // reset unread counter output.push(messageGroup); } } } } if (done !== undefined) { done(output); } return output; }; window.WAPI.getGroupOwnerID = async function (id, done) { const output = (await WAPI.getGroupMetadata(id)).owner.id; if (done !== undefined) { done(output); } return output; }; window.WAPI.getCommonGroups = async function (id, done) { let output = []; groups = window.WAPI.getAllGroups(); for (let idx in groups) { try { participants = await window.WAPI.getGroupParticipantIDs(groups[idx].id); if (participants.filter((participant) => participant == id).length) { output.push(groups[idx]); } } catch (err) { console.log("Error in group:"); console.log(groups[idx]); console.log(err); } } if (done !== undefined) { done(output); } return output; }; window.WAPI.getProfilePicSmallFromId = function(id, done) { window.Store.ProfilePicThumb.find(id).then(function(d) { if(d.img !== undefined) { window.WAPI.downloadFileWithCredentials(d.img, done); } else { done(false); } }, function(e) { done(false); }) }; window.WAPI.getProfilePicFromId = function(id, done) { window.Store.ProfilePicThumb.find(id).then(function(d) { if(d.imgFull !== undefined) { window.WAPI.downloadFileWithCredentials(d.imgFull, done); } else { done(false); } }, function(e) { done(false); }) }; window.WAPI.downloadFileWithCredentials = function (url, done) { let xhr = new XMLHttpRequest(); xhr.onload = function () { if (xhr.readyState == 4) { if (xhr.status == 200) { let reader = new FileReader(); reader.readAsDataURL(xhr.response); reader.onload = function (e) { done(reader.result.substr(reader.result.indexOf(',') + 1)) }; } else { console.error(xhr.statusText); } } else { console.log(err); done(false); } }; xhr.open("GET", url, true); xhr.withCredentials = true; xhr.responseType = 'blob'; xhr.send(null); }; window.WAPI.downloadFile = function (url, done) { let xhr = new XMLHttpRequest(); xhr.onload = function () { if (xhr.readyState == 4) { if (xhr.status == 200) { let reader = new FileReader(); reader.readAsDataURL(xhr.response); reader.onload = function (e) { done(reader.result.substr(reader.result.indexOf(',') + 1)) }; } else { console.error(xhr.statusText); } } else { console.log(err); done(false); } }; xhr.open("GET", url, true); xhr.responseType = 'blob'; xhr.send(null); }; window.WAPI.getBatteryLevel = function (done) { if (window.Store.Conn.plugged) { if (done !== undefined) { done(100); } return 100; } output = window.Store.Conn.battery; if (done !== undefined) { done(output); } return output; }; window.WAPI.deleteConversation = function (chatId, done) { let userId = new window.Store.UserConstructor(chatId, {intentionallyUsePrivateConstructor: true}); let conversation = window.Store.Chat.get(userId); if(!conversation) { if(done !== undefined) { done(false); } return false; } conversation.sendDelete().then(() => { if (done !== undefined) { done(true); } }).catch(() => { if (done !== undefined) { done(false); } }); return true; }; window.WAPI.deleteMessage = function (chatId, messageArray, revoke=false, done) { let userId = new window.Store.UserConstructor(chatId, {intentionallyUsePrivateConstructor: true}); let conversation = window.Store.Chat.get(userId); if(!conversation) { if(done !== undefined) { done(false); } return false; } if (!Array.isArray(messageArray)) { messageArray = [messageArray]; } if(revoke){ conversation.sendRevokeMsgs(messageArray, conversation); }else{ conversation.sendDeleteMsgs(messageArray, conversation); } if (done !== undefined) { done(true); } return true; }; window.WAPI.checkNumberStatus = function(id, done) { window.Store.WapQuery.queryExist(id).then((result) => { if(done !== undefined) { if(result.jid === undefined) throw 404; done(window.WAPI._serializeNumberStatusObj(result)); } }).catch((e) => { if(done !== undefined) { done(window.WAPI._serializeNumberStatusObj({ status: e, jid: id })); } }); return true; }; /** * New messages observable functions. */ window.WAPI._newMessagesQueue = []; window.WAPI._newMessagesBuffer = (sessionStorage.getItem('saved_msgs') != null) ? JSON.parse(sessionStorage.getItem('saved_msgs')) : []; window.WAPI._newMessagesDebouncer = null; window.WAPI._newMessagesCallbacks = []; window.Store.Msg.off('add'); sessionStorage.removeItem('saved_msgs'); window.WAPI._newMessagesListener = window.Store.Msg.on('add', (newMessage) => { if (newMessage && newMessage.__x_isUnreadType && !newMessage.isSentByMe) { let message = window.WAPI.processMessageObj(newMessage, false, false); if (message) { window.WAPI._newMessagesQueue.push(message); window.WAPI._newMessagesBuffer.push(message); } // Starts debouncer time to don't call a callback for each message if more than one message arrives // in the same second if(!window.WAPI._newMessagesDebouncer && window.WAPI._newMessagesQueue.length > 0) { window.WAPI._newMessagesDebouncer = setTimeout(() => { window.WAPI._newMessagesDebouncer = null; let queuedMessages = window.WAPI._newMessagesQueue; window.WAPI._newMessagesQueue = []; let removeCallbacks = []; window.WAPI._newMessagesCallbacks.forEach(function(callbackObj) { if(callbackObj.callback !== undefined) { callbackObj.callback(queuedMessages); } if(callbackObj.rmAfterUse === true) { removeCallbacks.push(callbackObj); } }); // Remove removable callbacks. removeCallbacks.forEach(function(rmCallbackObj) { let callbackIndex = window.WAPI._newMessagesCallbacks.indexOf(rmCallbackObj); window.WAPI._newMessagesCallbacks.splice(callbackIndex, 1); }); }, 1000); } } }); window.WAPI._unloadInform = (event) => { // Save in the buffer the ungot unreaded messages window.WAPI._newMessagesBuffer.forEach((message) => { Object.keys(message).forEach(key => message[key] === undefined ? delete message[key] : ''); }); sessionStorage.setItem("saved_msgs", JSON.stringify(window.WAPI._newMessagesBuffer)); // Inform callbacks that the page will be reloaded. window.WAPI._newMessagesCallbacks.forEach(function(callbackObj) { if(callbackObj.callback !== undefined) { callbackObj.callback({status: -1, message: 'page will be reloaded, wait and register callback again.'}); } }); }; window.addEventListener("unload", window.WAPI._unloadInform, false); window.addEventListener("beforeunload", window.WAPI._unloadInform, false); window.addEventListener("pageunload", window.WAPI._unloadInform, false); /** * Registers a callback to be called when a new message arrives the WAPI. * @param rmCallbackAfterUse - Boolean - Specify if the callback need to be executed only once * @param done - function - Callback function to be called when a new message arrives. * @returns {boolean} */ window.WAPI.waitNewMessages = function(rmCallbackAfterUse = true, done) { window.WAPI._newMessagesCallbacks.push({callback: done, rmAfterUse: rmCallbackAfterUse}); return true; }; /** * Reads buffered new messages. * @param done - function - Callback function to be called contained the buffered messages. * @returns {Array} */ window.WAPI.getBufferedNewMessages = function(done) { let bufferedMessages = window.WAPI._newMessagesBuffer; window.WAPI._newMessagesBuffer = []; if(done !== undefined) { done(bufferedMessages); } return bufferedMessages; }; /** End new messages observable functions **/ window.WAPI.sendImage = function (imgBase64, chatid, filename, caption, done) { //var idUser = new window.Store.UserConstructor(chatid); var idUser = new window.Store.UserConstructor(chatid, {intentionallyUsePrivateConstructor: true}); // create new chat return Store.Chat.find(idUser).then((chat) => { var mediaBlob = window.WAPI.base64ImageToFile(imgBase64, filename); var mc = new Store.MediaCollection(); mc.processFiles([mediaBlob], chat, 1).then(() => { var media = mc.models[0]; media.sendToChat(chat, {caption: caption}); if (done !== undefined) done(true); }); }); } window.WAPI.base64ImageToFile = function (b64Data, filename) { var arr = b64Data.split(','), mime = arr[0].match(/:(.*?);/)[1], bstr = atob(arr[1]), n = bstr.length, u8arr = new Uint8Array(n); while (n--) { u8arr[n] = bstr.charCodeAt(n); } return new File([u8arr], filename, {type: mime}); }; /** * Send contact card to a specific chat using the chat ids * * @param {string} to '[email protected]' * @param {string|array} contact '[email protected]' | ['[email protected]', '[email protected], ... '[email protected]'] */ window.WAPI.sendContact = function(to, contact) { if (!Array.isArray(contact)) { contact = [contact]; } contact = contact.map((c) => { return window.WAPI.getChat(c).__x_contact; }); if (contact.length > 1) { window.WAPI.getChat(to).sendContactList(contact); } else if (contact.length === 1) { window.WAPI.getChat(to).sendContact(contact[0]); } }; /** * Create an chat ID based in a cloned one * * @param {string} chatId '[email protected]' */ window.WAPI.getNewMessageId = function(chatId) { var newMsgId = Store.Msg.models[0].id.clone(); newMsgId.fromMe = true; newMsgId.id = WAPI.getNewId().toUpperCase(); newMsgId.remote = chatId; newMsgId._serialized = `${newMsgId.fromMe}_${newMsgId.remote}_${newMsgId.id}` return newMsgId; }; /** * Send Customized VCard without the necessity of contact be a Whatsapp Contact * * @param {string} chatId '[email protected]' * @param {object|array} vcard { displayName: 'Contact Name', vcard: 'BEGIN:VCARD\nVERSION:3.0\nN:;Contact Name;;;\nEND:VCARD' } | [{ displayName: 'Contact Name 1', vcard: 'BEGIN:VCARD\nVERSION:3.0\nN:;Contact Name 1;;;\nEND:VCARD' }, { displayName: 'Contact Name 2', vcard: 'BEGIN:VCARD\nVERSION:3.0\nN:;Contact Name 2;;;\nEND:VCARD' }] */ window.WAPI.sendVCard = function(chatId, vcard) { var chat = Store.Chat.get(chatId); var tempMsg = Object.create(Store.Msg.models.filter(msg => msg.__x_isSentByMe)[0]); var newId = window.WAPI.getNewMessageId(chatId); var extend = { ack: 0, id: newId, local: !0, self: "out", t: parseInt(new Date().getTime() / 1000), to: chatId, __x_isUnreadType: !0, }; if (Array.isArray(vcard)) { Object.assign(extend, { type: "multi_vcard", vcardList: vcard }); delete extend.body; } else { Object.assign(extend, { type: "vcard", subtype: vcard.displayName, body: vcard.vcard }); delete extend.vcardList; } Object.assign(tempMsg, extend); chat.addAndSendMsg(tempMsg); }; /** * Block contact * @param {string} id '[email protected]' * @param {*} done - function - Callback function to be called when a new message arrives. */ window.WAPI.contactBlock = function(id, done){ const contact = window.Store.Contact.get(id); if (contact !== undefined){ contact.setBlock(!0); done(true); return true; } done(false); return false; } /** * unBlock contact * @param {string} id '[email protected]' * @param {*} done - function - Callback function to be called when a new message arrives. */ window.WAPI.contactUnblock = function(id, done){ const contact = window.Store.Contact.get(id); if (contact !== undefined){ contact.setBlock(!1); done(true); return true; } done(false); return false; } /** * Remove participant of Group * @param {*} idGroup '[email protected]' * @param {*} idParticipant '[email protected]' * @param {*} done - function - Callback function to be called when a new message arrives. */ window.WAPI.removeParticipantGroup = function(idGroup, idParticipant, done){ const metaDataGroup = window.Store.GroupMetadata.get(idGroup); if (metaDataGroup === undefined){ done(false); return false; } const participant = metaDataGroup.participants.get(idParticipant); if (participant === undefined){ done(false); return false; } metaDataGroup.participants.removeParticipants([participant]).then((ret)=>{ const check = metaDataGroup.participants.get(idParticipant); if (check === undefined){ done(true); return true; } done(false); return false; }) } /** * Promote Participant to Admin in Group * @param {*} idGroup '[email protected]' * @param {*} idParticipant '[email protected]' * @param {*} done - function - Callback function to be called when a new message arrives. */ window.WAPI.promoteParticipantAdminGroup = function(idGroup, idParticipant, done){ const metaDataGroup = window.Store.GroupMetadata.get(idGroup); if (metaDataGroup === undefined){ done(false); return false; } const participant = metaDataGroup.participants.get(idParticipant); if (participant === undefined){ done(false); return false; } metaDataGroup.participants.promoteParticipants([participant]).then(()=>{ const checkParticipant = metaDataGroup.participants.get(idParticipant); if (checkParticipant !== undefined){ if (checkParticipant.__x_isAdmin){ done(true); return true; } } done(false); return false; }) } /** * Demote Admin of Group * @param {*} idGroup '[email protected]' * @param {*} idParticipant '[email protected]' * @param {*} done - function - Callback function to be called when a new message arrives. */ window.WAPI.demoteParticipantAdminGroup = function(idGroup, idParticipant, done){ const metaDataGroup = window.Store.GroupMetadata.get(idGroup); if (metaDataGroup === undefined){ done(false); return false; } const participant = metaDataGroup.participants.get(idParticipant); if (participant === undefined){ done(false); return false; } metaDataGroup.participants.demoteParticipants([participant]).then(()=>{ const checkParticipant = metaDataGroup.participants.get(idParticipant); if (checkParticipant !== undefined && checkParticipant.__x_isAdmin){ done(false); return false; } done(true); return true; }) }
Thanks it helped
hi sir i am getting "javascript error: Cannot read property 'push' of undefined" error recently in WAPI function,can anyone please explain how to change WAPI functions when whatsapp web website updates.If possible please send any documentation regarding this.
Note:
output of "window.webpackJsonp" is giving undefined.
Message: ReferenceError: webpackJsonp is not defined
When trying to use send_message_to_id which internally then calls sendMessageToID.
Any idea what wrong?
Message: ReferenceError: webpackJsonp is not defined
When trying to usesend_message_to_idwhich internally then callssendMessageToID.
Any idea what wrong?
i am also facing this issue
Message: ReferenceError: webpackJsonp is not defined
When trying to usesend_message_to_idwhich internally then callssendMessageToID.
Any idea what wrong?
Fixed the issue by @vbhv19 in this commit
(https://github.com/vbhv19/WebWhatsapp-Wrapper/commit/fb1b6d14cccc977457a6e3320a12d1277a617eaa)
Message: ReferenceError: webpackJsonp is not defined
When trying to usesend_message_to_idwhich internally then callssendMessageToID.
Any idea what wrong?Fixed the issue by @vbhv19 in this commit
(vbhv19@fb1b6d1)
thank you very much
sir getting below javascript error in WAPI.JS file
"javascript error: Comms::sendIq called before startComms",please help sir
sir getting below javascript error in WAPI.JS file
"javascript error: Comms::sendIq called before startComms",please help sir
Hi, I had the same problem as you. Were you successful in fixing so?
sir getting below javascript error in WAPI.JS file
"javascript error: Comms::sendIq called before startComms",please help sirHi, I had the same problem as you. Were you successful in fixing so?
Hi sir,Below solution worked for me,
Just change store discovery for WapQuery, getting wrong reference.
{
id: "WapQuery",
conditions: (module) => (module.default && module.default.queryExist) ? module.default : null
},
Hi sir,Below solution worked for me,
Worked for me too. Thank you.
Hi sir,Below solution worked for me,
Worked for me too. Thank you.
Hello, greetings everyone, I've been trying to fix the WAPI function.checkNumberStatus("[email protected]") but I'm still not having it work, could I help with an example of how to use it?
sir getting below javascript error in WAPI.JS file
"javascript error: Comms::sendIq called before startComms",please help sirHi, I had the same problem as you. Were you successful in fixing so?
Hi sir,Below solution worked for me,
Just change store discovery for WapQuery, getting wrong reference.
{
id: "WapQuery",
conditions: (module) => (module.default && module.default.queryExist) ? module.default : null
},
its not working now
same error on using checkNumberStatus(id)

Most helpful comment
Try this wapi.js file.
https://github.com/Theblood/Wapi_NEW/blob/master/wapi.js