簡體   English   中英

電報bot api - answerInlineQuery中的QUERY_ID_INVALID - Javascript

[英]Telegram bot api - QUERY_ID_INVALID in answerInlineQuery - Javascript

我正在嘗試使用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]"}

我剛看到這個問題: 電報機器人api python錯誤,但我不知道json.dumps如何在python中工作。 我需要知道我需要發送給API的正確“params”格式。

你應該在內聯鍵盤推送后發送通知最長15秒

我有兩個問題,沒有字符串“結果”和stringfy“params”這是錯誤的。

我只是需要stringfy“結果”而不是stringfy“params”

在做了一些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 ##

而且我的移動電報應用程序也得到了適當的響應。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM