var telegram = require('telegram-bot-api');
var find = require('find');
var imageList = []
find.file(/\.(jpe?g|png|gif)$
/i, process.cwd(), function(files) {
console.log(files.length);
imageList = files.filter((name)=>{
return !name.match('/node_modules/');
});
})
var api = new telegram({
token: 'TOKEN',
updates: {
enabled: true
}
});
api.on('message', function(message)
{
console.log(message)
if (message.from.username === 'SooXiaoTong') return;
if (!message.text) return;
if (!message.text.match(/^\
/plz_give_me_some_image(@|$)/)) return;
if (imageList.length === 0) return;
var fileIndex = (imageList.length * Math.random()) | 0
var chosonPath = imageList[fileIndex];
console.log('start uploading ' + fileIndex + ' ' + chosonPath)
api.sendPhoto({
chat_id:
message.chat.id,
caption: 'Random file ' + fileIndex,
// you can also send file_id here as string (as described in telegram bot api documentation)
photo: chosonPath
})
});