diff --git a/bot/admin/server/src/main/kotlin/BotAdminService.kt b/bot/admin/server/src/main/kotlin/BotAdminService.kt index 79b5bc6eaf..793132ff83 100644 --- a/bot/admin/server/src/main/kotlin/BotAdminService.kt +++ b/bot/admin/server/src/main/kotlin/BotAdminService.kt @@ -56,6 +56,7 @@ import ai.tock.bot.admin.story.dump.StoryDefinitionConfigurationDump import ai.tock.bot.admin.story.dump.StoryDefinitionConfigurationDumpController import ai.tock.bot.admin.story.dump.StoryDefinitionConfigurationFeatureDump import ai.tock.bot.admin.user.UserReportDAO +import ai.tock.bot.definition.Intent import ai.tock.bot.engine.dialog.DialogFlowDAO import ai.tock.bot.engine.feature.FeatureDAO import ai.tock.bot.engine.feature.FeatureState @@ -74,6 +75,7 @@ import ai.tock.nlp.front.shared.config.EntityTypeDefinition import ai.tock.nlp.front.shared.config.IntentDefinition import ai.tock.nlp.front.shared.config.SentencesQuery import ai.tock.shared.Dice +import ai.tock.shared.defaultLocale import ai.tock.shared.injector import ai.tock.shared.provide import ai.tock.shared.vertx.UnauthorizedException @@ -106,7 +108,9 @@ object BotAdminService { private class BotStoryDefinitionConfigurationDumpController( override val targetNamespace: String, - override val botId: String) + override val botId: String, + val story: StoryDefinitionConfigurationDump, + val application: ApplicationDefinition) : StoryDefinitionConfigurationDumpController { override fun keepFeature(feature: StoryDefinitionConfigurationFeatureDump): Boolean = @@ -138,6 +142,22 @@ object BotAdminService { ) } } + + override fun checkIntent(intent: Intent?): Intent? { + if (intent != null) { + AdminService.createOrGetIntent( + targetNamespace, + IntentDefinition( + intent.name, + targetNamespace, + setOf(application._id), + emptySet(), + category = story.category + ) + ) + } + return intent + } } fun getBots(namespace: String, botId: String): List { @@ -277,59 +297,48 @@ object BotAdminService { } fun importStories(namespace: String, botId: String, stories: List) { - stories.map { - it.toStoryDefinitionConfiguration( - BotStoryDefinitionConfigurationDumpController(namespace, botId) - ) - } - .forEach { - saveStory(namespace, it) + val botConf = getBotConfigurationsByNamespaceAndBotId(namespace, botId).firstOrNull() + + if (botConf == null) { + badRequest("No bot configuration is defined yet") + } else { + val application = front.getApplicationByNamespaceAndName(namespace, botConf.nlpModel)!! + stories.map { + it.toStoryDefinitionConfiguration( + BotStoryDefinitionConfigurationDumpController(namespace, botId, it, application) + ) } + .forEach { + saveStory(namespace, it, botConf, application) + } + } } private fun saveStory( namespace: String, - story: StoryDefinitionConfiguration + story: StoryDefinitionConfiguration, + botConf: BotApplicationConfiguration, + application: ApplicationDefinition ) { + storyDefinitionDAO.getStoryDefinitionByNamespaceAndBotIdAndIntent( + namespace, + botConf.botId, + story.intent.name + )?.also { + storyDefinitionDAO.delete(it) + } + storyDefinitionDAO.getStoryDefinitionByNamespaceAndBotIdAndStoryId( + namespace, + botConf.botId, + story.storyId + )?.also { + storyDefinitionDAO.delete(it) + } - val botConf = getBotConfigurationsByNamespaceAndBotId(namespace, story.botId).firstOrNull() - return if (botConf != null) { - - val application = front.getApplicationByNamespaceAndName(namespace, botConf.nlpModel)!! - - AdminService.createOrGetIntent( - namespace, - IntentDefinition( - story.intent.name, - namespace, - setOf(application._id), - emptySet(), - category = story.category - ) - ) - - storyDefinitionDAO.getStoryDefinitionByNamespaceAndBotIdAndIntent( - namespace, - botConf.botId, - story.intent.name - )?.also { - storyDefinitionDAO.delete(it) - } - storyDefinitionDAO.getStoryDefinitionByNamespaceAndBotIdAndStoryId( - namespace, - botConf.botId, - story.storyId - )?.also { - storyDefinitionDAO.delete(it) - } - - storyDefinitionDAO.save(story) + storyDefinitionDAO.save(story) - //save all intents of steps - story.steps.forEach { saveUserSentenceOfStep(application, it) } - } else { - badRequest("No bot configuration is defined yet") - } + //save all intents of steps + story.steps.forEach { saveUserSentenceOfStep(application, it) } } fun findStoryByBotIdAndIntent(namespace: String, botId: String, intent: String): BotStoryDefinitionConfiguration? { @@ -670,6 +679,7 @@ object BotAdminService { if (label != null && step.intent != null) { application.supportedLocales.forEach { locale -> val text = label.findLabel(locale)?.label + ?: label.findLabel(defaultLocale)?.label if (text != null) { val existingSentence = front.search( SentencesQuery( diff --git a/bot/admin/web/src/app/bot/story/search-story.component.ts b/bot/admin/web/src/app/bot/story/search-story.component.ts index 5e2d55ecfa..776bbf4548 100644 --- a/bot/admin/web/src/app/bot/story/search-story.component.ts +++ b/bot/admin/web/src/app/bot/story/search-story.component.ts @@ -131,7 +131,7 @@ export class SearchStoryComponent implements OnInit, OnDestroy { this.uploader.onCompleteItem = (item: FileItem, response: string, status: number, headers: ParsedResponseHeaders) => { this.dialog.notify(`Dump uploaded`, "Dump"); - this.load(); + this.state.resetConfiguration(); }; this.displayUpload = true; } diff --git a/bot/engine/src/main/kotlin/admin/story/dump/StoryDefinitionConfigurationDump.kt b/bot/engine/src/main/kotlin/admin/story/dump/StoryDefinitionConfigurationDump.kt index 58726d6651..cbb7c5ec13 100644 --- a/bot/engine/src/main/kotlin/admin/story/dump/StoryDefinitionConfigurationDump.kt +++ b/bot/engine/src/main/kotlin/admin/story/dump/StoryDefinitionConfigurationDump.kt @@ -107,7 +107,7 @@ data class StoryDefinitionConfigurationDump( StoryDefinitionConfiguration( storyId, controller.botId, - intent, + controller.checkIntent(intent)!!, currentType, answers.map { it.toAnswer(currentType, controller) }, version, diff --git a/bot/engine/src/main/kotlin/admin/story/dump/StoryDefinitionConfigurationDumpController.kt b/bot/engine/src/main/kotlin/admin/story/dump/StoryDefinitionConfigurationDumpController.kt index a93318b7b8..93bd812046 100644 --- a/bot/engine/src/main/kotlin/admin/story/dump/StoryDefinitionConfigurationDumpController.kt +++ b/bot/engine/src/main/kotlin/admin/story/dump/StoryDefinitionConfigurationDumpController.kt @@ -17,10 +17,12 @@ package ai.tock.bot.admin.story.dump import ai.tock.bot.admin.answer.ScriptAnswerVersionedConfiguration +import ai.tock.bot.definition.Intent interface StoryDefinitionConfigurationDumpController { val targetNamespace: String val botId:String fun keepFeature(feature: StoryDefinitionConfigurationFeatureDump): Boolean fun buildScript(script: ScriptAnswerVersionedConfigurationDump, compile: Boolean): ScriptAnswerVersionedConfiguration + fun checkIntent(intent: Intent?): Intent? } \ No newline at end of file diff --git a/bot/engine/src/main/kotlin/admin/story/dump/StoryDefinitionConfigurationMandatoryEntityDump.kt b/bot/engine/src/main/kotlin/admin/story/dump/StoryDefinitionConfigurationMandatoryEntityDump.kt index e527c14a90..eecee33553 100644 --- a/bot/engine/src/main/kotlin/admin/story/dump/StoryDefinitionConfigurationMandatoryEntityDump.kt +++ b/bot/engine/src/main/kotlin/admin/story/dump/StoryDefinitionConfigurationMandatoryEntityDump.kt @@ -57,7 +57,7 @@ data class StoryDefinitionConfigurationMandatoryEntityDump( StoryDefinitionConfigurationMandatoryEntity( role, entityType, - intent, + controller.checkIntent(intent)!!, answers.map { it.toAnswer(currentType, controller) }, currentType ) diff --git a/bot/engine/src/main/kotlin/admin/story/dump/StoryDefinitionConfigurationStepDump.kt b/bot/engine/src/main/kotlin/admin/story/dump/StoryDefinitionConfigurationStepDump.kt index 0d22101f20..ae6f239222 100644 --- a/bot/engine/src/main/kotlin/admin/story/dump/StoryDefinitionConfigurationStepDump.kt +++ b/bot/engine/src/main/kotlin/admin/story/dump/StoryDefinitionConfigurationStepDump.kt @@ -77,9 +77,9 @@ data class StoryDefinitionConfigurationStepDump( fun toStep(controller: StoryDefinitionConfigurationDumpController): StoryDefinitionConfigurationStep = StoryDefinitionConfigurationStep( - name, - intent, - targetIntent, + name.takeUnless { it.isBlank() } ?: "${intent?.name}_$level", + controller.checkIntent(intent), + controller.checkIntent(targetIntent), answers.map { it.toAnswer(currentType, controller) }, currentType, "",