【发布时间】:2021-09-26 08:17:20
【问题描述】:
我想制作一个关于代数的电报机器人。我需要在 expr 部分之后将代码发送到http://api.mathjs.org/v4/?expr=2*(7-3)。我想通过内联查询发送号码,但我该怎么做?
【问题讨论】:
标签: node.js bots telegram telegraf
我想制作一个关于代数的电报机器人。我需要在 expr 部分之后将代码发送到http://api.mathjs.org/v4/?expr=2*(7-3)。我想通过内联查询发送号码,但我该怎么做?
【问题讨论】:
标签: node.js bots telegram telegraf
original example 使用上下文object deconstruction,这似乎不起作用并吐出错误:
TypeError: Cannot read property 'assert' of undefined
这是没有对象解构的代码,它对我有用(为了更好地理解,我把它写得过于冗长了):
bot.on('inline_query', async (ctx) => {
const offset = parseInt(ctx.inlineQuery.offset) || 0;
let items = [];
for(var i = 0; i < 100; i++) {
items.push({ title: 'Item '+i, desc: 'item '+i+' desc', id: '0000'+i, moreinfo: 'More info about item'+i+', mucho importante information'})
}
let results = items.slice(offset, offset+10).map((item) => ({
type: "article",
id: item.id,
title: item.title,
description: item.desc,
input_message_content: {
message_text: '*'+item.title+'*\n'+item.desc,
parse_mode: 'Markdown'
},
reply_markup: {
inline_keyboard: [
[{ text: 'More info', callback_data: 'moreinfo' }]
]},
hide_url: true,
url: 'http://www.domain.se/'+item.id,
}));
console.log('hello');
let ourReturn = ctx.answerInlineQuery(results, {is_personal: true, next_offset: offset+results.length, cache_time: 10});
return ourReturn;
});
这是帮助我解决这个问题的article。
【讨论】:
您可以在https://github.com/telegraf/telegraf/tree/develop/docs/examples 找到多个 Telegraf 使用示例
Here 是利用内联查询的机器人示例
【讨论】: