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

Telegraf.js机器人如何创建不触发@提及通知的用户链接?

避免Telegraf.js发送用户资料链接时触发@通知的方法

在群组中发送包含tg://user?id=xxx的用户资料链接时,Telegram会自动识别为对该用户的提及,从而触发@通知。要解决这个问题,你可以通过将链接绑定到不可见字符的方式,既保留跳转功能,又避免触发通知。

修改后的代码:

const msg = data?.sort((a, b) => b.rating - a.rating)
  .reduce((acc, item, index) => {
    if (index > 14) return acc;
    // 用零宽空格(​)作为链接载体,用户名单独加粗
    acc += `🌟 <a href="tg://user?id=${item.user_id}">&#8203;</a><b>${item.user_name}</b> - ${item.rating}\n`;
    return acc;
  }, '');
ctx.replyWithHTML(`Top 15 gamers:\n${msg}`).catch((err) => console.error(err));

关键说明:

  • 零宽空格(&#8203;)是不可见的特殊字符,用户视觉上看不到它,但点击该字符所在的区域(即用户名附近)仍能正常打开用户资料页面。
  • 你之前设置的disable_notification: true仅用于关闭消息的推送通知(比如手机弹窗提示),无法阻止@用户的提及通知,因此可以移除该参数。

内容的提问来源于stack exchange,提问作者Dimi-Dun-Morogh

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.25 09:15:41