InlineQueryResultArticle of answerInlineQuery in Telegram Bot API with Google Apps Script

InlineQueryResultArticle of answerInlineQuery in Telegram Bot API with Google Apps Script

我正在使用 google Telegram Bot 的应用程序脚本 API 并且我遇到了问题 InlineQueryResultArticleanswerInlineQuery 方法中。

function answerInlineQuery(iqid, result){
  var data = {
        method: "post",
        payload: {
          method: "answerInlineQuery",
          inline_query_id: iqid,
          results:JSON.stringify(result)
        }
}
}

结果格式如下:-

    var result= {
        InlineQueryResultArticle:[
          {type:'article',id: iqid, title:"RESULT 1", input_message_content:"TEXT 1"},
         {type:'article',id: iqid, title:"RESULT 2", input_message_content:"TEXT 2"}           
        ]
   }; 
answerInlineQuery(iqid, result);

我在@BotFather 中打开了内联模式。我的机器人也在接收内联查询,对于每个请求,我都可以正确地看到我的内联查询 ID,而且我还可以看到作为 [object Object] 接收的结果。 但是,问题是我没有得到任何结果。

REF:在 answerinlinequery, the results should be a JSON-serialized array of results for the inline query using any of these results.

谁能指出我哪里错了

InlineQueryResultArticleid 字段对于每个结果必须是唯一的。但是,您将两个结果的 id 设置为 iqid

您应该用自定义 ID 替换它们。

 var result= {
    InlineQueryResultArticle:[
       {type:'article',id: "1", title:"RESULT 1", input_message_content:"TEXT 1"},
       {type:'article',id: "2", title:"RESULT 2", input_message_content:"TEXT 2"}           
    ]
}; 

经过多次尝试我找到了解决方案:

这里有一个包含三个结果的内联答案

****小心:使用来自您的机器人的示例 file_id 更改 document_file_id 的值,否则您会看到错误

//your bot token placed here
const token = "";
tgmsg('answerInlineQuery', {

    "inline_query_id": update['inline_query']['id'],
    "results": JSON.stringify([
        //inline result of an article with thumbnail photo
        {
            "type": "article",
            "id": "1",
            "title": "chek inline keybord ",
            "description": "test ",
            "caption": "caption",
            "input_message_content": {
                "message_text": "you can share inline keyboard to other chat"
            },

            "thumb_url": "https://avatars2.githubusercontent.com/u/10547598?v=3&s=88"
        },
        //inline result of an article with inline keyboard
        {
            id: "nchfjdfgd",
            title: 'title',
            description: "description",
            type: 'article',
            input_message_content: {
                message_text: "inline is enabled input_message_content: {message_text: message_text}message_text"
            },
            reply_markup: {
                "inline_keyboard": [
                    [{
                        "text": "InlineFeatures.",
                        "callback_data": "inline_plugs_1118095942"
                    }],
                    [{
                        "text": "OtherFeatures.",
                        "callback_data": "other_plugs_1118095942"
                    }]
                ]
            }
        },

        //inline result of a cached telegram document with inline keyboard
        {
            id: "nchgffjdfgd",
            title: 'title',
            description: "description",
            //change this on with the value of file_id from telegram bot api 
            document_file_id: "BQACAgQAAxkBAAIBX2CPrD3yFC0X1sI0HFTxgul0GdqhAALjDwACR4pxUKIV48XlktQNHwQ",
            type: 'document',
            caption: "caption ghh hhdd",
            reply_markup: {
                "inline_keyboard": [
                    [{
                        "text": "InlineFeatures.",
                        "callback_data": "inline_plugs_1118095942"
                    }],
                    [{
                        "text": "OtherFeatures.",
                        "callback_data": "other_plugs_1118095942"
                    }]
                ]
            }

        }
    ])
})

function tgmsg(method, data) {
    var options = {
        'method': 'post',
        'contentType': 'application/json',
        'payload': JSON.stringify(data)
    };
    var responselk = UrlFetchApp.fetch('https://api.telegram.org/bot' + token + '/' + method, options);
}