Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interception issue on documents while using new message event listener #2631

Open
ashishNiswey opened this issue Jan 8, 2025 · 0 comments
Open

Comments

@ashishNiswey
Copy link

WA-JS Version

3.16

WhatsApp Version

2.3000.1019206571

Browser Version

131.0.6778.265

Operation System

Windows 11 Enterprise

Steps to reproduce

I'm using wa-js in chrome extension to listen to new messages and sync them to connected CRM.

using the following code after initiating the WPP and sending a docx or pptx file from WhatsApp web UI

WPP.ev.on("chat.new_message", async (message) => {
processMessage(message, "single"); //handle text and media messages
});

async function processMessage(message, type) {
try {
if (!message?.type) {
console.warn("Invalid message structure");
return;
}

if (["document", "image", "video", "audio"].includes(message.type)) {
  const fileResponse = await handleMediaMessage(message);
} else if (message.type != "chat") {
  console.log(`Message type ${message.type} not supported for HS sync`);
  return;
}

// logic for CRM sync
} catch (error) {
console.warn(Error processing message: ${message?.id || "Unknown"}, error);
}
}

async function handleMediaMessage(message) {
try {
console.log("Media message detected:", message);

const mediaData = await WPP.chat.downloadMedia(message.id);

if (mediaData) {
  // Convert Blob to Base64
  const base64Media = await blobToBase64(mediaData);

  // Use or return the base64 string as needed

  return { body: base64Media, fileName: mediaData.name };
} else {
  console.warn("Failed to download media.");
  return null;
}

} catch (error) {
console.warn("Error handling media message:", error);
return null;
}

What is expected?

It should handle all media and text and document type messages and above code should be able to sync messages to CRM

What is actually happening?

It's only working with text and media and when it comes to documents, I'm able to intercept it using above code but actual messages is not able to go, and it went through when we retry it.
it works with pdf files though but not working with docx, pptx etc

I'm using WPP.chat.downloadMedia(message.id); to download media

SS of error: Here photo is sent on one go but docs are not processing

Screenshot 2025-01-08 190442

Any additional comments?

I think there is some interception issue while sending few documents, while it worked well with media files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant