A simple library to decrypt and download WhatsApp media files directly from message payloads.
npm install @w3nder/media-downloader
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);
}
}
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 install
-
Update the media keys in
examples/download-media.ts
with your WhatsApp message data. -
Run the example:
npm run example
The example will attempt to download different types of media and save them to the downloads
directory.
- Audio Messages
- Images
- Videos
- Documents
- Stickers
Decrypts and saves WhatsApp media.
payload
: Message payload containing media informationoutputDir
: Directory to save the file (default: 'output')
{
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
}
MIT