private IConversationMemory loadAndValidateConversationMemory(String botId, String conversationId) throws ResourceStoreException, ResourceNotFoundException, IllegalAccessException { var conversationMemory = loadConversationMemory(conversationId); checkConversationMemoryNotNull(conversationMemory, conversationId); if (!botId.equals(conversationMemory.getBotId())) { throw new IllegalAccessException("Supplied botId is incompatible to conversationId"); } return conversationMemory; }
final IConversationMemory conversationMemory = loadConversationMemory(conversationId); checkConversationMemoryNotNull(conversationMemory, conversationId); if (!botId.equals(conversationMemory.getBotId())) { String message = "Supplied botId (%s) is incompatible with conversationId (%s)"; message = String.format(message, botId, conversationId); IBot bot = botFactory.getBot(environment, conversationMemory.getBotId(), conversationMemory.getBotVersion()); if (bot == null) { String msg = "Bot not deployed (environment=%s, conversationId=%s, version=%s)"; msg = String.format(msg, environment, conversationMemory.getBotId(), conversationMemory.getBotVersion()); response.resume(new NotFoundException(msg)); return;
public static ConversationMemorySnapshot convertConversationMemory(IConversationMemory conversationMemory) { ConversationMemorySnapshot snapshot = new ConversationMemorySnapshot(); if (conversationMemory.getUserId() != null) { snapshot.setUserId(conversationMemory.getUserId()); } if (conversationMemory.getConversationId() != null) { snapshot.setConversationId(conversationMemory.getConversationId()); } snapshot.setBotId(conversationMemory.getBotId()); snapshot.setBotVersion(conversationMemory.getBotVersion()); snapshot.setConversationState(conversationMemory.getConversationState()); for (IConversationMemory.IConversationStep redoStep : conversationMemory.getRedoCache()) { ConversationMemorySnapshot.ConversationStepSnapshot redoStepSnapshot = iterateConversationStep(redoStep); snapshot.getRedoCache().push(redoStepSnapshot); } for (int i = conversationMemory.getAllSteps().size() - 1; i >= 0; i--) { IConversationMemory.IConversationStep conversationStep = conversationMemory.getAllSteps().get(i); snapshot.getConversationSteps().add(iterateConversationStep(conversationStep)); } snapshot.getConversationOutputs().addAll(conversationMemory.getConversationOutputs()); snapshot.getConversationProperties().putAll(conversationMemory.getConversationProperties()); return snapshot; }