pedroslopez / whatsapp-web.js

A WhatsApp client library for NodeJS that connects through the WhatsApp Web browser app
https://wwebjs.dev
Apache License 2.0
14.95k stars 3.55k forks source link

bipolarity in the media #2698

Closed matheustorsani closed 8 months ago

matheustorsani commented 8 months ago

Is there an existing issue for this?

Describe the bug

Well, I'm trying to make a system that makes stickers for the user, when I send a photo it works normally, I send a video it works normally, but if I try the video again, it simply stops working.

Expected behavior

make the sticker normally, whether video or photo, photos work normally, while video always breaks the code. I am using the DownloadMedia() function. It works really well, but when I send two videos, one works, the rest make downloadMedia undefined.

Videos:

first attempt (bot has just been turned on) image in the console, it normally returns the base64 of the video.

second attempt image now, in the console it returns undefined.

Images:

first attempt image

second attempt image

Ok, I think you already understand.

Steps to Reproduce the Bug or Issue

.

Relevant Code

Archive Sticker.js

const Command = require('../../config/Command');

module.exports = class StickerCommand extends Command {
  constructor(zap) {
    super(zap, {
      name: 'sticker',
      aliases: ['figurinha', 's', 'fig'],
      category: 'utils',
      description: 'Deixe-me fazer um sticker com alguma foto/gif/vídeo que tu me mandar! (Às vezes pode bugar!)',
      example: 'sticker <arquivo>',
      groupOnly: false,
      groupAdmPermission: {
        bot: false,
        user: false,
      },
      ownerOnly: false,
      isWorking: true,
    });
  }

  async execute({ msg, prefix }) {
    try {
      const quotedMsg = await msg.getQuotedMessage();
      const mediaQuoted = quotedMsg && quotedMsg.hasMedia ? await quotedMsg.downloadMedia() : null;
      const media = msg.hasMedia ? await msg.downloadMedia() : null;

      if (!media && !mediaQuoted) {
        return await msg.send(`Oops, mencione ou mande a imagem/gif/vídeo que tu quer e escreva no texto "${prefix}s"`, { reply: true });
      }

      await msg.send('Seu sticker está a caminho!!!', { reply: true });

      if (media) {
        try {
          await msg.sendSticker(media);
        } catch (error) {
          console.log(error);
        }
      }

      if (mediaQuoted) {
        try {
          await msg.sendSticker(mediaQuoted);
        } catch (error) {
          console.log(error);
        }
      }
    } catch (err) {
      await msg.zapFail(err);
    }
  }
};

Archive message.js (msg.sendSticker function)

 msg.sendSticker = async (sticker) => {
      const errortext = 'Não foi possível transformar o arquivo em um sticker. Se por acaso você estiver enviando um vídeo, na hora de enviar selecione a opção "gif".\nhttps://is.gd/aJNpv7';

      try {
        await zap.atizap.sendMessage(msg.from, sticker, { sendMediaAsSticker: true, stickerAuthor: '*************', stickerName: 'Skye! ❤' })
          .catch(e => {
            msg.zapFail(errortext + '\n\n' + e)
            msg.react("❎")
          }
          );
        msg.react("✅")
      } catch (error) {
        msg.zapFail('Erro ao processar o sticker: ' + error);
      }
    };

Browser Type

Google Chrome

WhatsApp Account Type

WhatsApp Business

Does your WhatsApp account have multidevice enabled?

Yes, I am using Multi Device

Environment

OS: Windows 10 Phone OS: Android whatsapp-web.js version: 1.23.0 WhatsApp Web version 2.2353.59 Node.js Version v21.4.0

Additional context

No response

alechkos commented 8 months ago

1621