open-wa / wa-automate-nodejs

💬 🤖 The most reliable tool for chatbots with advanced features. Be sure to 🌟 this repository for updates!
https://docs.openwa.dev/
Other
3.07k stars 592 forks source link

Today I realized that Send Images no longer works Do you have any idea ? #78

Closed tsapap closed 4 years ago

tsapap commented 4 years ago

Describe the bug Today 29-01-2020 I realized that Send Images no longer works Do you have any idea ?

To Reproduce Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior A clear and concise description of what you expected to happen.

sulla-hotfix version Which sulla-hotfix version

Whatsapp version Go to console in the chromium/chrome instance and type window.Debug.VERSION

Screenshots If applicable, add screenshots to help explain your problem. Use headless: false to get screenshots

Host (please complete the following information):

Additional context Add any other context about the problem here.

smashah commented 4 years ago

@stefano71 please fill out the template more thoroughly. I've just tested it and it is working ok so I will need more info for reproduction

tsapap commented 4 years ago

I'm not getting any error messages. the wapi.sendimage function after I cleared the chrome cache doesn't work

rizki96 commented 4 years ago

@smashah I'm also getting the same problem, sendImage function is not working. After debugging the sendImage code then I've found out that this line is crashing var mc = new Store.MediaCollection()

I've tried on both macosx and linux, tried also on sulla-hotfix 1.5.x and 1.6.10, all have the same behaviour.

tsapap commented 4 years ago

image

this is the error message that has now occurred in the chrome console

duzaq commented 4 years ago

error message WAPI.sendImage erro_wp

nicolaubrasil commented 4 years ago

error message WAPI.sendImage erro_wp

Search for all occurrences of mediaCollection and replace: var mc = new Store.MediaCollection(); to var mc = new Store.MediaCollection(chat);

smashah commented 4 years ago

Can you all share you whatsapp version please.

In the console in the browser run window.Debug.VERSION

tsapap commented 4 years ago

with this change it works Search for all occurrences of mediaCollection and replace: var mc = new Store.MediaCollection(); to var mc = new Store.MediaCollection(chat);

thanks

smashah commented 4 years ago

@stefano71 @nicolaubrasil As it seems to work for you, I'll implement this now

smashah commented 4 years ago

Should be live in v1.6.11

smashah commented 4 years ago

Closing this for now. Please reopen if it happens again

duzaq commented 4 years ago

The problem really came back, with the last modification above.

error_whats_

haroldorodsilva commented 4 years ago

I tried now and the image was not send.

@smashah Debug Info { WA_VERSION: '0.4.930', PAGE_UA: 'WhatsApp/0.4.613 Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36', SULLA_HOTFIX_VERSION: '1.7.24', BROWSER_VERSION: 'HeadlessChrome/79.0.3945.0' }

smashah commented 4 years ago

@haroldorodsilva @duzaq new version of WhatsApp :/

marcelocecin commented 4 years ago

change this

{ id: "MediaCollection", conditions: (module) => (module.default && module.default.prototype && module.default.prototype.processFiles !== undefined) ? module.default : null },

mc.processFiles([mediaBlob], chat, 1).then(() => {
    var media = mc.models[0];
    media.sendToChat(chat, { caption: caption });
    if (done !== undefined) done(true);
});

to this

{ id: "MediaCollection", conditions: (module) => (module.default && module.default.prototype && module.default.prototype.processAttachments) ? module.default : null },

if (Debug.VERSION === '0.4.613') {
    mc.processAttachments([mediaBlob], chat, 1).then(() => {
        var media = mc.models[0];
        media.sendToChat(chat, {caption: caption});
        if (done !== undefined) done(true);
    });
} else {
        mc.processAttachments([{file: mediaBlob}], chat, 1).then(() => {
        var media = mc.models[0];
        media.sendToChat(chat, {caption: caption});
        if (done !== undefined) done(true);
    });
}
gildastema commented 4 years ago

send image not work

smashah commented 4 years ago

@gildastema @marcelocecin @haroldorodsilva @duzaq Fix is live in v.1.7.25

I've tested it here and it's working. Please report back ASAP if it is/is not working for you.

Thanks

tsapap commented 4 years ago

I have the same problem too on mac while on windows it works could it depend on the user agent? it is strange that on chrome mac whatsapp web responds differently

smashah commented 4 years ago

@stefano71 did you try latest version 1.7.25? Also please share your debug info on both systems for context

tsapap commented 4 years ago

i was wrong by clearing the chrome cache on windows i get the same mac error

VM1223:1442 Uncaught TypeError: Cannot read property 'createWid' of undefined at Object.window.WAPI.sendImage (:1442:39) at :2097:13

has anyone solved it?

tsapap commented 4 years ago

@stefano71 did you try latest version 1.7.25? Also please share your debug info on both systems for context

yes

smashah commented 4 years ago

@stefano71 this appears to be a seperate problem if it is still happnening then please make a new issue. Closing this for now.

tsapap commented 4 years ago

with your wapi.js I can't send images i tried this and it works even if it also sends to wrong numbers.

https://raw.githubusercontent.com/blubbll/wabot/72fd4f6353109d7f933f78942b03c3dd7fcd84a5/inject/WAPI.js

marcelocecin commented 4 years ago

please attach print with the error

tsapap commented 4 years ago

unfortunately I get this error
VM2223:1458 Uncaught TypeError: Cannot read property 'createWid' of undefined at Object.window.WAPI.sendImage (:1458:39) at :2131:13

tsapap commented 4 years ago

image

smashah commented 4 years ago

@stefano71 please clear your console history

tsapap commented 4 years ago

It works well only the control of sending the file on the wrong phone number is missing. unfortunately the file is also sent to non-existent numbers

tsapap commented 4 years ago

now if the number is wrong the file is not sent please you can check if everything is correct

window.WAPI.sendImage = function(imgBase64, chatid, filename, caption, done) { try { //alert 'WhatsApp'; window.getContact = chatid => { return Store.WapQuery.queryExist(chatid); //alert 'WhatsApp'; }; window.getContact(chatid).then(contact => { if (contact.status === 404) { //alert 'WhatsApp Error'; done(true); } else { Store.Chat.find(contact.jid) .then(chat => { //chat.sendMessage(message); //alert("1"); //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(chat); mc.processAttachments([{ file: mediaBlob }, 1], chat, 1).then(() => { var media = mc.models[0]; media.sendToChat(chat, { caption: caption }); if (done !== undefined) done(true); }); }); ////alert 'WhatsApp'; return true; }) .catch(reject => { if (WAPI.sendMessage(chatid, message)) { //alert("2"); } else {
//alert("3"); } }); } }); } catch (e) { if (window.Store.Chat.length === 0) { //alert 'WhatsApp'; return false};

firstChat = Store.Chat.models[0];
var originalID = firstChat.chatid;
firstChat.chatid =
  typeof originalID === "string"
    ? chatid
    : new window.Store.UserConstructor(chatid, {
        intentionallyUsePrivateConstructor: true
      });
if (done !== undefined) {
  firstChat.sendMessage(message).then(function() {
    firstChat.chatid = originalID;
    done(true);
  });
  //alert 'WhatsApp';
  return true;
} else {
  //firstChat.sendMessage(message);
  //firstChat.id = originalID;
              //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(chat);
                mc.processAttachments([{ file: mediaBlob }, 1], chat, 1).then(() => {
                  var media = mc.models[0];
                  media.sendToChat(chat, { caption: caption });
                  if (done !== undefined) done(true);
                });
              });     
  //alert 'WhatsApp';
  return true;
}

} if (done !== undefined) done(false); return false; };