Skip to content

Instantly share code, notes, and snippets.

@phpRajat
Last active April 24, 2024 07:11
Show Gist options
  • Star 59 You must be signed in to star a gist
  • Fork 21 You must be signed in to fork a gist
  • Save phpRajat/a6422922efae32914f4dbd1082f3f412 to your computer and use it in GitHub Desktop.
Save phpRajat/a6422922efae32914f4dbd1082f3f412 to your computer and use it in GitHub Desktop.
setTimeout(function() {
function getAllModules() {
return new Promise((resolve) => {
const id = _.uniqueId("fakeModule_");
window["webpackJsonp"](
[],
{
[id]: function(module, exports, __webpack_require__) {
resolve(__webpack_require__.c);
}
},
[id]
);
});
}
var modules = getAllModules()._value;
for (var key in modules) {
if (modules[key].exports) {
if (modules[key].exports.createFromData) {
createFromData_id = modules[key].i.replace(/"/g, '"');
}
if (modules[key].exports.prepRawMedia) {
prepareRawMedia_id = modules[key].i.replace(/"/g, '"');
}
if (modules[key].exports.default) {
if (modules[key].exports.default.Wap) {
store_id = modules[key].i.replace(/"/g, '"');
}
}
if (modules[key].exports.sendTextMsgToChat) {
chat_id = modules[key].i.replace(/"/g, '"');
}
}
}
}, 2000);
function _requireById(id) {
return webpackJsonp([], null, [id]);
}
var createFromData_id = 0;
var prepareRawMedia_id = 0;
var store_id = 0;
var chat_id = 0;
function fixBinary (bin) {
var length = bin.length;
var buf = new ArrayBuffer(length);
var arr = new Uint8Array(buf);
for (var i = 0; i < length; i++) {
arr[i] = bin.charCodeAt(i);
}
return buf;
}
var send_media;
window.send_media = function(jid, link, caption, msg_id, content_type) {
var file = "";
var createFromDataClass = _requireById(createFromData_id)["default"];
var prepareRawMediaClass = _requireById(prepareRawMedia_id).prepRawMedia;
window.Store.Chat.find(jid).then((chat) => {
var img_b64 = link;
var base64 = img_b64.split(',')[1];
var type = img_b64.split(',')[0];
type = type.split(';')[0];
type = type.split(':')[1];
var binary = fixBinary(atob(base64));
var blob = new Blob([binary], {type: type});
var random_name = Math.random().toString(36).substr(2, 5);
file = new File([blob], random_name, {
type: type,
lastModified: Date.now()
});
var temp = createFromDataClass.createFromData(file, file.type);
var rawMedia = prepareRawMediaClass(temp, {});
var target = _.filter(window.Store.Msg.models, (msg) => {
return msg.id.id === msg_id;
})[0];
var textPortion = {
caption: caption,
mentionedJidList: [],
quotedMsg: target
};
rawMedia.sendToChat(chat, textPortion);
});
}
var Store = {};
function init() {
window.Store = _requireById(store_id).default;
window.Store.sendTextMsgToChat = _requireById(chat_id).sendTextMsgToChat;
console.log("Store is ready");
console.log(window.Store);
window.send_media("91xxxxxxxxxx@c.us", "data:image/png;base64,iVBORw0KG..........sda=", "test messsage", null, null);
}
setTimeout(function() {
init();
}, 5000);
@Manjit2003
Copy link

It's not open source. If you want then msg me

Shared the code please

Shared the code where man.

@mikelustosa
Copy link

It's not open source. If you want then msg me

Shared the code please

Shared the code where man.

Get out man! This repository is open source! kkkkkk

@mikelustosa
Copy link

Get out

Go bite your father in the ass. hahahaha

@mikelustosa
Copy link

Anyone using the WAPI.createGroup function? Does not work.

@rajeshshettysrs
Copy link

hi anyone having latest checkNumberStatus function of WAPI,because existing is not working properly

@nistarok
Copy link

nistarok commented Jul 8, 2022

This issue has the solution for check number problem pedroslopez/whatsapp-web.js#1576

@rajeshshettysrs
Copy link

Finally this solution worked.
mikelustosa/Projeto-TInject#41

@mikelustosa
Copy link

Anyone having a problem with this function?

Store.MyStatus.getStatus()

Return :

_value:
id: "+xxxxxxxxxx@c.us"
status: ""

@mikelustosa
Copy link

Has anyone managed to use the sendButtons function?

@rafahlobo
Copy link

It's not open source. If you want then msg me

Shared the code please

Shared the code where man.

Get out man! This repository is open source! kkkkkk

You are right!!! I allow with you. Kkkkkkkk

@mikelustosa
Copy link

Gentlemen, I'm working on fixing push buttons in WAPI. At the moment it is only possible to view the buttons on whatsapp web, it remains to be corrected to display on mobile. Who can help.

@bobaoapae
Copy link

Gentlemen, I'm working on fixing push buttons in WAPI. At the moment it is only possible to view the buttons on whatsapp web, it remains to be corrected to display on mobile. Who can help.

I can help you, send-me a e-mail jvborges@outlook.com

@mikelustosa
Copy link

Include conditions in getStore function:

{ id: 'Clock', conditions: (module) => (module.Clock ? module.Clock : null)},
{ id: 'TemplateButtonCollection', conditions: (module) => (module.TemplateButtonCollectionImpl || module.TemplateButtonCollection ? module.TemplateButtonCollection : null)},
{ id: 'ButtonCollection', conditions: (module) => (module.ButtonCollectionImpl || module.ButtonCollection ? module.ButtonCollection : null)}

Before:

function prepareMessageButtons(message, options) {
if (!options.buttons) {
return message;
}
if (!Array.isArray(options.buttons)) {
throw 'Buttons options is not a array';
}
if (typeof options.useTemplateButtons === 'undefined') {
options.useTemplateButtons = options.buttons.some((button) => 'phoneNumber' in button || 'url' in button);
}
if (options.useTemplateButtons) {
if (options.buttons.length === 0 || options.buttons.length > 5) {
throw 'Buttons options must have between 1 and 5 options';
}
}
else {
if (options.buttons.length === 0 || options.buttons.length > 3) {
throw 'Buttons options must have between 1 and 3 options';
}
}
message.title = options.title;
message.footer = options.footer;
if (options.useTemplateButtons) {
message.isFromTemplate = true;
message.buttons = new Store.TemplateButtonCollection();
message.hydratedButtons = options.buttons.map((button, index) => {
if ('phoneNumber' in button) {
return {
index: index,
callButton: {
displayText: button.text,
phoneNumber: button.phoneNumber,
},
};
}
if ('url' in button) {
return {
index: index,
urlButton: {
displayText: button.text,
url: button.url,
},
};
}
return {
index: index,
quickReplyButton: {
displayText: button.text,
id: button.id || ${index},
},
};
});
message.buttons.add(message.hydratedButtons.map((e, t) => {
var _a, _b, _c, _d;
const i = ${null != e.index ? e.index : t};
if (e.urlButton) {
return {
id: i,
displayText: (_a = e.urlButton) === null || _a === void 0 ? void 0 : _a.displayText,
url: (_b = e.urlButton) === null || _b === void 0 ? void 0 : _b.url,
subtype: 'url',
};
}
if (e.callButton) {
return {
id: i,
displayText: e.callButton.displayText,
phoneNumber: e.callButton.phoneNumber,
subtype: 'call',
};
}
return {
id: i,
displayText: (_c = e.quickReplyButton) === null || _c === void 0 ? void 0 : _c.displayText,
selectionId: (_d = e.quickReplyButton) === null || _d === void 0 ? void 0 : _d.id,
subtype: 'quick_reply',
};
}));
}
else {
message.isDynamicReplyButtonsMsg = true;
message.dynamicReplyButtons = options.buttons.map((button, index) => ({
buttonId: button.id || ${index},
buttonText: { displayText: button.text },
type: 1,
}));
// For UI only
message.replyButtons = new Store.ButtonCollection();
message.replyButtons.add(message.dynamicReplyButtons.map((b) => {
var _a;
return {
id: b.buttonId,
displayText: ((_a = b.buttonText) === null || _a === void 0 ? void 0 : _a.displayText) || undefined,
};
}));
}
return message;
}

async function sendRawMessage(chatId, rawMessage, options = {}) {
options = Object.assign(Object.assign({}, defaultSendMessageOptions), options);
const chat = options.createChat
? await Store.FindChat.findChat(chatId)
: WAPI.getChat(chatId);
rawMessage = await prepareRawMessage(chat, rawMessage, options);
// if (options.markIsRead) {
// debug(marking chat is read before send message);
// // Try to mark is read and ignore errors
// await (0, _1.markIsRead)(chat.id).catch(() => null);
// }
// debug(sending message (${rawMessage.type}) with id ${rawMessage.id});
const result = await Store.addAndSendMsgToChat(chat, rawMessage);
// debug(message ${rawMessage.id} queued);
const message = await result[0];
if (options.waitForAck) {
// debug(waiting ack for ${rawMessage.id});
const sendResult = await result[1];
// debug(ack received for ${rawMessage.id} (ACK: ${message.ack}, SendResult: ${sendResult}));
}
return {
id: message.id.toString(),
ack: message.ack,
sendMsgResult: result[1],
};
}

window.WAPI.sendTextMessage = async function (chatId, content, options = {}) {
options = Object.assign(Object.assign({}, defaultSendMessageOptions), options);
let rawMessage = {
body: content,
type: 'chat',
subtype: null,
urlText: null,
urlNumber: null,
};
rawMessage = prepareMessageButtons(rawMessage, options);
// rawMessage = await (0, _1.prepareLinkPreview)(rawMessage, options);
return await sendRawMessage(chatId, rawMessage, options);
}

@mikelustosa
Copy link

mikelustosa commented Aug 3, 2022

To call, use:

WAPI.sendTextMessage('558199301443@c.us','Se liga na novidade: Novos botões voltando na Versão FREE!',
{
useTemplateButtons: true,
createChat: true,
buttons: [
{
url: 'https://wa.me/558196302385',
text: 'Fale conosco'
},
{
url: 'https://www.hci.com.br/',
text: 'Acesse nosso site'
},
{
id: '001',
text: 'Curti'
},
{
id: '002',
text: 'Show de Bola'
}
],

	footer: 'Este é um teste usando a Versão Beta MultiDevice' // Optional
}

);

@ranomail
Copy link

ranomail commented Aug 3, 2022

Gentlemen, I'm working on fixing push buttons in WAPI. At the moment it is only possible to view the buttons on whatsapp web, it remains to be corrected to display on mobile. Who can help.

### solução pronta, basta implementar com WPPConnect .
ws https://github.com/wppconnect-team/WPP4Delphi/blob/main/Source/JS/js.abr
💪🏿 (WPP4Delphi)

@ranomail
Copy link

ranomail commented Aug 3, 2022

Include conditions in getStore function:

{ id: 'Clock', conditions: (module) => (module.Clock ? module.Clock : null)}, { id: 'TemplateButtonCollection', conditions: (module) => (module.TemplateButtonCollectionImpl || module.TemplateButtonCollection ? module.TemplateButtonCollection : null)}, { id: 'ButtonCollection', conditions: (module) => (module.ButtonCollectionImpl || module.ButtonCollection ? module.ButtonCollection : null)}

Before:

function prepareMessageButtons(message, options) { if (!options.buttons) { return message; } if (!Array.isArray(options.buttons)) { throw 'Buttons options is not a array'; } if (typeof options.useTemplateButtons === 'undefined') { options.useTemplateButtons = options.buttons.some((button) => 'phoneNumber' in button || 'url' in button); } if (options.useTemplateButtons) { if (options.buttons.length === 0 || options.buttons.length > 5) { throw 'Buttons options must have between 1 and 5 options'; } } else { if (options.buttons.length === 0 || options.buttons.length > 3) { throw 'Buttons options must have between 1 and 3 options'; } } message.title = options.title; message.footer = options.footer; if (options.useTemplateButtons) { message.isFromTemplate = true; message.buttons = new Store.TemplateButtonCollection(); message.hydratedButtons = options.buttons.map((button, index) => { if ('phoneNumber' in button) { return { index: index, callButton: { displayText: button.text, phoneNumber: button.phoneNumber, }, }; } if ('url' in button) { return { index: index, urlButton: { displayText: button.text, url: button.url, }, }; } return { index: index, quickReplyButton: { displayText: button.text, id: button.id || ${index}, }, }; }); message.buttons.add(message.hydratedButtons.map((e, t) => { var _a, _b, _c, _d; const i = ${null != e.index ? e.index : t}; if (e.urlButton) { return { id: i, displayText: (_a = e.urlButton) === null || _a === void 0 ? void 0 : _a.displayText, url: (_b = e.urlButton) === null || _b === void 0 ? void 0 : _b.url, subtype: 'url', }; } if (e.callButton) { return { id: i, displayText: e.callButton.displayText, phoneNumber: e.callButton.phoneNumber, subtype: 'call', }; } return { id: i, displayText: (_c = e.quickReplyButton) === null || _c === void 0 ? void 0 : _c.displayText, selectionId: (_d = e.quickReplyButton) === null || _d === void 0 ? void 0 : _d.id, subtype: 'quick_reply', }; })); } else { message.isDynamicReplyButtonsMsg = true; message.dynamicReplyButtons = options.buttons.map((button, index) => ({ buttonId: button.id || ${index}, buttonText: { displayText: button.text }, type: 1, })); // For UI only message.replyButtons = new Store.ButtonCollection(); message.replyButtons.add(message.dynamicReplyButtons.map((b) => { var _a; return { id: b.buttonId, displayText: ((_a = b.buttonText) === null || _a === void 0 ? void 0 : _a.displayText) || undefined, }; })); } return message; }

async function sendRawMessage(chatId, rawMessage, options = {}) { options = Object.assign(Object.assign({}, defaultSendMessageOptions), options); const chat = options.createChat ? await Store.FindChat.findChat(chatId) : WAPI.getChat(chatId); rawMessage = await prepareRawMessage(chat, rawMessage, options); // if (options.markIsRead) { // debug(marking chat is read before send message); // // Try to mark is read and ignore errors // await (0, _1.markIsRead)(chat.id).catch(() => null); // } // debug(sending message (${rawMessage.type}) with id ${rawMessage.id}); const result = await Store.addAndSendMsgToChat(chat, rawMessage); // debug(message ${rawMessage.id} queued); const message = await result[0]; if (options.waitForAck) { // debug(waiting ack for ${rawMessage.id}); const sendResult = await result[1]; // debug(ack received for ${rawMessage.id} (ACK: ${message.ack}, SendResult: ${sendResult})); } return { id: message.id.toString(), ack: message.ack, sendMsgResult: result[1], }; }

window.WAPI.sendTextMessage = async function (chatId, content, options = {}) { options = Object.assign(Object.assign({}, defaultSendMessageOptions), options); let rawMessage = { body: content, type: 'chat', subtype: null, urlText: null, urlNumber: null, }; rawMessage = prepareMessageButtons(rawMessage, options); // rawMessage = await (0, _1.prepareLinkPreview)(rawMessage, options); return await sendRawMessage(chatId, rawMessage, options); }

funçao mencionada já encontra-se em https://github.com/wppconnect-team/WPP4Delphi/blob/main/Source/JS/js.abr
mas fizeste apenas alterações nas nomeclaturas das funções mas a idéia é boa, não esquece de fazer os referidos créditos ao pessoal da wppconnect-team/wpp4delphi. tmj

de function t.prepareMessageButtons = function(e, t)
para function prepareMessageButtons(message, options) {

@mikelustosa
Copy link

Gentlemen, I'm working on fixing push buttons in WAPI. At the moment it is only possible to view the buttons on whatsapp web, it remains to be corrected to display on mobile. Who can help.

### solução pronta, basta implementar com WPPConnect .ws https://github.com/wppconnect-team/WPP4Delphi/blob/main/Source/JS/js.abr 💪🏿 (WPP4Delphi)

Esse js.abr tem meu nome né? kkkkk

@ranomail
Copy link

ranomail commented Aug 3, 2022

Esse js.abr tem meu nome né? kkkkk

não sei.. só mencionei no código que você postou que 'estava' arrumando, faz parte do código do pessoal da wwpconnect, como pode comparar...só comentei a respeito do crédito do código, porém vi que vc estava apenas renomeando as funções para facilitar sua leitura de forma mais ditática e dinâmica. tmj..

@mikelustosa
Copy link

@mikelustosa
Copy link

Esse js.abr tem meu nome né? kkkkk

não sei.. só mencionei no código que você postou que 'estava' arrumando, faz parte do código do pessoal da wwpconnect, como pode comparar...só comentei a respeito do crédito do código, porém vi que vc estava apenas renomeando as funções para facilitar sua leitura de forma mais ditática e dinâmica. tmj..

Fizeram tudo baseado no meu projeto TInject. Note que eles começaram agora em 2022. O nosso teve o primeiro commit em 2019! Abraço!

Link do projeto TInject: https://github.com/mikelustosa/Projeto-TInject

@AlexDiSomma
Copy link

AlexDiSomma commented Nov 4, 2022

Full code with send buttons: https://raw.githubusercontent.com/mikelustosa/Projeto-TInject/master/Source/JS/js.abr

Hi mikelustosa, I am testing the functionality of SendButton, the message is displayed on whatsappweb without buttons and it is not sent correctly.
I use your example:
https://gist.github.com/phpRajat/a6422922efae32914f4dbd1082f3f412?permalink_comment_id=4254689#gistcomment-4254689

Am I doing something wrong? Should I create button templates before inserting the buttons?

This functionality can only be enabled on a business account right?

Thank you

@edgardmessias
Copy link

@mikelustosa se você olhar bem o nosso projeto do WPP4Delphi, temos todas as referências com o seu nome, que teve origem no TInject, alias, o Marcelo fez um grande trabalho de colocar em todo lugar que estava faltando.

Eu peço por gentileza que você faça o mesmo relacionado a parte de javascript.

Eu criei o projeto WA-JS do zero, fazendo abstrações e criando funções novas, na qual o objetivo desse projeto é ser um javascript que pode ser usado por qualquer projeto (inclusive você pode usar no TInject).

Única coisa que peço é fazer a referência correta do projeto, como exemplo o commit abaixo e a origem do código:

mikelustosa/Projeto-TInject@16e5077#diff-e1f4c52f75b4c739ee87b883b2cb0152a899308d6af98c40dac6b476c415c01e

Origem do código:

https://github.com/wppconnect-team/wa-js/blob/main/src/chat/functions/prepareRawMessage.ts

https://github.com/wppconnect-team/wa-js/blob/main/src/chat/functions/sendRawMessage.ts

https://github.com/wppconnect-team/wa-js/blob/main/src/chat/functions/sendCreatePollMessage.ts

@mikelustosa
Copy link

For now it is only possible to view the buttons on whatsapp web. We are still trying to find a solution.

@mikelustosa
Copy link

@mikelustosa se você olhar bem o nosso projeto do WPP4Delphi, temos todas as referências com o seu nome, que teve origem no TInject, alias, o Marcelo fez um grande trabalho de colocar em todo lugar que estava faltando.

Eu peço por gentileza que você faça o mesmo relacionado a parte de javascript.

Eu criei o projeto WA-JS do zero, fazendo abstrações e criando funções novas, na qual o objetivo desse projeto é ser um javascript que pode ser usado por qualquer projeto (inclusive você pode usar no TInject).

Única coisa que peço é fazer a referência correta do projeto, como exemplo o commit abaixo e a origem do código:

mikelustosa/Projeto-TInject@16e5077#diff-e1f4c52f75b4c739ee87b883b2cb0152a899308d6af98c40dac6b476c415c01e

Origem do código:

https://github.com/wppconnect-team/wa-js/blob/main/src/chat/functions/prepareRawMessage.ts

https://github.com/wppconnect-team/wa-js/blob/main/src/chat/functions/sendRawMessage.ts

https://github.com/wppconnect-team/wa-js/blob/main/src/chat/functions/sendCreatePollMessage.ts

Desculpe pela demora! Feito. Parabéns pelo belo trabalho em JS!

@rajeshshettysrs
Copy link

sir is their any way to check valid/invalid whatsapp number,please help?

@rajeshshettysrs
Copy link

Finally this solution worked. mikelustosa/Projeto-TInject#41
sir its not working after latest whatsapp update,is their any other way to check valid/invalid whatsapp numbers? plz help

@ADISOMMA
Copy link

This WAPI make some problems on reply messages, anyone find solutions?

@edgardmessias
Copy link

@ADISOMMA , you can use WPPConnect/WA-JS, look for quoteMessage while send a message

@mikelustosa
Copy link

mikelustosa commented Mar 26, 2023

sir is their any way to check valid/invalid whatsapp number,please help?

Yes. Use TInject's NewCheckIsValidNumber(number) function.

https://github.com/mikelustosa/Projeto-TInject

@sergey-chechaev
Copy link

isLoggedIn not working

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