Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nothing append when using answerInlineQuery to send photo. #59

Closed
larfadin opened this issue Jan 9, 2016 · 5 comments
Closed

nothing append when using answerInlineQuery to send photo. #59

larfadin opened this issue Jan 9, 2016 · 5 comments

Comments

@larfadin
Copy link

larfadin commented Jan 9, 2016

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

@yagop
Copy link
Owner

yagop commented Jan 9, 2016

Your code is wrong.
Take a look on answerInlineQuery

@yagop yagop closed this as completed Jan 9, 2016
@larfadin
Copy link
Author

larfadin commented Jan 9, 2016

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
Copy link
Author

larfadin commented Jan 9, 2016

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

@yagop
Copy link
Owner

yagop commented Jan 9, 2016

photo_url is a simple web URL

@larfadin
Copy link
Author

larfadin commented Jan 9, 2016

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants