Cizaquita
Cizaquita

Reputation: 167

Telegram bot api - QUERY_ID_INVALID in answerInlineQuery - Javascript

I'm trying to use answerInlineQuery method but i have an error:

function(inlineQuery) {
        var url = API_URL + '/answerInlineQuery',
            params = {};    
        var inline_query_id = inlineQuery.id;
        var results = [{
                                "type":"location",
                                "id":"1",
                                "latitude":4.710989,
                                "longitude":-74.072092,
                                "title":"Bogotá"
                              }];

        params.inline_query_id = inline_query_id;
        params.results = results;

        request('post', url, JSON.stringify(params), function(data) {
            if(data && data.ok){
                console.log('answerInlineQuery enviado');
            }else{
                console.log('Error enviando answerInlineQuery: ' + JSON.stringify(data));
            }
        });
    };

The parameters that i'm sending are (formated with JSON.stringify):

{
  "inline_query_id": "32021086267134929",
  "results": [
    {
      "type": "location",
      "id": "1",
      "latitude": 4.710989,
      "longitude": -74.072092,
      "title": "Bogotá"
    }
  ]
}

I'm using Javascript with a POST request function to the Telegram Bot API and the error that i have is this:

Error enviando answerInlineQuery: {"ok":false,"error_code":400,"description":"[Error : 400 : Bad Request: QUERY_ID_INVALID]"}

I just saw this question: telegram bot api python error but i don't know how json.dumps works in python. I need to know the correct "params" format that i need to send to the API.

Upvotes: 3

Views: 4544

Answers (3)

Manab
Manab

Reputation: 1

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 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='Test', last_name='test', username='null'}, location=null, query='hi', offset=''}, chosen_inline_result=null, callback_query=null}

InlineQuery{id='995145139265927135', from=User{id=231700283, first_name='test', last_name='test', username='null'}, location=null, query='hi', offset=''}

true
BaseResponse{ok=true, error_code=0, description='null'}
null## Heading ##

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

Upvotes: 0

amir
amir

Reputation: 39

you should send notify max 15 sec after inline keyboard pushed

Upvotes: 3

Cizaquita
Cizaquita

Reputation: 167

I had 2 problems, no stringfy the "results" and stringfy the "params" that was wrong.

I just needed stringfy the "results" and not stringfy the "params"

Upvotes: 2

Related Questions