Esempio n. 1
0
    def __get_next_node_id(cls, data, state, node_data):

        next_node_id = node_data.get('NextNodeId', '')  # Fallback node id

        for button in node_data.get('Buttons', []):
            try:
                root_key = re.split(r'\.|\[',
                                    button.get("ConditionMatchKey"))[0]

                if data.get(root_key) is None:
                    data[root_key] = None

                logger.debug("rootKey " + root_key)

                path = button.get("ConditionMatchKey")
                obj = {root_key: data[root_key]}
                variable_value = Util.deep_find(obj, path)

                match_operator = button.get("ConditionOperator")
                match_value = AnaHelper.verb_replacer(text=button.get(
                    "ConditionMatchValue", ""),
                                                      state=state)

                condition_matched = AnaHelper.is_condition_match(
                    variable_value, match_operator, match_value)

                if condition_matched:
                    next_node_id = button["NextNodeId"]
                    break
            except:
                logger.error("error in btn " + str(button))
                pass

        return next_node_id
Esempio n. 2
0
    def get_next_node(self, node_data):

        next_node_id = node_data.get('NextNodeId', '')  #Fallback node id
        variable_data = self.state.get("var_data", {})
        buttons = node_data.get("Buttons")

        for button in buttons:

            root_key = re.split(r'\.|\[', button.get("ConditionMatchKey"))[0]
            logger.debug(
                f"Variable Data received for condition call is {variable_data}"
            )

            # if isinstance(variable_data, str):
            # try:
            # variable_data = json.loads(variable_data)
            # except Exception as err:
            # logger.error(f"Error parsing variable_data {variable_data}")
            # variable_data = {}

            logger.debug(
                f"Variable Data after dict conversion is {variable_data}")
            if variable_data.get(root_key) is None:
                continue

            path = button.get("ConditionMatchKey")
            obj = {root_key: variable_data[root_key]}
            variable_value = Util.deep_find(obj, path)

            match_operator = button.get("ConditionOperator")
            match_value = AnaHelper.verb_replacer(text=button.get(
                "ConditionMatchValue", ""),
                                                  state=self.state)

            logger.debug(
                f"variable_value {variable_value} {variable_value.__class__} match_operator {match_operator} match_value {match_value}"
            )

            condition_matched = AnaHelper.is_condition_match(
                variable_value, match_operator, match_value)
            logger.debug(f"Condition matched is {condition_matched}")
            if condition_matched:
                variable_data = self.state.get("var_data", {})
                node_variable_name = node_data.get("VariableName")
                if node_variable_name:
                    button_variable_value = button.get("VariableValue")
                    button_variable_value = AnaHelper.verb_replacer(
                        text=button_variable_value, state=self.state)
                    variable_data[node_variable_name] = button_variable_value
                next_node_id = button["NextNodeId"]
                break

        next_node_key = self.state.get("flow_id", "") + "." + next_node_id
        node_data = AnaNode(next_node_key).get_contents()
        return {"id": next_node_key, "data": node_data}