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-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(..)
正在返回预期的消息?
这个原因你的工作不起作用是因为你称它为parse_mode
而不是parseMode
(See 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
,这是回复:
你走了希望能帮助到你