37 lines
998 B
Python
37 lines
998 B
Python
from functools import cached_property
|
|
|
|
|
|
class Processor:
|
|
def __init__(self, data: dict):
|
|
self.data = data
|
|
self.user_id = data['session']['user']['user_id']
|
|
self.message = data['request']['original_utterance']
|
|
|
|
def next(self):
|
|
...
|
|
|
|
def save(self):
|
|
...
|
|
|
|
def finish(self):
|
|
return {
|
|
"text": "Пока-пока, заходи еще",
|
|
"end_session": True
|
|
}
|
|
|
|
@cached_property
|
|
def handlers(self) -> dict:
|
|
return {
|
|
"следующий": self.next,
|
|
"сохрани": self.save,
|
|
"закончить": self.finish
|
|
}
|
|
|
|
def process(self) -> dict:
|
|
action = self.handlers.get(self.message)
|
|
if action is None:
|
|
return {
|
|
"text": f"Я не понимаю этой команды. Я могу выполнить только действия: {', '.join(self.handlers.keys())}"
|
|
}
|
|
return action()
|