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

on media send not able to send PDf with my own file name #1200

Open
tls-jil opened this issue Jan 10, 2025 · 1 comment
Open

on media send not able to send PDf with my own file name #1200

tls-jil opened this issue Jan 10, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@tls-jil
Copy link

tls-jil commented Jan 10, 2025

I have the following code for sending media for using base64 and direct URL

while only facing issue with the PDF on other doc files it's properly working for more ref I attached a screenshot

// if get media direact URL
messageContent = {
[mediaType]: {
url: image,
mimetype: mimeType,
fileName: file_name,
},
caption,
};

// if get base64
messageContent = {
[mediaType]: mediaBuffer,
mimetype: mimeType,
fileName: file_name,
caption,
};
}

  console.log("messageContent :>> ", messageContent);
  const sendResult = await wpClient.sendMessage(
    `${number}@c.us`,
    messageContent
  );

Reference Screenshot
Group 14

@tls-jil tls-jil added the bug Something isn't working label Jan 10, 2025
@tls-jil
Copy link
Author

tls-jil commented Jan 10, 2025

if i send pdf with base64 then it's send properly with PDF name or other doc name but I have direct file URL and file name

const sendMedia = async (
wpClient,
number,
URL,
file_name,
caption = "",
mediaType = undefined
)


// Convert to Base64 for URLs without extensions
        const base64Result = await convertUrlToBase64(image);
        if (base64Result.status === 1) {
          const { data: base64Data, mimeType } = base64Result;
          // Determine media type

          // Convert Base64 to Buffer
          const mediaBuffer = base64Data.includes("data:")
            ? Buffer.from(base64Data.split(",")[1], "base64") // Extract payload if data URL
            : Buffer.from(base64Data, "base64"); // Raw Base64 without data URLExtract payload
          const mediaType = mimeType.startsWith("image")
            ? "image"
            : mimeType.startsWith("video")
            ? "video"
            : mimeType.startsWith("audio")
            ? "audio"
            : "document"; // Default to document for other types
          messageContent = {
            [mediaType]: mediaBuffer,
            mimetype: mimeType,
            fileName: file_name,
            caption,
          };
        }
        
        const sendResult = await wpClient
        .sendMessage(
          // `${number}@c.us`,
          `${number}@s.whatsapp.net`,
          messageContent
        )
        .catch((err) => {
          return isMessageSend;
        });

      console.log("sendResult :>> ", sendResult);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant