const bot = new Telegraf('522578718:AAGc4Ydk1P2lQy-_EG_KSpY3sy4wrro2Zms', { telegram: { // Telegram options agent: null, // https.Agent instance, allows custom proxy, certificate, keep alive, etc. webhookReply: true // Reply via webhook } }); bot.start((ctx) => { console.log('bot start'); ctx.reply('Welcome!'); chatId = ctx.message.chat.id; }); bot.catch((err) => { console.log('Ooops', err) }) function newDiff(diff) { if (!chatId) { console.log('Need open chat!!!'); return; } diff.forEach(line => { bot.telegram.sendMessage(chatId, line) .then(r => console.log(`promise => ${r}`)) .catch(err => console.log(`send msg error ${err}`)); }) } bot.startPolling()
throw 'invalid data'; } } catch (err) { ctx.reply(config.get('bot.messages.invalidPeriod')); return; } logger.info('period update %d', period); config.set('period', period * 1000); periodicalRunner(config.get('period')); ctx.reply(config.get('bot.messages.updatePeriod')); }); bot.command('/ping', (ctx) => { ctx.reply('pong'); }); // error handling bot.catch((err) => { logger.error('bot:', err); bot.sendError(err); }); // bot.use((ctx, next) => { // const start = new Date() // return next().then(() => { // const ms = new Date() - start // console.log('response time %sms', ms) // }) // }) module.exports = bot;