def run(
        self,
        user: User,
        text_preprocessing_result: BaseTextPreprocessingResult,
        params: Optional[Dict[str, Union[str, float, int]]] = None
    ) -> Optional[List[Command]]:
        self._nodes["consumer"] = {
            "projectId": user.settings["template_settings"]["project_id"]
        }

        settings_kafka_key = user.settings["template_settings"].get(
            "client_profile_kafka_key")
        self.request_data = {
            "topic_key":
            "client_info",
            "kafka_key":
            self.kafka_key or settings_kafka_key or self.DEFAULT_KAFKA_KEY,
            "kafka_replyTopic":
            user.settings["template_settings"]["consumer_topic"]
        }

        if self.behavior:
            scenario_id = user.last_scenarios.last_scenario_name
            user.behaviors.add(user.message.generate_new_callback_id(),
                               self.behavior,
                               scenario_id,
                               text_preprocessing_result.raw,
                               action_params=pickle_deepcopy(params))

        commands = super().run(user, text_preprocessing_result, params)
        return commands
Ejemplo n.º 2
0
 def run(self, user: User, text_preprocessing_result: BaseTextPreprocessingResult,
         params: Optional[Dict[str, Union[str, float, int]]] = None) -> None:
     scenario_id = None
     if self.check_scenario:
         scenario_id = user.last_scenarios.last_scenario_name
     user.behaviors.add(user.message.generate_new_callback_id(), self.behavior, scenario_id,
                        text_preprocessing_result.raw, action_params=pickle_deepcopy(params))
 def masked_value(self):
     data = pickle_deepcopy(self.as_dict)
     masking(data, self.masking_fields)
     if self.command.loader == "json.dumps":
         return json.dumps(data, ensure_ascii=False)
     elif self.command.loader == "protobuf":
         protobuf_message = self.as_protobuf_message(data)
         return protobuf_message.SerializeToString()
Ejemplo n.º 4
0
 def make_message(cls,
                  user=None,
                  params=None,
                  cls_name='',
                  log_store_for=0):
     params = params or {}
     if user:
         cls.update_user_params(user, params)
     params = pickle_deepcopy(params)
     masking(params)
     cls.update_other_params(user, params, cls_name, log_store_for)
     return params
Ejemplo n.º 5
0
 def extract(self,
             text_preprocessing_result: BaseTextPreprocessingResult,
             user: User,
             params: Dict[str, Any] = None) -> Optional[str]:
     original_text = text_preprocessing_result.original_text
     if self.operations:
         for op in self.operations:
             original_text = self._operation(original_text, op["type"],
                                             op.get("amount"))
     text_preprocessing_result_copy = pickle_deepcopy(
         text_preprocessing_result)
     text_preprocessing_result_copy.original_text = original_text
     return super(RegexpAndStringOperationsFieldFiller,
                  self).extract(text_preprocessing_result_copy, user,
                                params)
Ejemplo n.º 6
0
    def run(self, payload, user):
        action_params = pickle_deepcopy(self.get_action_params(payload))
        params = {
            log_const.KEY_NAME: "handling_server_action",
            "server_action_params": str(action_params),
            "server_action_id": self.get_action_name(payload, user)
        }
        log("HandlerServerAction %(server_action_id)s started", user, params)

        app_info = user.message.app_info
        smart_kit_metrics.counter_incoming(self.app_name,
                                           user.message.message_name,
                                           self.__class__.__name__,
                                           user,
                                           app_info=app_info)

        action_id = self.get_action_name(payload, user)
        action = user.descriptions["external_actions"][action_id]
        return action.run(user, TextPreprocessingResult({}), action_params)
Ejemplo n.º 7
0
    def add(self,
            callback_id: str,
            behavior_id,
            scenario_id=None,
            text_preprocessing_result_raw=None,
            action_params=None):
        host = socket.gethostname()
        text_preprocessing_result_raw = text_preprocessing_result_raw or {}
        # behavior will be removed after timeout + EXPIRATION_DELAY
        expiration_time = (int(time()) +
                           self.descriptions[behavior_id].timeout(self._user) +
                           self.EXPIRATION_DELAY)
        action_params = action_params or dict()
        action_params[LOCAL_VARS] = pickle_deepcopy(
            self._user.local_vars.values)

        callback = self.Callback(
            behavior_id=behavior_id,
            expire_time=expiration_time,
            scenario_id=scenario_id,
            text_preprocessing_result=text_preprocessing_result_raw,
            action_params=action_params,
            hostname=host)
        self._callbacks[callback_id] = callback
        log(
            f"behavior.add: adding behavior %({log_const.BEHAVIOR_ID_VALUE})s with scenario_id"
            f" %({log_const.CHOSEN_SCENARIO_VALUE})s for callback %({log_const.BEHAVIOR_CALLBACK_ID_VALUE})s"
            f" expiration_time: %(expiration_time)s.",
            user=self._user,
            params={
                log_const.KEY_NAME: log_const.BEHAVIOR_ADD_VALUE,
                log_const.BEHAVIOR_CALLBACK_ID_VALUE: callback_id,
                log_const.BEHAVIOR_ID_VALUE: behavior_id,
                log_const.CHOSEN_SCENARIO_VALUE: scenario_id,
                "expiration_time": expiration_time
            })

        behavior_description = self.descriptions[behavior_id]
        expire_time_us = behavior_description.get_expire_time_from_now(
            self._user)
        self._add_behavior_timeout(expire_time_us, callback_id)
Ejemplo n.º 8
0
 def masked_value(self):
     data = pickle_deepcopy(self.as_dict)
     masking(data, self.masking_fields)
     return json.dumps(data, ensure_ascii=False)