如何在电报机器人的parse_mode中使用'Markdown'?

问题描述 投票:0回答:2
bot.on(/^\/s (.+)$/, async function(msg, props) {
      let id = msg.chat.id;
      let message = await MyBot.getBySearchQuery(props.match[1]);
      let parse_mode = 'Markdown';
      return bot.sendMessage(id, message, { parse_mode });
    });

通过/s <param>我想在电报中得到一些hyperlink。但而不是我得到[hyperlink](http://some_url)

这里出了什么问题?这里的message总是像[title](url)这样的字符串。

node.js telegram-bot
2个回答
0
投票

你在使用node-telegram-bot-api npm模块吗?

我想你想使用bot.onText方法而不是.on。我刚试过两个,当使用.on时,回调函数永远不会运行。

bot.onText(/^\/s (.+)$/, async function(msg, props) {
  let id = msg.chat.id;
  let message = await MyBot.getBySearchQuery(props.match[1]);
  let parse_mode = 'Markdown';
  return bot.sendMessage(id, message, { parse_mode });
});

您是否尝试过向此方法添加某种日志记录以查看它是否实际运行,并且您的getBySearchQuery(..)正在返回预期的消息?


0
投票

这个原因你的工作不起作用是因为你称它为parse_mode而不是parseModeSee doc

试试这个,它应该工作。

const TeleBot = require('telebot');

const bot = new TeleBot('35353453:sfsdfsdffgrtyrty454646thfhfgfgh')

bot.on(/^\/s (.+)$/, async function(msg, props) {
  const id = msg.chat.id;
  const url = "https://google.com";
  const message = `Read more about [Google](${url}) now!!!!`;

  return bot.sendMessage(id, message, { parseMode: 'Markdown' });
});

bot.start();

好的,我测试了它,效果很好。我发送了/s ert,这是回复:

enter image description here

所以现在让我点击Google,你会看到弹出窗口:enter image description here

你走了希望能帮助到你

© www.soinside.com 2019 - 2024. All rights reserved.