Пример #1
0
 def render(self, seed=None, additional_suggests=None):
     if seed is not None:
         random.seed(seed)
     text = random.choice(self.texts)
     resp = Response(text, suggests=self.suggests)
     resp.set_text(text)
     if self.exit:
         resp.commands.append(names.COMMANDS.EXIT)
     if additional_suggests:
         resp.suggests.extend(additional_suggests)
     return resp
Пример #2
0
 def postprocess_response(self, response: Response, turn: DialogTurn):
     response.updated_user_object['prev'] = {
         'text': response.text,
         'voice': response.voice,
         'suggests': response.suggests,
         'stage': turn.next_stage
     }
Пример #3
0
    def handle_completed_form(self, form, user_object, ctx: Context):
        document = copy.deepcopy(form)
        document['user_id'] = ctx.user_id
        document['timestamp'] = datetime.now()

        if self.forms_collection:
            self.forms_collection.insert_one(document)
        return Response(
            text=self.config.finish_message,
            user_object=user_object,
            suggests=self.config.finish_suggests or [],
        )
Пример #4
0
 def make_response(self) -> Optional[Response]:
     if self.response:
         return self.response
     if self.response_text:
         r = Response(
             text=None,
             user_object=self.user_object,
             rich_text=self.response_text,
             suggests=self.suggests,
             commands=self.commands,
             image_url=self.image_url,
             show_item_meta=self.show_item_meta,
             extra_directives=self.extra_directives,
             should_listen=self.should_listen,
         )
         if isinstance(self.card, BigImage):
             r.image = self.card
         elif isinstance(self.card, (VisualGallery, ImageGallery)):
             r.gallery = self.card
         if self.image_id:
             r.image_id = self.image_id
         return r
Пример #5
0
def test_keyboard_squeeze():
    resp = Response(text='не важно',
                    suggests=[
                        'удалить направление', 'Агропромышленный комплекс',
                        'Вооружение и военная техника', 'Естественные науки',
                        'Инженерные науки и технологии',
                        'Искусство и гуманитарные науки', 'Компьютерные науки',
                        'Медицина и здравоохранение', 'Педагогические науки',
                        'Социально-экономические науки', 'вакансии',
                        'мой регион', 'мои направления', 'главное меню'
                    ])
    adapter = VkAdapter(suggest_cols='auto')
    result = adapter.make_response(resp)
    keyboard = result['keyboard']['buttons']
    assert len(keyboard) == 10
    assert sum(len(row) for row in keyboard) == len(resp.suggests)
    assert max(len(row) for row in keyboard) <= 5
Пример #6
0
 def postprocess_response(self, response: Response, turn: PTurn):
     response.no_response = turn.no_response
Пример #7
0
 def postprocess_response(self, response: Response, turn: PTurn):
     response.no_response = turn.no_response
     response.updated_user_object['last_time'] = str(datetime.now())