@w3nder/media-downloader
v1.0.8
Published
A simple library to decrypt and download media files directly from message payloads.
Downloads
78
Readme
media-downloader
A simple library to decrypt and download WhatsApp media files directly from message payloads.
Installation
npm install @w3nder/media-downloaderUsage
import { decryptWhatsAppMedia } from '@w3nder/media-downloader';
// Example with a document message
const payload = {
message: {
documentMessage: {
url: "https://mmg.whatsapp.net/...",
mimetype: "application/pdf",
mediaKey: "base64EncodedKey...",
fileName: "document.pdf"
}
}
};
async function downloadMedia() {
try {
const result = await decryptWhatsAppMedia(payload, 'downloads');
console.log('File saved at:', result.outputPath);
} catch (error) {
console.error('Error downloading media:', error);
}
}Running the Example
The package includes an example that demonstrates how to download different types of WhatsApp media (documents, images, videos).
- Clone the repository:
git clone https://github.com/w3nder/media-downloader.git
cd wa-download- Install dependencies:
npm installUpdate the media keys in
examples/download-media.tswith your WhatsApp message data.Run the example:
npm run exampleThe example will attempt to download different types of media and save them to the downloads directory.
Supported Media Types
- Audio Messages
- Images
- Videos
- Documents
- Stickers
API
decryptWhatsAppMedia(payload, outputDir?)
Decrypts and saves WhatsApp media.
Parameters
payload: Message payload containing media informationoutputDir: Directory to save the file (default: 'output')
Returns
{
outputPath: string, // Path where the file was saved
mediaType: string, // Type of media (audio, image, video, document, sticker)
mimeType: string, // File MIME type
fileName: string // Name of the saved file
}License
MIT
