Telegram(最简单的)内联机器人在 iOS 上发送照片 2 次

Telegram (simplest) inline bot send photo 2 times on iOS

我有一个类似于@pic 的内联机器人,它工作正常,当我输入查询词时,我可以看到图片出现,所以我可以选择一个并发送到聊天室。问题是当我这样做时 - 发送了 2 个相同结果的副本。这仅发生在 iOS 客户端上。在Android,PC等平台只发送一张图片。我已经检查了所有日志(机器人在 Node.js 中完成)并且对于每个请求我都有一个响应。这似乎是一个 iOS 客户端错误,尽管 @pic bot 工作正常。是否有人遇到过此错误或知道可能导致此错误的原因?

answerInlineQuery 响应对象示例

{
"inline_query_id": "817150058382989968",
"results": [
    {
        "type": "photo",
        "id": "se090",
        "photo_url": "http://www.shadowera.com/secardbot361/se090.jpg",
        "thumb_url": "http://www.shadowera.com/secardbot361/se090.jpg",
        "photo_width": 344,
        "photo_height": 480,
        "title": "Tracking Gear",
        "description": "You can view the hands of opposing players.",
        "caption": "king"
    },
    {...

更新: 所以我在 node.js @iosinlinebot 中创建了一个最简单的内联机器人(你可以试试)并且你有完全相同的行为:只有在 iOS 设备上,你会在点击后向聊天发送 2 张图像结果。 这是代码:

exports.handler = function(event, context) {
        console.log(event);
        const https = require("https");
        let answer = {
            inline_query_id: event.inline_query.id,
            results: [{
                    type: "photo",
                    id: "abcd",
                    photo_url: "https://lh3.googleusercontent.com/jVXglyWWL5J2y1vRN-7Jy3_ozvvZc4w5486IAkbAIrWcNN_vn7YuIvhc1JDtGq43BqGl=s180",
                    thumb_url: "https://lh3.googleusercontent.com/jVXglyWWL5J2y1vRN-7Jy3_ozvvZc4w5486IAkbAIrWcNN_vn7YuIvhc1JDtGq43BqGl=s180",
                    photo_width: 180,
                    photo_height: 180,
                    title: "title",
                    description: "description",
                    caption: "test"
                }],
            cache_time:1 
        };
        let postBody = JSON.stringify(answer);
        let options = {
            hostname: "api.telegram.org",
            port: 443,
            path: "/bot" + process.env.TOKEN + "/answerInlineQuery",
            method: "POST",
            headers: {
                'Content-Type': 'application/json',
                'Content-Length': postBody.length
            }
        };

        let postreq = https.request(options, (res) => {
            res.setEncoding('utf8');
            const body = [];
            res.on('data', (chunk) => body.push(chunk));

            res.on('end', () => {
                let j = body.join('');
                console.log(j);
                //context.done(JSON.parse(j));
            });
        });
        postreq.write(postBody);
        postreq.end();
};

这是一个事件对象(来自电报):

{
  "update_id": 12345678,
  "inline_query": {
    "id": "123456789123456789",
    "from": {
      "id": 123456789,
      "is_bot": false,
      "first_name": "Firstname",
      "username": "username",
      "language_code": "it-IT"
    },
    "query": "test",
    "offset": ""
  }
}

更新: 多亏了 Sedric Heidarizarei,我们才能够找到问题所在。这是一个电报 iOS 客户端错误。如果 InlineQueryResultPhoto 对象包含 caption 字段,您的用户将 post 2 张图片添加到聊天中。

^$ 关闭正则表达式的开始和结束非常重要。
例如,具有此正则表达式 /^[/]start/ 的用户可以使用 startstart a 以及 start b 作为 Bot 命令并允许他们接收您的照片,但使用 /^[/]start$/ , 用户必须输入准确的 /start 命令。

1:使用此模块:node-telegram-bot-api
2:并发送您的照片:

bot.onText(/^[/]start$/, (msg) => {
  const opts = {
    parse_mode: 'Markdown',
    reply_markup: {
        inline_keyboard: [[{
                text: '',
                callback_data: 'back'
                }]]
        }
  };
  bot.sendPhoto(msg.chat.id, 'AgADBAADn64xBoABCx8L8trMV9eMqgDAAEC', opts); // Your Photo id
}); 

通知:
打开一个空项目,然后使用并检查你的 InlineQueryResultPhoto.

更新:
这是一个 Telegram 错误,供临时使用,从您的 let answer ={}

中删除 caption