private void addActionsToConversationMemory(IConversationMemory memory, List<BehaviorRule> successRules) { List<String> allCurrentActions = new LinkedList<>(); successRules.forEach(successRule -> successRule.getActions().stream(). filter(action -> !allCurrentActions.contains(action)).forEach(allCurrentActions::add)); var currentStep = memory.getCurrentStep(); List<String> actions = new LinkedList<>(); if (appendActions || allCurrentActions.isEmpty()) { IData<List<String>> latestActions = currentStep.getLatestData(KEY_ACTIONS); if (latestActions != null && latestActions.getResult() != null) { actions.addAll(latestActions.getResult()); } } actions.addAll(allCurrentActions.stream(). filter(action -> !actions.contains(action)).collect(Collectors.toList())); Data actionsData = new Data<>(KEY_ACTIONS, actions); actionsData.setPublic(true); currentStep.storeData(actionsData); currentStep.resetConversationOutput(KEY_ACTIONS); currentStep.addConversationOutputList(KEY_ACTIONS, actions); }
@Override public void executeTask(IConversationMemory memory) { IWritableConversationStep currentStep = memory.getCurrentStep(); List<IData<Object>> outputDataList = currentStep.getAllData(KEY_OUTPUT); List<IData<List<QuickReply>>> quickReplyDataList = currentStep.getAllData(KEY_QUICK_REPLIES); final Map<String, Object> contextMap = memoryItemConverter.convert(memory); if (!outputDataList.isEmpty()) { currentStep.resetConversationOutput(KEY_OUTPUT); } templateOutputTexts(memory, outputDataList, contextMap); if (!quickReplyDataList.isEmpty()) { currentStep.resetConversationOutput(KEY_QUICK_REPLIES); } templatingQuickReplies(memory, quickReplyDataList, contextMap); }