【问题标题】:Telegram bot api - QUERY_ID_INVALID in answerInlineQuery - JavascriptTelegram bot api - answerInlineQuery 中的 QUERY_ID_INVALID - Javascript
【发布时间】:2016-10-21 17:00:08
【问题描述】:

我正在尝试使用answerInlineQuery 方法,但出现错误:

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

我发送的参数是(格式为JSON.stringify):

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

我正在使用带有POST 请求函数的 JavaScript 到 Telegram Bot API,我遇到的错误是:

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

我刚看到这个问题:telegram bot api python error 但我不知道 json.dumps 在 python 中是如何工作的。我需要知道我需要发送到 API 的正确“参数”格式。

【问题讨论】:

  • 您发送答案的速度够快吗?如果该查询是很久以前发送的,Telegram 也会出现此错误。

标签: javascript json telegram-bot


【解决方案1】:

您应该在按下内联键盘后最多 15 秒发送通知

【讨论】:

  • 你能在你的答案中添加一些代码来展示如何做到这一点吗?
【解决方案2】:

我有 2 个问题,没有 stringfy 的“结果”和 stringfy 错误的“params”。

我只需要对“结果”进行字符串化,而不是对“参数”进行字符串化

【讨论】:

  • 当我对结果进行编码时,我得到Bad Request: can't parse JSON encoded inline query results: Unexpected symbol 当我不对结果进行编码时,电报说没问题,但电报客户端中没有出现消息
【解决方案3】:

我在做一些 POC 后得到了正确的响应。我正在使用 Java com.github.pengrad。

代码下方:

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

}

    }

在控制台输出下方:

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 ##

而且我的移动电报应用程序也得到了适当的响应。

【讨论】:

    猜你喜欢
    • 2017-05-13
    • 1970-01-01
    • 2018-06-13
    • 2018-04-07
    • 2021-11-26
    • 2016-03-14
    • 2017-02-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多