![](/img/trans.png)
[英]Cannot use Inline keyboard and parse mode together in node js telegram bot?
[英]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 });
});
通過/s <param>
我想在電報中獲得一些超鏈接 。 但我沒有得到[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
( 參見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
,這是回復:
你走了 希望能幫助到你
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.