[英]How to use 'Markdown' in parse_mode of telegram bot?
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 });
});
By /s <param>
I want to get some hyperlink in telegram. 通过
/s <param>
我想在电报中获得一些超链接 。 But instead of that I'm getting [hyperlink](http://some_url)
. 但我没有得到
[hyperlink](http://some_url)
。
What is going wrong here? 这里出了什么问题? The
message
here is always a string like [title](url)
. 这里的
message
总是像[title](url)
这样的字符串。
Are you using the node-telegram-bot-api npm module? 你在使用node-telegram-bot-api npm模块吗?
I think you want to be using bot.onText
method not .on
. 我想你想使用
bot.onText
方法而不是.on
。 I've just tried with both, and when using .on the callback function never runs. 我刚试过两个,当使用.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 });
});
Have you tried adding some kind of logging to this method to see if it ever actually runs, and that your getBySearchQuery(..)
is returning the expected message? 您是否尝试过向此方法添加某种日志记录以查看它是否实际运行,并且您的
getBySearchQuery(..)
正在返回预期的消息?
This reason yours isn't working is because you called it parse_mode
instead of parseMode
( See doc ) 你的这个原因不起作用是因为你称之为
parse_mode
而不是parseMode
( 参见doc )
Try this, it should work. 试试这个,它应该工作。
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();
Okay, I tested it and it works well. 好的,我测试了它,效果很好。 I sent
/s ert
and here was the response: 我发送了
/s ert
,这是回复:
So now let me click Google
and you'll see the popup: 所以现在让我点击
Google
,你会看到弹出窗口:
THERE YOU GO. 你走了 Hope it helps
希望能帮助到你
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.