telebot icon indicating copy to clipboard operation
telebot copied to clipboard

Cron or timer event and autopost

Open CarlosLopezES opened this issue 7 years ago • 5 comments

Hi,

Is possible to make a function that executes at some hours (for ejemple, 17:00:00) to some group? Without previous event, like chat or something.

Thank you!

CarlosLopezES avatar Mar 21 '18 13:03 CarlosLopezES

Well, maybe it's useful for anyone, i have made it with node schedule

var schedule = require('/***/node_modules/node-schedule/lib/schedule.js');
var j = schedule.scheduleJob('10 * * * *', function(){
var data;
var data2;
var rawData;

rawData = fs.readFileSync('/home/***.txt', 'utf8');
  if(rawData==null) {
    return console.log(err);
  }
  data = rawData.split('\n');
function randomInt (low, high) {
    return Math.floor(Math.random() * (high - low) + low);
}
data2 = data[randomInt(0,data.length -1)];
bot.sendMessage('-XXXXX (group id)', 'Text: '+ data2);
});

CarlosLopezES avatar Mar 22 '18 08:03 CarlosLopezES

Great idea for a new plugin (:

mullwar avatar Apr 09 '18 08:04 mullwar

@CarlosLopezES did you had any issues with Telegram limitations on sending messagess ?

eko24ive avatar May 15 '18 04:05 eko24ive

Not at all, but our bot send maybe less tan 100 messages by day

CarlosLopezES avatar May 15 '18 07:05 CarlosLopezES

Got it - thanks!

eko24ive avatar May 15 '18 14:05 eko24ive