import datetime import os from random import randrange, choice import base import queues from telebot.types import Message import json from sprint_platform import PlatformClient security_token = os.getenv("PLATFORM_SECURITY_TOKEN") stage = os.getenv("STAGE", 'local') client = PlatformClient( security_token, 'law-exam-bot', stage, ['constants', 'answers', 'replies'], [], need_poll=True, ) store = {} class Daemon(base.Daemon, queues.TasksHandlerMixin): @property def queue_name(self): return 'law_exam_bot_worker' def execute(self): self.poll() def send(self, text: str, chat_id: int): queues.set_task( 'botalka_mailbox', { 'project': 'law-exam-bot', 'name': 'telegram-bot', 'body': { 'text': text, 'chat_id': chat_id, } }, 1, ) def process(self, payload): global store message: Message = Message.de_json(json.dumps(payload)) questions = client.get_config('questions') current_question = store.get(message.chat.id) if current_question is not None: self.send("Вот ответ на вопрос", message.chat.id) text = questions[current_question]['answer'] text_split = [text[i:i+4000] for i in range(0, len(text), 4000)] for elem in text_split: self.send(elem, message.chat.id) selected = randrange(len(questions)) store[message.chat.id] = selected self.send("Следующий вопрос: " + questions[selected]['question'], message.chat.id) Daemon().execute()