Automate WhatsApp Document Sharing with Node.js/JavaScript
Looking to automate PDF delivery, document notifications, or file sharing from your JavaScript applications? This guide walks you through sending PDF files to WhatsApp users using Node.js and the WhatsMate WA Gateway REST API. Perfect for JavaScript developers, full-stack engineers, and Node.js enthusiasts who want to integrate document delivery into their JavaScript-based WhatsApp messaging workflows.
📋 Prerequisites
Before you begin, ensure you have:
- A WhatsMate WA Gateway account - Required for API access
- Recipient registration - Each recipient must register with the Gateway first
- Node.js installed - Version 12+ recommended for modern JavaScript features
- PDF file ready - Have the document you want to send available locally
⚠️ Important: Recipients must register with the WhatsMate WA Gateway before they can receive messages. Unregistered users will not receive any messages from the Gateway. Registration instructions are available on the official WhatsMate site.
📝 Step-by-Step Implementation
Follow these steps to send your first PDF document to a WhatsApp user from a Node.js application:
1. Copy the Node.js Code Template
Start by copying the following source code into your JavaScript file:
2. Configure a few Parameters
Customize these key parameters in the Node.js code:
- Lines 7-9: Replace
YOUR_OWN_GATEWAY_INSTANCE_ID,YOUR_OWN_CLIENT_ID, andYOUR_OWN_SECRET_IDwith your WhatsApp gateway instance ID, Client ID, and Secret - Line 12: Replace
12025550108with the target phone number (including the country code) - Line 13: Replace
../assets/subwaymap.pdfwith the path to your PDF file - Line 14: Replace
anyname.pdfwith the desired filename for the document - Line 15: Replace
Hope you like itwith an optional caption for your PDF
3. Make the Script Executable
Set execute permissions on your script (if needed):
chmod 755 send-pdf-individual.js
4. Send Your PDF Document
Run the Node.js script to deliver your PDF to WhatsApp:
./send-pdf-individual.js
🔧 Common Use Cases
This automation approach is ideal for:
- Automated report delivery - Send daily/weekly PDF reports to WhatsApp from Node.js applications
- Document sharing automation - Deliver invoices, receipts, or contracts via WhatsApp using Node.js
- System documentation - Share configuration files or logs as PDF documents from JavaScript systems
- Educational content - Distribute learning materials or tutorials through WhatsApp from Node.js apps
- Integration with JavaScript document generation - Combine with Node.js libraries that create PDFs for WhatsApp delivery
🚀 Get Started Today
Ready to automate your document sharing over WhatsApp with Node.js? You’ll need a trial account to access the API. Sign up for a 2-week trial and start sending PDF files within minutes!
Next Steps: Once you’ve mastered basic PDF sending, explore advanced features like sending images or group messages through the WhatsMate WA Gateway API documentation.