【问题标题】:InlineQueryResultArticle of answerInlineQuery in Telegram Bot API with Google Apps ScriptInlineQueryResultArticle of answerInlineQuery in Telegram Bot API with Google Apps Script
【发布时间】:2018-07-06 03:01:31
【问题描述】:

我正在为 Telegram Bot API 使用谷歌应用脚​​本,我在 answerInlineQuery 方法中遇到了问题 InlineQueryResultArticle

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 中,结果应该是使用these results 中的任何一个的内联查询的JSON 序列化结果数组。

谁能指出我哪里出错了

【问题讨论】:

  • 您如何检查结果?通过Logger.log,不记录复杂对象?或者通过 Stackdriver Logging,您可以在其中与复杂对象进行交互? console.log({message: "the result object", response: result});
  • 我正在使用错误处理机制,try & catch 和 bot API 中的sendMessage 来检查结果。

标签: google-apps-script telegram telegram-bot


【解决方案1】:

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"}           
    ]
}; 

【讨论】:

    【解决方案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);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-13
      • 1970-01-01
      • 1970-01-01
      • 2018-06-13
      • 1970-01-01
      • 1970-01-01
      • 2021-12-27
      • 2021-03-31
      相关资源
      最近更新 更多