SHARE
TWEET

Telegram Bot

a guest Feb 17th, 2020 267 in 322 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'use strict'
  2.  
  3. const Task = use('Task')
  4. const TelegramBot = require('node-telegram-bot-api')
  5. const Env = use('Env')
  6. const token = Env.get('TELEGRAM_BOT_TOKEN')
  7. const bot = new TelegramBot(token)
  8. const moment = require('moment-timezone')
  9.  
  10. class StandUp extends Task {
  11.   static get schedule () {
  12.     const kyivNotificationHour = 9
  13.     const kyivHour = Number(moment().tz("Europe/Kiev").format('HH'))
  14.     const serverHour = Number(moment().format('HH'))
  15.     const diffHour = kyivHour - serverHour
  16.     const notificationHour = kyivNotificationHour - diffHour
  17.  
  18.     return `0 0 ${notification_hour} * * *`
  19.   }
  20.  
  21.   async handle () {
  22.     if(Env.get('NODE_ENV') === 'production') {
  23.       bot.sendMessage(Env.get('TELEGRAM_CHAT_ID'), 'Всім привіт.\n' + 'Що вчора (з)робили?\n' + 'Що сьогодні плануєте робити?');
  24.     }
  25.   }
  26. }
  27.  
  28. module.exports = StandUp
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top