node-telegram-bot-api
node-telegram-bot-api copied to clipboard
nothing append when using answerInlineQuery to send photo.
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
Your code is wrong. Take a look on answerInlineQuery
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?
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
photo_url is a simple web URL
Thank you for your help. For now it's not possible to send local file.