def send_otp(employee): otp = OTP.generate(employee.phone.as_e164) try: updater = bot_init(settings.BOT_TOKEN) updater.send_otp(otp, employee.chat_id) except Exception as e: return False return True
def save(self, *args, **kwargs): init_id = self.id super(News, self).save(*args, **kwargs) if not self.employees_notified: employees = self.employees_to_notify.all() if self.all_employees: employees = Employee.objects.all() if employees.exists(): updater = bot_init(settings.BOT_TOKEN) updater.news_notify(self, employees) self.employees_notified = True self.save()
def handle(self, *args, **options): updater = bot_init(settings.BOT_TOKEN) self.updater = updater current = timezone.localtime() current_date = timezone.localdate() employees = Employee.objects.all() for employee in employees: activity, _ = EmployeeActivity.objects.get_or_create( employee=employee, date=current_date) if time(8, 0) <= current.time() < time(19, 0): self.start_notify(employee, activity) elif time(19,0) <= current.time(): self.finish_notify(employee, activity)
def post(self, request, *args, **kwargs): token = kwargs.get("token") updater = bot_init(token) update = Update.de_json(request.data, updater.bot) updater.dispatcher.process_update(update) return Response(status=status.HTTP_200_OK)
def handle(self, *args, **options): updater = bot_init(settings.BOT_TOKEN) updater.start_polling() updater.idle()
def notify_employee(self): updater = bot_init(settings.BOT_TOKEN) updater.task_notify(self.task, [self.employee]) self.notified = True self.save()