-
-
Notifications
You must be signed in to change notification settings - Fork 671
Description
Are you using the latest version of the library?
- I have checked and am using the latest version of the library.
What type of session are you experiencing this issue on?
Tested and experienced on both
What type of host account are you experiencing this issue on?
Personal account (normal)
Mode
EASY API/CLI
Current Behavior
await client.sendImage(id, './image.jpg', 'image.jpg', 'Here is JPG image');
ssues is only png file i am not able to send base64 or direct ❌ Error sending file: b: b
at #evaluate (C:\Users\virch\CascadeProjects\invitationcard\node_modules\puppeteer-core\lib\cjs\puppeteer\cdp\ExecutionContext.js:391:56)
at async ExecutionContext.evaluate (C:\Users\virch\CascadeProjects\invitationcard\node_modules\puppeteer-core\lib\cjs\puppeteer\cdp\ExecutionContext.js:278:16)
at async IsolatedWorld.evaluate (C:\Users\virch\CascadeProjects\invitationcard\node_modules\puppeteer-core\lib\cjs\puppeteer\cdp\IsolatedWorld.js:100:16)
at async CdpFrame.evaluate (C:\Users\virch\CascadeProjects\invitationcard\node_modules\puppeteer-core\lib\cjs\puppeteer\api\Frame.js:348:20)
at async CdpPage.evaluate (C:\Users\virch\CascadeProjects\invitationcard\node_modules\puppeteer-core\lib\cjs\puppeteer\api\Page.js:812:20)
Expected Behavior
No response
Steps To Reproduce
// wa_automate_api.js
// WhatsApp automation API using open-wa/wa-automate-nodejs
// Run: npx wa-automate --help for CLI usage or use as a library
const wa = require('@open-wa/wa-automate');
const express = require('express');
const multer = require('multer');
const fs = require('fs');
const path = require('path');
const app = express();
const port = 3001;
const upload = multer({ dest: 'uploads/' });
const filePath = "C:\Users\virch\CascadeProjects\invitationcard\output_invitations\test.png"
//const filePath = "C:\Viral\skc\test.pdf"
let clientInstance = null;
wa.create({
sessionId: 'INVITE',
multiDevice: true,
headless: false,
qrTimeout: 0,
authTimeout: 0,
cacheEnabled: true,
useChrome: true,
killProcessOnBrowserClose: false,
chromiumArgs: ['--no-sandbox', '--disable-setuid-sandbox'],
}).then(async client => {
clientInstance = client;
console.log('✅ open-wa client ready!');
// Send a message to a contact (replace with actual number)
const id = '[email protected]'; // Contact WhatsApp ID (no + or spaces)
try {
console.log('✅ [email protected]!');
if (!require('fs').existsSync(filePath)) {
console.log('❌ File not found:', filePath);
return;
}
const imageBase64 = fs.readFileSync(filePath, 'base64');
await client.sendFile(id, `data:image/png;base64,${imageBase64}`, 'image.png', 'Please see attached document.');
console.log('✅ File sent with caption');
} catch (e) {
console.error('❌ Error sending file:', e);
}
}).catch(e => {
console.error('❌ open-wa client error:', e);
});
app.post('/send', upload.single('image'), async (req, res) => {
if (!clientInstance) return res.status(503).json({ error: 'Client not ready' });
const { number, message } = req.body;
if (!number) return res.status(400).json({ error: 'Missing number' });
const chatId = number.includes('@c.us') ? number : ${number}@c.us;
try {
if (req.file) {
const filePath = path.join(__dirname, req.file.path);
const mediaData = fs.readFileSync(filePath, { encoding: 'base64' });
await clientInstance.sendImage(chatId, filePath, path.basename(filePath), message || '');
fs.unlinkSync(filePath);
} else if (message) {
await clientInstance.sendText(chatId, message);
} else {
return res.status(400).json({ error: 'No image or message provided' });
}
res.json({ status: 'sent', to: chatId });
} catch (err) {
res.status(500).json({ error: err.message });
}
});
app.listen(port, () => {
console.log(🚀 open-wa API server running at http://localhost:${port});
});
create() code OR full CLI command + CONFIG
DEBUG INFO
√ https://github.com/open-wa/wa-automate-nodejs/issues/new?template=bug_report.yaml&d_info=%7B%0A%20%20%22WA_VERSION%22:%20%222.3000.1024801671%22,%0A%20%20%22WA_AUTOMATE_VERSION%22:%20%224.76.0%22,%0A%20%20%22BROWSER_VERSION%22:%20%22Chrome/138.0.7204.158%22,%0A%20%20%22START_TS%22:%201752673081582,%0A%20%20%22RAM_INFO%22:%20%22Total:%2033.75%20GB%20%7C%20Free:%2013.51%20GB%22,%0A%20%20%22PPTR_VERSION%22:%20%2223.11.1%22,%0A%20%20%22LATEST_VERSION%22:%20true,%0A%20%20%22CLI%22:%20false,%0A%20%20%22PATCH_HASH%22:%20%22300da%22,%0A%20%20%22LAUNCH_TIME_MS%22:%2017758,%0A%20%20%22ACC_TYPE%22:%20%22PERSONAL%22,%0A%20%20%22chats%22:%20137,%0A%20%20%22messages%22:%20266,%0A%20%20%22contacts%22:%202483,%0A%20%20%22isBiz%22:%20false,%0A%20%20%22isMd%22:%20true,%0A%20%20%22INSTANCE_ID%22:%20%22d95c6366-92a4-419d-86eb-516282a00c59%22%0A%7D&enviro=-%20OS:%20Windows%2010%0A-%20Node:%2020.14.0%0A-%20npm:%2010.7.0&labels=MD,PHA
√ 🚀 @OPEN-WA ready for account: 4105
❌ Error sending file: b: b
at #evaluate (C:\Users\virch\CascadeProjects\invitationcard\node_modules\puppeteer-core\lib\cjs\puppeteer\cdp\ExecutionContext.js:391:56)
at async ExecutionContext.evaluate (C:\Users\virch\CascadeProjects\invitationcard\node_modules\puppeteer-core\lib\cjs\puppeteer\cdp\ExecutionContext.js:278:16)
at async IsolatedWorld.evaluate (C:\Users\virch\CascadeProjects\invitationcard\node_modules\puppeteer-core\lib\cjs\puppeteer\cdp\IsolatedWorld.js:100:16)
at async CdpFrame.evaluate (C:\Users\virch\CascadeProjects\invitationcard\node_modules\puppeteer-core\lib\cjs\puppeteer\api\Frame.js:348:20)
at async CdpPage.evaluate (C:\Users\virch\CascadeProjects\invitationcard\node_modules\puppeteer-core\lib\cjs\puppeteer\api\Page.js:812:20)Environment
- OS:
- Node:
- npm:Screenshots/Logs
No response
Anything else?
No response