Пример #1
0
    def _process_update(self, bot: BotAPIClient, update: Update) -> None:
        print()  # newline on incoming request makes the logs more readable

        context = self.context_manager.add_incoming_update(update)

        try:
            try:
                next_response = self.planning_agent.build_next_actions(context)
            except ForceReevaluation:
                # Some handlers require to reevaluate the template parameters (only once)
                next_response = self.planning_agent.build_next_actions(context)
            if next_response is None:
                return
            actions = next_response.collect_actions()
        finally:
            context.dialog_states.update_step()

        if self.recorder:
            self.recorder.record_dialog(update, actions, context.dialog_states)

        if settings.NO_DELAYS:
            # No message delays while debugging
            for a in actions:
                a.delay = None

        try:
            bot.perform_actions(actions)
        except Exception as e:
            log.error("Error while performing chat action:")
            log.exception(e)

        context.add_actions(actions)
        update.save()