You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用whatsapp-web.js发送WhatsApp消息时如何启用URL预览?

WhatsApp消息无法显示URL预览问题

我通过以下Node.js代码搭建服务,借助curl命令能成功向指定手机号发送WhatsApp文本消息,但消息中的URL始终无法显示预览效果,即使调整linkPreview相关参数也无法解决。

服务代码

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 }调用sendMessage
  • 传递参数{ linkPreview: { includePreview: true }}调用sendMessage
  • 不传递任何linkPreview参数,直接调用sendMessage

以上三种方式均无法让消息中的URL显示预览,实际效果截图:
WhatsApp消息无URL预览

内容的提问来源于stack exchange,提问作者Mévatlavé Kraspek

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.20 08:42:55