Whatsapp-web.js:是否可以像Web客户端一样添加WhatsApp消息的URL预览

问题描述 投票:0回答:1
使用以下代码,我可以使用whatsapp使用

curl

命令成功将短信发送到电话号码:

const { Client } = require('whatsapp-web.js'); const qrcode = require('qrcode-terminal'); const express = require('express'); const bodyParser = require('body-parser'); const app = express(); app.use(bodyParser.json()); const client = new Client({ puppeteer: { args: ['--no-sandbox'], } }); client.on('qr', (qr) => { console.log('QR Code received, scan it with your phone.'); qrcode.generate(qr, { small: true }); }); client.on('ready', () => { console.log('Client is ready!'); }); client.initialize(); app.post('/send-message', async (req, res) => { const { number, text } = req.body; if (!number || !text) { return res.status(400).json({ error: 'Missing number or text' }); } try { await client.sendMessage(`${number}@c.us`, text, { linkPreview: true }); console.log(`Message sent to ${number}: ${text}`); res.status(200).json({ success: 'Message sent' }); } catch (error) { console.error('Error sending message:', error); res.status(500).json({ error: 'Error sending message' }); } }); const PORT = process.env.PORT || 3000; app.listen(PORT, () => { console.log(`Server is running on port ${PORT}`); });
到了

curl

,我可以跑

curl -H "Content-Type: application/json" -d '{"number": "1234567890", "text": "text http://stackoverflow.com "}'
但即使有

linkPreview: true

,我也没有预览。
tried:

await client.sendMessage(`${number}@c.us`, text, { linkPreview: { includePreview: true }});

或:
await client.sendMessage(`${number}@c.us`, text);

没有工作

您找到解决问题的解决方案吗?

javascript node.js curl puppeteer whatsapp
1个回答
0
投票

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.