Cizaquita Cizaquita - 1 month ago 36
Javascript Question

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.

Answer

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"