skip to Main Content

I want to make a telegram bot about algebra. I need to send code to http://api.mathjs.org/v4/?expr=2*(7-3) after the expr part. I want to send numbers with inline query, but how can I do it?

2

Answers


  1. You can find multiple examples of Telegraf usage at https://github.com/telegraf/telegraf/tree/develop/docs/examples

    Here is an example of a bot utilizing an inline query

    Login or Signup to reply.
  2. The original example uses context object deconstruction, which doesn’t seem to work and spits out error:

    TypeError: Cannot read property 'assert' of undefined

    Here is the code without object deconstruction, which works for me (I’ve made it superfluously verbose for better understanding ):

    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;
    });
    

    Here is the article that helped me to solve this problem.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search