Telegram.Bot: [Error : 400 : Bad Request: QUERY_ID_INVALID]

var link1 = new InlineQueryResultArticle()
            {
               Id = "1",//Guid.NewGuid().ToString("N"),
                Description = "Description",
                DisableWebPagePreview = false,
                HideUrl = true,
                ParseMode = ParseMode.Html,
                MessageText = "Text",
                Url = "https://kompstar.com/catalog/329649/471772/200000045/i4117225.html",
                Title = "res1"
            };

I am getting this error on both ways of asign value to ID property. It’s so strange that this exception throwed after the different sequence of operations from time to time. Is it known problem or I’m doing something wrong?

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 2
  • Comments: 18 (9 by maintainers)

Most upvoted comments

I tested it and I got an error exactly after 10 seconds delay. So you have to reply within 10 seconds

hi you must answer InlineQuery and CallbackQuery until 15 seconds. after that recive QUERY_ID_INVALID

I’m getting this same error even though I’m answering the query in less than 2 seconds. The data I’m trying to POST back is

{
    inline_query_id: '216443202',
    results: '[{"type":"article","id":"1533502232641_0","title":"Test Result","input_message_content":{"message_text":"This was a triumph","parse_mode":"Markdown"}}]'
}

The ID I’m using is the ID of the incoming query. I’ve no idea what else to try at this point. Google only points me to more solutions regarding the timeout of the reply.

I receive [Error : 400 : Bad Request: QUERY_ID_INVALID] if I delay the response by 8-10 seconds. But can’t find anything in the docs about some timeout.

Robin, I got the next answer from Bot Support:

Hi, inline queries require a fast answer, if the answer is delayed, you may get that error and the answer won’t be valid. I suggest you to answer faster to them in order to make them work.

May be need catch this exception and simply do nothing in catch body? Like here catch (TaskCanceledException) { } for example.

Hi I am getting the correct response after doing some POC. I am using java com.github.pengrad. below the code.

        GetUpdatesResponse updatesResponse = bot.execute(new GetUpdates());
        List<Update> updates = updatesResponse.updates();
        for(Update update:updates){
            InlineQuery inlineQuery = update.inlineQuery();
            System.out.println(update);
            System.out.println(inlineQuery);
            System.out.println("----------------");
            if(inlineQuery!=null) {
                InlineQueryResult r1 = new InlineQueryResultPhoto("AgADBQADrqcxG5q8tQ0EKSz5JaZjzDWgvzIABL0Neit4ar9MsXYBAAEC", "https://api.telegram.org/file/bot230014106:AAGtWr8xUCqUy8HjSgSFrY3aCs4IZs00Omg/photo/file_1.jpg", "https://api.telegram.org/file/bot230014106:AAGtWr8xUCqUy8HjSgSFrY3aCs4IZs00Omg/photo/file_1.jpg");
                BaseResponse baseResponse = bot.execute(new AnswerInlineQuery(inlineQuery.id(), r1)
                .cacheTime(6000)
                        .isPersonal(true)
                        .nextOffset("offset")
                        .switchPmParameter("pmParam")
                        .switchPmText("pmText"));
                System.out.println(baseResponse.isOk());
                System.out.println(baseResponse.toString());
                System.out.println(baseResponse.description());                
            }

        }

below the console output:

Update{update_id=465103212, message=null, edited_message=null, inline_query=InlineQuery{id='995145139265927135', from=User{id=231700283, first_name='Manabendra', last_name='Maji', username='null'}, location=null, query='hi', offset=''}, chosen_inline_result=null, callback_query=null}
InlineQuery{id='995145139265927135', from=User{id=231700283, first_name='Manabendra', last_name='Maji', username='null'}, location=null, query='hi', offset=''}
----------------
true
BaseResponse{ok=true, error_code=0, description='null'}
null

And I am getting proper response in my mobile telegram app also.

InlineQueryResultArticle requires the property InputMessageContent, that’s the Can't find field "message_text" error.

I receive [Error : 400 : Bad Request: QUERY_ID_INVALID] if I delay the response by 8-10 seconds. But can’t find anything in the docs about some timeout.