node-telegram-bot-api icon indicating copy to clipboard operation
node-telegram-bot-api copied to clipboard

nothing append when using answerInlineQuery to send photo.

Open larfadin opened this issue 10 years ago • 5 comments

Here is my code, very basic:

bot.on('inline_query', function(query) {
  picturesToSend = [];
  // open the folder and get the number of pictures in
  var files = fs.readdirSync('./img/');
  var numberOfPics = files.length;

  // get 3 random pictures from my folder
  for (var i = 0; i < 3; i++) {
    // get a random picture name in my folder
    pictureName = files[Math.floor(Math.random() * numberOfPics)];
    // open this picture and add it to and array
    picturesToSend.push(fs.readFileSync('./img/' + pictureName));
  }
  // send the array containing 3 pictures
  bot.answerInlineQuery(query.id, picturesToSend);
});

When using answerInlineQuery nothing append and I got no error. Of course I have activate /setinlineBot with botfather

larfadin avatar Jan 09 '16 17:01 larfadin

Your code is wrong. Take a look on answerInlineQuery

yagop avatar Jan 09 '16 17:01 yagop

Yes I have seen it but I don't understand, I have set inline_query_id and results, cache_time, is_personal and next_offset are optional. Do I have to set them?

larfadin avatar Jan 09 '16 17:01 larfadin

bot.on('inline_query', function(query) {
  picturesToSend = [];
  // open the folder and get the number of pictures in
  var files = fs.readdirSync('./img/');
  var numberOfPics = files.length;

  // get 3 random pictures from my folder
  for (var i = 0; i < 3; i++) {
    // get a random picture name in my folder
    var pictureName = files[Math.floor(Math.random() * numberOfPics)];
    var pictureData = fs.readFileSync('./img/' + pictureName);
    picturesToSend.push({
      type: 'photo',
      id: i,
      photo_url: pictureData,
      thumb_url: pictureData
    });
  }
  // send the array containing 3 pictures
  bot.answerInlineQuery(query.id, picturesToSend);
});

I try this way, but nothing append

larfadin avatar Jan 09 '16 18:01 larfadin

photo_url is a simple web URL

yagop avatar Jan 09 '16 18:01 yagop

Thank you for your help. For now it's not possible to send local file.

larfadin avatar Jan 09 '16 22:01 larfadin