【问题标题】:I couldn't find a working Telegraf inline query project我找不到有效的 Telegraf 内联查询项目
【发布时间】:2021-09-26 08:17:20
【问题描述】:

我想制作一个关于代数的电报机器人。我需要在 expr 部分之后将代码发送到http://api.mathjs.org/v4/?expr=2*(7-3)。我想通过内联查询发送号码,但我该怎么做?

【问题讨论】:

    标签: node.js bots telegram telegraf


    【解决方案1】:

    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

    【讨论】:

      【解决方案2】:

      您可以在https://github.com/telegraf/telegraf/tree/develop/docs/examples 找到多个 Telegraf 使用示例

      Here 是利用内联查询的机器人示例

      【讨论】:

      • 不要使用这个“内联查询”示例。我试过了
      • 什么不适合你...请给我们任何细节来处理
      • 链接中的内联查询代码不起作用
      • 你使用了那里的确切代码吗?或者你有没有用你自己的逻辑来解决它?请编辑您的消息,向我们展示您尝试过的代码和遇到的错误,以便我们以特定方式提供帮助
      • 我使用了相同的代码。我还添加了自己的机器人令牌代码
      猜你喜欢
      • 1970-01-01
      • 2021-11-12
      • 1970-01-01
      • 2018-01-01
      • 2021-08-22
      • 1970-01-01
      • 1970-01-01
      • 2018-12-22
      • 2013-12-03
      相关资源
      最近更新 更多