From 52ed41d3829f28f4181fceb1dfbeae4437d8910f Mon Sep 17 00:00:00 2001 From: Fabilin Date: Tue, 23 Jul 2024 17:55:19 +0200 Subject: [PATCH] fixes #1829 bot_engine: rename applicationId to connectorId --- .../client/src/main/kotlin/TockClientBus.kt | 4 +- .../service/src/main/kotlin/BotApiHandler.kt | 16 ++--- .../service/src/main/kotlin/Transformers.kt | 2 +- .../src/main/kotlin/WebConnector.kt | 32 +++++----- .../admin/bot/BotApplicationConfiguration.kt | 2 +- .../admin/message/MessageConfiguration.kt | 2 +- .../kotlin/definition/StoryHandlerBase.kt | 2 +- .../definition/StoryHandlerDefinitionBase.kt | 6 +- bot/engine/src/main/kotlin/engine/BotBus.kt | 11 ++-- bot/engine/src/main/kotlin/engine/Bus.kt | 11 +++- .../src/main/kotlin/engine/TockBotBus.kt | 8 +-- .../src/main/kotlin/engine/action/Action.kt | 18 ++++-- .../kotlin/engine/action/SendAttachment.kt | 20 ++++-- .../main/kotlin/engine/action/SendChoice.kt | 63 ++++++++++++++++--- .../main/kotlin/engine/action/SendDebug.kt | 32 ++++++++-- .../main/kotlin/engine/action/SendLocation.kt | 23 ++++++- .../main/kotlin/engine/action/SendSentence.kt | 33 ++++++++-- .../action/SendSentenceWithFootnotes.kt | 25 +++++++- .../engine/config/ConfiguredStoryHandler.kt | 14 ++--- .../CoreConfigurationModuleServiceLoader.kt | 4 +- .../kotlin/engine/config/RAGAnswerHandler.kt | 4 +- .../src/main/kotlin/engine/event/Event.kt | 14 ++++- .../src/main/kotlin/engine/message/Message.kt | 2 +- .../config/ConfiguredStoryHandlerTest.kt | 14 ++--- bot/test-base/src/main/kotlin/BotBusMock.kt | 8 +-- .../src/main/kotlin/BotBusMockInitializers.kt | 6 +- .../kotlin/junit/TockJUnit5ExtensionBase.kt | 46 +++++++------- .../src/main/kotlin/mock/BotBusMocked.kt | 6 +- 28 files changed, 303 insertions(+), 125 deletions(-) diff --git a/bot/api/client/src/main/kotlin/TockClientBus.kt b/bot/api/client/src/main/kotlin/TockClientBus.kt index 5a32421ab9..1d124ee46a 100644 --- a/bot/api/client/src/main/kotlin/TockClientBus.kt +++ b/bot/api/client/src/main/kotlin/TockClientBus.kt @@ -54,7 +54,7 @@ class TockClientBus( constructor(botDefinition: ClientBotDefinition, data: RequestData, sendAnswer: (BotResponse) -> Unit) : this(botDefinition, data.requestId, data.botRequest!!, sendAnswer) - override val applicationId: String = request.context.applicationId + override val connectorId: String = request.context.applicationId override val userId: PlayerId = request.context.userId override val botId: PlayerId = request.context.botId override val intent: IntentAware? = request.intent?.let { Intent(it) } @@ -191,7 +191,7 @@ class TockClientBus( } override fun withMessage(connectorType: ConnectorType, connectorId: String, messageProvider: () -> ConnectorMessage): ClientBus { - if (applicationId == connectorId && targetConnectorType == connectorType) { + if (this.connectorId == connectorId && targetConnectorType == connectorType) { context.connectorMessages[connectorType] = messageProvider() } return this diff --git a/bot/api/service/src/main/kotlin/BotApiHandler.kt b/bot/api/service/src/main/kotlin/BotApiHandler.kt index 0084f80f53..c6708f8744 100644 --- a/bot/api/service/src/main/kotlin/BotApiHandler.kt +++ b/bot/api/service/src/main/kotlin/BotApiHandler.kt @@ -80,7 +80,7 @@ internal class BotApiHandler( botDefinition.botId, story.definition.id ) - val endingStoryId = storySetting?.findEnabledEndWithStoryId(applicationId) + val endingStoryId = storySetting?.findEnabledEndWithStoryId(connectorId) val messages = response.messages if (messages.isEmpty()) { @@ -143,7 +143,7 @@ internal class BotApiHandler( userTimelineDAO.save(userTimeline, botDefinition, asynchronousProcess = false) } - val targetStory = botDefinition.findStoryDefinitionById(endingStoryId, applicationId) + val targetStory = botDefinition.findStoryDefinitionById(endingStoryId, connectorId) switchEndingStory(targetStory) } } @@ -185,7 +185,7 @@ internal class BotApiHandler( private fun BotBus.toAction(message: CustomMessage): Action { return SendSentence( botId, - applicationId, + connectorId, userId, null, listOfNotNull(message.message.value).toMutableList() @@ -201,7 +201,7 @@ internal class BotApiHandler( if (message != null) { return SendSentence( botId, - applicationId, + connectorId, userId, null, mutableListOf(message) @@ -210,7 +210,7 @@ internal class BotApiHandler( } return SendSentence( botId, - applicationId, + connectorId, userId, text ) @@ -219,7 +219,7 @@ internal class BotApiHandler( private fun BotBus.toAction(data: Debug): Action { return SendDebug( botId, - applicationId, + connectorId, userId, data.text, data.data @@ -237,7 +237,7 @@ internal class BotApiHandler( return connectorMessages?.map { SendSentence( botId, - applicationId, + connectorId, userId, null, mutableListOf(it) @@ -256,7 +256,7 @@ internal class BotApiHandler( return connectorMessages?.map { SendSentence( botId, - applicationId, + connectorId, userId, null, mutableListOf(it) diff --git a/bot/api/service/src/main/kotlin/Transformers.kt b/bot/api/service/src/main/kotlin/Transformers.kt index 6980f40a12..1eecce1cd1 100644 --- a/bot/api/service/src/main/kotlin/Transformers.kt +++ b/bot/api/service/src/main/kotlin/Transformers.kt @@ -77,7 +77,7 @@ private fun BotBus.toRequestContext(): RequestContext = sourceConnectorType, targetConnectorType, userInterfaceType, - applicationId, + connectorId, userId, botId, userPreferences.toUserData(), diff --git a/bot/connector-web/src/main/kotlin/WebConnector.kt b/bot/connector-web/src/main/kotlin/WebConnector.kt index e7d028dbd1..9c3620faca 100644 --- a/bot/connector-web/src/main/kotlin/WebConnector.kt +++ b/bot/connector-web/src/main/kotlin/WebConnector.kt @@ -106,9 +106,11 @@ val webConnectorUseExtraHeadersAsMetadata: Boolean = booleanProperty("tock_web_connector_use_extra_header_as_metadata_request", false) class WebConnector internal constructor( - val applicationId: String, + val connectorId: String, val path: String ) : ConnectorBase(webConnectorType, setOf(CAROUSEL)), OrchestrationConnector { + @Deprecated("Use the more aptly named connectorId field", ReplaceWith("connectorId")) + val applicationId: String get() = connectorId companion object { private val logger = KotlinLogging.logger {} @@ -186,7 +188,7 @@ class WebConnector internal constructor( val timerId = vertx.setPeriodic(Duration.ofSeconds(sseKeepaliveDelay).toMillis()) { response.sendSsePing() } - val channelId = channels.register(applicationId, userId) { webConnectorResponse -> + val channelId = channels.register(connectorId, userId) { webConnectorResponse -> response.sendSseResponse(webConnectorResponse) } response.closeHandler { @@ -288,11 +290,11 @@ class WebConnector internal constructor( val applicationId = if (request.connectorId?.isNotBlank() == true) if (webConnectorBridgeEnabled) - request.connectorId.also { logger.debug { "Web bridge: $applicationId -> $it" } } + request.connectorId.also { logger.debug { "Web bridge: $connectorId -> $it" } } else - applicationId.also { logger.warn { "Web bridge disabled." } } + connectorId.also { logger.warn { "Web bridge disabled." } } else - applicationId + connectorId val event = request.toEvent(applicationId) val requestInfos = WebRequestInfos(context.request()) @@ -349,12 +351,12 @@ class WebConnector internal constructor( throw UnsupportedOperationException("Web Connector only supports notifications when SSE is enabled") } handleEvent( - applicationId = applicationId, + applicationId = connectorId, locale = defaultLocale, event = SendChoice( recipientId, - applicationId, - PlayerId(applicationId, bot), + connectorId, + PlayerId(connectorId, bot), intent.wrappedIntent().name, step, parameters @@ -392,14 +394,14 @@ class WebConnector internal constructor( val request: ResumeOrchestrationRequest = mapper.readValue(context.body().asString()) val callback = RestOrchestrationCallback( webConnectorType, - applicationId = applicationId, + applicationId = connectorId, context = context, orchestrationMapper = webMapper ) controller.handle(request.toAction(), ConnectorData(callback)) } catch (t: Throwable) { - RestOrchestrationCallback(webConnectorType, applicationId, context = context).sendError() + RestOrchestrationCallback(webConnectorType, connectorId, context = context).sendError() BotRepository.requestTimer.throwable(t, timerData) } finally { BotRepository.requestTimer.end(timerData) @@ -416,23 +418,23 @@ class WebConnector internal constructor( val request: AskEligibilityToOrchestratedBotRequest = mapper.readValue(context.body().asString()) val callback = RestOrchestrationCallback( webConnectorType, - applicationId, + connectorId, context = context, orchestrationMapper = webMapper ) - val support = controller.support(request.toAction(applicationId), ConnectorData(callback)) + val support = controller.support(request.toAction(connectorId), ConnectorData(callback)) val sendEligibility = SecondaryBotEligibilityResponse( support, OrchestrationMetaData( - playerId = PlayerId(applicationId, bot), - applicationId = applicationId, + playerId = PlayerId(connectorId, bot), + applicationId = connectorId, recipientId = request.metadata?.playerId ?: PlayerId(Dice.newId(), user) ) ) callback.sendResponse(sendEligibility) } catch (t: Throwable) { - RestOrchestrationCallback(webConnectorType, applicationId, context = context).sendError() + RestOrchestrationCallback(webConnectorType, connectorId, context = context).sendError() BotRepository.requestTimer.throwable(t, timerData) } finally { BotRepository.requestTimer.end(timerData) diff --git a/bot/engine/src/main/kotlin/admin/bot/BotApplicationConfiguration.kt b/bot/engine/src/main/kotlin/admin/bot/BotApplicationConfiguration.kt index ad65f87807..6fa7268e82 100644 --- a/bot/engine/src/main/kotlin/admin/bot/BotApplicationConfiguration.kt +++ b/bot/engine/src/main/kotlin/admin/bot/BotApplicationConfiguration.kt @@ -137,5 +137,5 @@ data class BotApplicationConfigurationKey( botDefinition.namespace ) - constructor(bus: BotBus) : this(bus.applicationId, bus.botDefinition) + constructor(bus: BotBus) : this(bus.connectorId, bus.botDefinition) } diff --git a/bot/engine/src/main/kotlin/admin/message/MessageConfiguration.kt b/bot/engine/src/main/kotlin/admin/message/MessageConfiguration.kt index c54dc5b7df..3ec03231ed 100644 --- a/bot/engine/src/main/kotlin/admin/message/MessageConfiguration.kt +++ b/bot/engine/src/main/kotlin/admin/message/MessageConfiguration.kt @@ -33,7 +33,7 @@ interface MessageConfiguration { fun toAction(bus: BotBus): Action = toAction( bus.userId, - bus.applicationId, + bus.connectorId, bus.botId, bus.userLocale, bus.userInterfaceType diff --git a/bot/engine/src/main/kotlin/definition/StoryHandlerBase.kt b/bot/engine/src/main/kotlin/definition/StoryHandlerBase.kt index 7cbe8e3398..e9a2df84f8 100644 --- a/bot/engine/src/main/kotlin/definition/StoryHandlerBase.kt +++ b/bot/engine/src/main/kotlin/definition/StoryHandlerBase.kt @@ -167,7 +167,7 @@ abstract class StoryHandlerBase( * Finds the story definition of this handler. */ open fun findStoryDefinition(bus: BotBus): StoryDefinition? = - bus.botDefinition.findStoryByStoryHandler(this, bus.applicationId) + bus.botDefinition.findStoryByStoryHandler(this, bus.connectorId) /** * Handles the action and switches the context to the underlying story definition. diff --git a/bot/engine/src/main/kotlin/definition/StoryHandlerDefinitionBase.kt b/bot/engine/src/main/kotlin/definition/StoryHandlerDefinitionBase.kt index c1cea2d489..3ef78cafa2 100644 --- a/bot/engine/src/main/kotlin/definition/StoryHandlerDefinitionBase.kt +++ b/bot/engine/src/main/kotlin/definition/StoryHandlerDefinitionBase.kt @@ -22,12 +22,12 @@ import ai.tock.bot.connector.ConnectorType import ai.tock.bot.engine.BotBus import ai.tock.shared.injector import ai.tock.shared.provide -import mu.KotlinLogging import kotlin.LazyThreadSafetyMode.PUBLICATION import kotlin.reflect.KClass import kotlin.reflect.full.isSubtypeOf import kotlin.reflect.full.primaryConstructor import kotlin.reflect.full.starProjectedType +import mu.KotlinLogging /** * Base implementation of [StoryHandlerDefinition]. @@ -95,8 +95,8 @@ abstract class StoryHandlerDefinitionBase>(val connectorProvider.provide(this, connectorId) as? T? private val cachedConnector: T? by lazy(PUBLICATION) { - (findConnector(applicationId) ?: findConnector(connectorType)) - .also { if (it == null) logger.warn { "unsupported connector type $applicationId or $connectorType for ${this::class}" } } + (findConnector(connectorId) ?: findConnector(connectorType)) + .also { if (it == null) logger.warn { "unsupported connector type $connectorId or $connectorType for ${this::class}" } } } /** diff --git a/bot/engine/src/main/kotlin/engine/BotBus.kt b/bot/engine/src/main/kotlin/engine/BotBus.kt index 2c1a73ec2b..bcf3617717 100644 --- a/bot/engine/src/main/kotlin/engine/BotBus.kt +++ b/bot/engine/src/main/kotlin/engine/BotBus.kt @@ -75,16 +75,13 @@ interface BotBus : Bus { } /** - * The current TOCK application id. + * The connector ID. * * This identifier matches the identifier of the [underlyingConnector], as defined in TOCK Studio. * - * *This identifier is not to be confused with the chat platform's application id (this is not a Messenger/Whatsapp - * application ID).* - * * @see ConnectorConfiguration.connectorId */ - override val applicationId: String + override val connectorId: String /** * The bot definition of the current bot. @@ -373,7 +370,7 @@ interface BotBus : Bus { * Sends text that should not be translated as last bot answer. */ override fun endRawText(plainText: CharSequence?, delay: Long): BotBus { - return end(SendSentence(botId, applicationId, userId, plainText), delay) + return end(SendSentence(botId, connectorId, userId, plainText), delay) } /** @@ -507,7 +504,7 @@ interface BotBus : Bus { */ fun isFeatureEnabled(feature: FeatureType, default: Boolean = false) = injector.provide() - .isEnabled(botDefinition.botId, botDefinition.namespace, feature, applicationId, default, userId.id) + .isEnabled(botDefinition.botId, botDefinition.namespace, feature, connectorId, default, userId.id) /** * Marks the current as not understood in the nlp model. diff --git a/bot/engine/src/main/kotlin/engine/Bus.kt b/bot/engine/src/main/kotlin/engine/Bus.kt index 11dcfac940..e3bb4f3baa 100644 --- a/bot/engine/src/main/kotlin/engine/Bus.kt +++ b/bot/engine/src/main/kotlin/engine/Bus.kt @@ -29,10 +29,19 @@ import ai.tock.bot.engine.user.PlayerId */ interface Bus> : I18nTranslator { + /** + * The connector ID. + */ + val connectorId: String + /** * The current TOCK application id. + * + * *This identifier is not to be confused with the chat platform's application id (this is not a Messenger/Whatsapp + * application ID).* */ - val applicationId: String + @Deprecated("Use more appropriately named connectorId", ReplaceWith("connectorId")) + val applicationId: String get() = connectorId /** * The current bot id. diff --git a/bot/engine/src/main/kotlin/engine/TockBotBus.kt b/bot/engine/src/main/kotlin/engine/TockBotBus.kt index ce2d954ca0..daa6043cb9 100644 --- a/bot/engine/src/main/kotlin/engine/TockBotBus.kt +++ b/bot/engine/src/main/kotlin/engine/TockBotBus.kt @@ -61,7 +61,7 @@ internal class TockBotBus( currentDialog.stories.add(value) } override val botDefinition: BotDefinition = bot.botDefinition - override val applicationId = action.applicationId + override val connectorId = action.applicationId override val botId = action.recipientId override val userId = action.playerId override val userPreferences: UserPreferences = userTimeline.userPreferences @@ -166,11 +166,11 @@ internal class TockBotBus( } override fun sendRawText(plainText: CharSequence?, delay: Long): BotBus { - return answer(SendSentence(botId, applicationId, userId, plainText), delay) + return answer(SendSentence(botId, connectorId, userId, plainText), delay) } override fun sendDebugData(title: String, data: Any?): BotBus { - return answer(SendDebug(botId, applicationId, userId, title, data), 0) + return answer(SendDebug(botId, connectorId, userId, title, data), 0) } override fun send(action: Action, delay: Long): BotBus { @@ -200,7 +200,7 @@ internal class TockBotBus( } override fun withMessage(connectorType: ConnectorType, connectorId: String, messageProvider: () -> ConnectorMessage): BotBus { - if (applicationId == connectorId && isCompatibleWith(connectorType)) { + if (this.connectorId == connectorId && isCompatibleWith(connectorType)) { context.addMessage(messageProvider.invoke()) } return this diff --git a/bot/engine/src/main/kotlin/engine/action/Action.kt b/bot/engine/src/main/kotlin/engine/action/Action.kt index c93b41caf7..f438edab82 100644 --- a/bot/engine/src/main/kotlin/engine/action/Action.kt +++ b/bot/engine/src/main/kotlin/engine/action/Action.kt @@ -25,21 +25,31 @@ import ai.tock.shared.jackson.mapper import com.fasterxml.jackson.module.kotlin.readValue import java.time.Instant import org.litote.kmongo.Id +import org.litote.kmongo.newId /** * A user (or bot) action. - * - * @param applicationId the TOCK application id (matches the id of the connector) */ abstract class Action( val playerId: PlayerId, val recipientId: PlayerId, - applicationId: String, + connectorId: String, id: Id, date: Instant, state: EventState, val metadata: ActionMetadata = ActionMetadata() -) : Event(applicationId, id, date, state) { +) : Event(connectorId, id, date, state) { + @Deprecated("Use constructor with connectorId", ReplaceWith("Action(playerId = playerId, recipientId = recipientId, connectorId = applicationId, id = id, date = date, state = state, metadata = metadata)")) + constructor( + playerId: PlayerId, + recipientId: PlayerId, + applicationId: String, + id: Id = newId(), + date: Instant = Instant.now(), + state: EventState = EventState(), + metadata: ActionMetadata = ActionMetadata(), + _deprecatedConstructor: Nothing? = null, + ): this(playerId, recipientId, applicationId, id, date, state, metadata) abstract fun toMessage(): Message diff --git a/bot/engine/src/main/kotlin/engine/action/SendAttachment.kt b/bot/engine/src/main/kotlin/engine/action/SendAttachment.kt index e01d8972c0..f1d2c059cd 100644 --- a/bot/engine/src/main/kotlin/engine/action/SendAttachment.kt +++ b/bot/engine/src/main/kotlin/engine/action/SendAttachment.kt @@ -26,12 +26,10 @@ import org.litote.kmongo.newId /** * A simple attachment file sent. - * - * @param applicationId the TOCK application id (matches the id of the connector) */ open class SendAttachment( playerId: PlayerId, - applicationId: String, + connectorId: String, recipientId: PlayerId, val url: String, val type: AttachmentType, @@ -40,7 +38,21 @@ open class SendAttachment( state: EventState = EventState(), metadata: ActionMetadata = ActionMetadata() ) : - Action(playerId, recipientId, applicationId, id, date, state, metadata) { + Action(playerId, recipientId, connectorId, id, date, state, metadata) { + + @Deprecated("Use constructor with connectorId", ReplaceWith("Action(connectorId = applicationId, id, date, state)")) + constructor( + playerId: PlayerId, + applicationId: String, + recipientId: PlayerId, + url: String, + type: AttachmentType, + id: Id = newId(), + date: Instant = Instant.now(), + state: EventState = EventState(), + metadata: ActionMetadata = ActionMetadata(), + _deprecatedConstructor: Nothing? = null, + ): this(playerId, applicationId, recipientId, url, type, id, date, state, metadata) enum class AttachmentType { image, audio, video, file diff --git a/bot/engine/src/main/kotlin/engine/action/SendChoice.kt b/bot/engine/src/main/kotlin/engine/action/SendChoice.kt index 734b97c476..5f4cc73bc5 100644 --- a/bot/engine/src/main/kotlin/engine/action/SendChoice.kt +++ b/bot/engine/src/main/kotlin/engine/action/SendChoice.kt @@ -35,12 +35,10 @@ import org.litote.kmongo.newId /** * A user choice (click on a button or direct action). - * - * @param applicationId the TOCK application id (matches the id of the connector) */ class SendChoice( playerId: PlayerId, - applicationId: String, + connectorId: String, recipientId: PlayerId, val intentName: String, val parameters: Map = emptyMap(), @@ -48,13 +46,35 @@ class SendChoice( date: Instant = Instant.now(), state: EventState = EventState(), metadata: ActionMetadata = ActionMetadata() -) : Action(playerId, recipientId, applicationId, id, date, state, metadata) { - +) : Action(playerId, recipientId, connectorId, id, date, state, metadata) { + @Deprecated("Use constructor with connectorId", ReplaceWith("SendChoice(" + + "playerId, " + + "connectorId = applicationId, " + + "recipientId, " + + "intentName, " + + "parameters, " + + "id, " + + "date, " + + "state, " + + "metadata)")) constructor( playerId: PlayerId, applicationId: String, recipientId: PlayerId, intentName: String, + parameters: Map = emptyMap(), + id: Id = newId(), + date: Instant = Instant.now(), + state: EventState = EventState(), + metadata: ActionMetadata = ActionMetadata(), + _deprecatedConstructor: Nothing? = null, + ): this(playerId, applicationId, recipientId, intentName, parameters, id, date, state, metadata) + + constructor( + playerId: PlayerId, + connectorId: String, + recipientId: PlayerId, + intentName: String, step: StoryStep?, parameters: Map = emptyMap(), id: Id = newId(), @@ -64,7 +84,7 @@ class SendChoice( ) : this( playerId, - applicationId, + connectorId, recipientId, intentName, parameters + mapNotNullValues(STEP_PARAMETER to step?.name), @@ -74,6 +94,33 @@ class SendChoice( metadata ) + @Deprecated("Use constructor with connectorId", ReplaceWith("SendChoice(" + + "playerId, " + + "connectorId = applicationId, " + + "recipientId, " + + "intentName, " + + "step, " + + "parameters, " + + "id, " + + "date, " + + "state, " + + "metadata)")) + constructor( + playerId: PlayerId, + applicationId: String, + recipientId: PlayerId, + intentName: String, + step: StoryStep?, + parameters: Map = emptyMap(), + id: Id = newId(), + date: Instant = Instant.now(), + state: EventState = EventState(), + metadata: ActionMetadata = ActionMetadata(), + _deprecatedConstructor: Nothing? = null, + ) : this( + playerId, applicationId, recipientId, intentName, step, parameters, id, date, state, metadata + ) + companion object { const val TITLE_PARAMETER = "_title" @@ -134,7 +181,7 @@ class SendChoice( parameters, bus.stepName, bus.currentIntent?.wrappedIntent(), - sourceAppId = bus.applicationId + sourceAppId = bus.connectorId ) } @@ -165,7 +212,7 @@ class SendChoice( parameters, bus.stepName, bus.currentIntent?.wrappedIntent(), - sourceAppId = bus.applicationId + sourceAppId = bus.connectorId ) } diff --git a/bot/engine/src/main/kotlin/engine/action/SendDebug.kt b/bot/engine/src/main/kotlin/engine/action/SendDebug.kt index 1355981eac..6407a75114 100644 --- a/bot/engine/src/main/kotlin/engine/action/SendDebug.kt +++ b/bot/engine/src/main/kotlin/engine/action/SendDebug.kt @@ -16,19 +16,17 @@ package ai.tock.bot.engine.action -import ai.tock.bot.connector.ConnectorMessage import ai.tock.bot.engine.dialog.EventState import ai.tock.bot.engine.message.DebugMessage import ai.tock.bot.engine.message.Message -import ai.tock.bot.engine.message.Sentence import ai.tock.bot.engine.user.PlayerId +import java.time.Instant import org.litote.kmongo.Id import org.litote.kmongo.newId -import java.time.Instant class SendDebug( playerId: PlayerId, - applicationId: String, + connectorId: String, recipientId: PlayerId, val text: String, val data: Any?, @@ -36,7 +34,31 @@ class SendDebug( date: Instant = Instant.now(), state: EventState = EventState(), metadata: ActionMetadata = ActionMetadata(), -) : Action(playerId, recipientId, applicationId, id, date, state, metadata) { +) : Action(playerId, recipientId, connectorId, id, date, state, metadata) { + @Deprecated("Use constructor with connectorId", ReplaceWith("SendDebug(" + + "playerId, " + + "connectorId = applicationId, " + + "recipientId, " + + "text, " + + "data, " + + "id, " + + "date, " + + "state, " + + "metadata)")) + constructor( + playerId: PlayerId, + applicationId: String, + recipientId: PlayerId, + text: String, + data: Any?, + id: Id = newId(), + date: Instant = Instant.now(), + state: EventState = EventState(), + metadata: ActionMetadata = ActionMetadata(), + _deprecatedConstructor: Nothing? = null, + ): this(playerId, applicationId, recipientId, text, data, id, date, state, metadata) + + override fun toMessage(): Message { return DebugMessage(text, data) } diff --git a/bot/engine/src/main/kotlin/engine/action/SendLocation.kt b/bot/engine/src/main/kotlin/engine/action/SendLocation.kt index 150787fdd6..7c56fb795a 100644 --- a/bot/engine/src/main/kotlin/engine/action/SendLocation.kt +++ b/bot/engine/src/main/kotlin/engine/action/SendLocation.kt @@ -27,8 +27,6 @@ import org.litote.kmongo.newId /** * A user location transmission. - * - * @param applicationId the TOCK application id (matches the id of the connector) */ class SendLocation( playerId: PlayerId, @@ -42,6 +40,27 @@ class SendLocation( ) : Action(playerId, recipientId, applicationId, id, date, state, metadata) { + @Deprecated("Use constructor with connectorId", ReplaceWith("SendLocation(" + + "playerId, " + + "connectorId = applicationId, " + + "recipientId, " + + "location, " + + "id, " + + "date, " + + "state, " + + "metadata)")) + constructor( + playerId: PlayerId, + applicationId: String, + recipientId: PlayerId, + location: UserLocation?, + id: Id = newId(), + date: Instant = Instant.now(), + state: EventState = EventState(), + metadata: ActionMetadata = ActionMetadata(), + _deprecatedConstructor: Nothing? = null, + ): this(playerId, applicationId, recipientId, location, id, date, state, metadata) + override fun toMessage(): Message { return Location(location) } diff --git a/bot/engine/src/main/kotlin/engine/action/SendSentence.kt b/bot/engine/src/main/kotlin/engine/action/SendSentence.kt index a7d2f36fab..012b471890 100644 --- a/bot/engine/src/main/kotlin/engine/action/SendSentence.kt +++ b/bot/engine/src/main/kotlin/engine/action/SendSentence.kt @@ -31,12 +31,10 @@ import org.litote.kmongo.newId /** * The most important [Action] class. * Could be a simple text, or a complex message using one or more [ConnectorMessage]. - * - * @param applicationId the TOCK application id (matches the id of the connector) */ open class SendSentence( playerId: PlayerId, - applicationId: String, + connectorId: String, recipientId: PlayerId, val text: CharSequence?, open val messages: MutableList = mutableListOf(), @@ -50,7 +48,34 @@ open class SendSentence( */ var precomputedNlp: NlpResult? = null ) : - Action(playerId, recipientId, applicationId, id, date, state, metadata) { + Action(playerId, recipientId, connectorId, id, date, state, metadata) { + + @Deprecated("Use constructor with connectorId", ReplaceWith("SendSentence(" + + "playerId, " + + "connectorId = applicationId, " + + "recipientId, " + + "text, " + + "messages, " + + "id, " + + "date, " + + "state, " + + "metadata, " + + "nlpStats, " + + "precomputedNlp)")) + constructor( + playerId: PlayerId, + applicationId: String, + recipientId: PlayerId, + text: CharSequence?, + messages: MutableList = mutableListOf(), + id: Id = newId(), + date: Instant = Instant.now(), + state: EventState = EventState(), + metadata: ActionMetadata = ActionMetadata(), + nlpStats: NlpCallStats? = null, + precomputedNlp: NlpResult? = null, + _deprecatedConstructor: Nothing? = null, + ): this(playerId, applicationId, recipientId, text, messages, id, date, state, metadata, nlpStats, precomputedNlp) @Transient val stringText: String? = text?.toString() diff --git a/bot/engine/src/main/kotlin/engine/action/SendSentenceWithFootnotes.kt b/bot/engine/src/main/kotlin/engine/action/SendSentenceWithFootnotes.kt index 1446b6d0fe..b04b42262e 100644 --- a/bot/engine/src/main/kotlin/engine/action/SendSentenceWithFootnotes.kt +++ b/bot/engine/src/main/kotlin/engine/action/SendSentenceWithFootnotes.kt @@ -20,9 +20,9 @@ import ai.tock.bot.engine.dialog.EventState import ai.tock.bot.engine.message.Message import ai.tock.bot.engine.message.SentenceWithFootnotes import ai.tock.bot.engine.user.PlayerId +import java.time.Instant import org.litote.kmongo.Id import org.litote.kmongo.newId -import java.time.Instant open class SendSentenceWithFootnotes( @@ -37,6 +37,29 @@ open class SendSentenceWithFootnotes( metadata: ActionMetadata = ActionMetadata() ) : Action(playerId, recipientId, applicationId, id, date, state, metadata) { + @Deprecated("Use constructor with connectorId", ReplaceWith("SendChoice(" + + "playerId, " + + "connectorId = applicationId, " + + "recipientId, " + + "text, " + + "footnotes, " + + "id, " + + "date, " + + "state, " + + "metadata)")) + constructor( + playerId: PlayerId, + applicationId: String, + recipientId: PlayerId, + text: CharSequence, + footnotes: MutableList = mutableListOf(), + id: Id = newId(), + date: Instant = Instant.now(), + state: EventState = EventState(), + metadata: ActionMetadata = ActionMetadata(), + _deprecatedConstructor: Nothing? = null, + ): this(playerId, applicationId, recipientId, text, footnotes, id, date, state, metadata) + override fun toMessage(): Message = SentenceWithFootnotes(text.toString(), footnotes.toList()) } diff --git a/bot/engine/src/main/kotlin/engine/config/ConfiguredStoryHandler.kt b/bot/engine/src/main/kotlin/engine/config/ConfiguredStoryHandler.kt index c48e337036..7f50c3a095 100644 --- a/bot/engine/src/main/kotlin/engine/config/ConfiguredStoryHandler.kt +++ b/bot/engine/src/main/kotlin/engine/config/ConfiguredStoryHandler.kt @@ -116,7 +116,7 @@ internal class ConfiguredStoryHandler( ?: (bus.intent.takeIf { !step.hasCurrentAnswer() }?.wrappedIntent()?.name) bus.botDefinition .takeIf { targetIntent != null } - ?.findStoryDefinition(targetIntent, bus.applicationId) + ?.findStoryDefinition(targetIntent, bus.connectorId) ?.takeUnless { it == bus.botDefinition.unknownStory } ?.takeUnless { bus.viewedStories.contains(it) } ?.apply { @@ -236,8 +236,8 @@ internal class ConfiguredStoryHandler( bus: BotBus ) { if (!isMissingMandatoryEntities(bus) && bus.story.definition.steps.isEmpty() || step?.hasNoChildren == true) { - configuration.findEnabledEndWithStoryId(bus.applicationId) - ?.let { bus.botDefinition.findStoryDefinitionById(it, bus.applicationId) } + configuration.findEnabledEndWithStoryId(bus.connectorId) + ?.let { bus.botDefinition.findStoryDefinitionById(it, bus.connectorId) } ?.let { // before switching story (Only for an ending rule), we need to save a snapshot with the current intent if (bus.connectorData.saveTimeline){ @@ -296,7 +296,7 @@ internal class ConfiguredStoryHandler( } it.last().apply { val currentStep = (step as? Step)?.configuration - val endingStoryRule = configuration.findEnabledEndWithStoryId(applicationId) != null + val endingStoryRule = configuration.findEnabledEndWithStoryId(connectorId) != null send( container, this, isMissingMandatoryEntities || @@ -394,7 +394,7 @@ internal class ConfiguredStoryHandler( .map { SendSentence( botId, - applicationId, + connectorId, userId, null, mutableListOf(it) @@ -406,7 +406,7 @@ internal class ConfiguredStoryHandler( ?.let { SendSentenceWithFootnotes( playerId = botId, - applicationId = applicationId, + applicationId = connectorId, recipientId = userId, text = label, footnotes = it.toMutableList() @@ -414,7 +414,7 @@ internal class ConfiguredStoryHandler( } ?: SendSentence( botId, - applicationId, + connectorId, userId, label ) diff --git a/bot/engine/src/main/kotlin/engine/config/CoreConfigurationModuleServiceLoader.kt b/bot/engine/src/main/kotlin/engine/config/CoreConfigurationModuleServiceLoader.kt index 5b9eac2fe1..7ad71abe8e 100644 --- a/bot/engine/src/main/kotlin/engine/config/CoreConfigurationModuleServiceLoader.kt +++ b/bot/engine/src/main/kotlin/engine/config/CoreConfigurationModuleServiceLoader.kt @@ -45,7 +45,7 @@ private val satisfactionModule = BotConfigurationModule( SATISFACTION_MODULE_ID, listOf( BotConfigurationStoryHandlerBase(REVIEW_ASK.id) { - val storyReview = botDefinition.findStoryDefinitionById(SATISFACTION_MODULE_ID, applicationId) + val storyReview = botDefinition.findStoryDefinitionById(SATISFACTION_MODULE_ID, connectorId) val ratingIndex = storyReview.steps.indexOfFirst { (it as? StoryDefinitionConfigurationStep.Step) ?.configuration?.userSentenceLabel?.defaultLabel == userText?.trim() @@ -65,7 +65,7 @@ private val satisfactionModule = BotConfigurationModule( changeContextValue(REVIEW_COMMENT_PARAMETER, true) } else { dialog.review = userText - handleAndSwitchStory(botDefinition.findStoryDefinitionById(SatisfactionIntent.REVIEW_ADDED.id, applicationId)) + handleAndSwitchStory(botDefinition.findStoryDefinitionById(SatisfactionIntent.REVIEW_ADDED.id, connectorId)) } } ) diff --git a/bot/engine/src/main/kotlin/engine/config/RAGAnswerHandler.kt b/bot/engine/src/main/kotlin/engine/config/RAGAnswerHandler.kt index 904d738d23..5b7337c67d 100644 --- a/bot/engine/src/main/kotlin/engine/config/RAGAnswerHandler.kt +++ b/bot/engine/src/main/kotlin/engine/config/RAGAnswerHandler.kt @@ -81,7 +81,7 @@ object RAGAnswerHandler : AbstractProactiveAnswerHandler { logger.info { "Send RAG answer." } send( SendSentenceWithFootnotes( - botId, applicationId, userId, text = answer.text, footnotes = answer.footnotes.map { + botId, connectorId, userId, text = answer.text, footnotes = answer.footnotes.map { Footnote( it.identifier, it.title, it.url, if(action.metadata.sourceWithContent) it.content else null, @@ -138,7 +138,7 @@ object RAGAnswerHandler : AbstractProactiveAnswerHandler { val noAnswerStoryId = ragConfig.noAnswerStoryId if (!noAnswerStoryId.isNullOrBlank()) { logger.info { "A no-answer story $noAnswerStoryId is configured, so run it." } - noAnswerStory = botDefinition.findStoryDefinitionById(noAnswerStoryId, applicationId).let { + noAnswerStory = botDefinition.findStoryDefinitionById(noAnswerStoryId, connectorId).let { // Prevent infinite loop when the noAnswerStory is removed or disabled if (it.id == RAGStoryDefinition.RAG_STORY_NAME) { logger.info { "The no-answer story is removed or disabled, so run the default unknown story." } diff --git a/bot/engine/src/main/kotlin/engine/event/Event.kt b/bot/engine/src/main/kotlin/engine/event/Event.kt index b8a4825c6e..1afdea89a6 100644 --- a/bot/engine/src/main/kotlin/engine/event/Event.kt +++ b/bot/engine/src/main/kotlin/engine/event/Event.kt @@ -35,7 +35,7 @@ abstract class Event( * * @see ConnectorConfiguration.connectorId */ - val applicationId: String, + val connectorId: String, /** * The unique id of the event. */ @@ -49,6 +49,18 @@ abstract class Event( */ val state: EventState = EventState() ) { + @Deprecated("Use constructor with connectorId", ReplaceWith("Event(connectorId = applicationId, id, date, state)")) + constructor( + applicationId: String, + id: Id = newId(), + date: Instant = Instant.now(), + state: EventState = EventState(), + _deprecatedConstructor: Nothing? = null, + ): this(applicationId, id, date, state) + + @Deprecated("Use more appropriately named connectorId", ReplaceWith("connectorId")) + val applicationId: String get() = connectorId + /** * Does this event contains specified role entity? */ diff --git a/bot/engine/src/main/kotlin/engine/message/Message.kt b/bot/engine/src/main/kotlin/engine/message/Message.kt index f31c7a7f2c..0d9e7084f9 100644 --- a/bot/engine/src/main/kotlin/engine/message/Message.kt +++ b/bot/engine/src/main/kotlin/engine/message/Message.kt @@ -29,7 +29,7 @@ interface Message { val eventType: EventType val delay: Long - fun toAction(bus: BotBus): Action = toAction(bus.botId, bus.applicationId, bus.userId) + fun toAction(bus: BotBus): Action = toAction(bus.botId, bus.connectorId, bus.userId) fun toAction( playerId: PlayerId, diff --git a/bot/engine/src/test/kotlin/engine/config/ConfiguredStoryHandlerTest.kt b/bot/engine/src/test/kotlin/engine/config/ConfiguredStoryHandlerTest.kt index 3fea1211f8..6dd389c052 100644 --- a/bot/engine/src/test/kotlin/engine/config/ConfiguredStoryHandlerTest.kt +++ b/bot/engine/src/test/kotlin/engine/config/ConfiguredStoryHandlerTest.kt @@ -48,10 +48,10 @@ import io.mockk.justRun import io.mockk.mockk import io.mockk.slot import io.mockk.verify -import org.junit.jupiter.api.Test -import org.litote.kmongo.toId import kotlin.test.assertEquals import kotlin.test.assertTrue +import org.junit.jupiter.api.Test +import org.litote.kmongo.toId class ConfiguredStoryHandlerTest { @@ -90,7 +90,7 @@ class ConfiguredStoryHandlerTest { every { targetConnectorType } returns ConnectorType("a") every { botId } returns PlayerId("botId") every { userId } returns PlayerId("userId") - every { applicationId } returns "appId" + every { connectorId } returns "appId" every { currentAnswerIndex } returns 1 every { userTimeline } returns UserTimeline(PlayerId("userId")) every { botDefinition } returns BotDefinitionTest() @@ -193,7 +193,7 @@ class ConfiguredStoryHandlerTest { every { targetConnectorType } returns ConnectorType("a") every { botId } returns PlayerId("botId") every { userId } returns PlayerId("userId") - every { applicationId } returns "appId" + every { connectorId } returns "appId" every { currentAnswerIndex } returns 1 every { userTimeline } returns UserTimeline(PlayerId("userId")) every { botDefinition } returns BotDefinitionTest() @@ -338,7 +338,7 @@ class ConfiguredStoryHandlerTest { every { targetConnectorType } returns ConnectorType("a") every { botId } returns PlayerId("botId") every { userId } returns PlayerId("userId") - every { applicationId } returns "appId" + every { connectorId } returns "appId" every { currentAnswerIndex } returns 1 every { userTimeline } returns UserTimeline(PlayerId("userId")) every { botDefinition } returns BotDefinitionTest() @@ -487,7 +487,7 @@ class ConfiguredStoryHandlerTest { every { botId } returns PlayerId("botId") every { userId } returns PlayerId("userId") every { userTimeline } returns UserTimeline(userId) - every { applicationId } returns "appId" + every { connectorId } returns "appId" every { currentAnswerIndex } returns 1 every { botDefinition } returns BotDefinitionTest() every { step } returns null @@ -573,7 +573,7 @@ class ConfiguredStoryHandlerTest { every { botId } returns PlayerId("botId") every { userId } returns PlayerId("userId") every { userTimeline } returns UserTimeline(userId) - every { applicationId } returns "appId" + every { connectorId } returns "appId" every { currentAnswerIndex } returns 1 every { botDefinition } returns BotDefinitionTest() every { step } returns storyDefinitionConfigurationStep.toStoryStep(configuration) diff --git a/bot/test-base/src/main/kotlin/BotBusMock.kt b/bot/test-base/src/main/kotlin/BotBusMock.kt index 5eb65ecef5..487094cd3b 100644 --- a/bot/test-base/src/main/kotlin/BotBusMock.kt +++ b/bot/test-base/src/main/kotlin/BotBusMock.kt @@ -241,7 +241,7 @@ open class BotBusMock( * The translator used to translate labels - default is NoOp. */ val translator: TranslatorEngine get() = context.testContext.testInjector.provide() - override val applicationId get() = action.applicationId + override val connectorId get() = action.applicationId override val botId get() = action.recipientId override val userId get() = action.playerId override val userPreferences: UserPreferences get() = userTimeline.userPreferences @@ -390,7 +390,7 @@ open class BotBusMock( } fun createBotSentence(plainText: CharSequence?): SendSentence = - SendSentence(botId, applicationId, userId, plainText) + SendSentence(botId, connectorId, userId, plainText) override fun sendRawText(plainText: CharSequence?, delay: Long): BotBus { return answer(createBotSentence(plainText), delay) @@ -401,7 +401,7 @@ open class BotBusMock( // but it invokes the engine with a target connector, // to receive the corresponding messages if(ConnectorType.rest == sourceConnectorType) { - return answer(SendDebug(botId, applicationId, userId, title, data), 0) + return answer(SendDebug(botId, connectorId, userId, title, data), 0) } return this } @@ -437,7 +437,7 @@ open class BotBusMock( connectorId: String, messageProvider: () -> ConnectorMessage ): BotBus { - if (applicationId == connectorId && (targetConnectorType == connectorType || isCompatibleWith(connectorType))) { + if (this.connectorId == connectorId && (targetConnectorType == connectorType || isCompatibleWith(connectorType))) { mockData.addMessage(messageProvider.invoke()) } return this diff --git a/bot/test-base/src/main/kotlin/BotBusMockInitializers.kt b/bot/test-base/src/main/kotlin/BotBusMockInitializers.kt index f3bb804822..bb8d00fffc 100644 --- a/bot/test-base/src/main/kotlin/BotBusMockInitializers.kt +++ b/bot/test-base/src/main/kotlin/BotBusMockInitializers.kt @@ -61,8 +61,8 @@ fun BotDefinition.newBusMockContext( locale: Locale = testContext.defaultLocale(), userId: PlayerId = testContext.defaultPlayerId(), botId: PlayerId = PlayerId("bot", PlayerType.bot), - applicationId: String = this.botId, - action: Action = SendSentence(userId, applicationId, botId, ""), + connectorId: String = this.botId, + action: Action = SendSentence(userId, connectorId, botId, ""), userInterfaceType: UserInterfaceType = UserInterfaceType.textChat, userPreferences: UserPreferences = UserPreferences(locale = locale), secondaryConnectorTypes: List = listOf(), @@ -70,7 +70,7 @@ fun BotDefinition.newBusMockContext( BotBusMockContext( this, story, - applicationId, + connectorId, userId, botId, action, diff --git a/bot/test-base/src/main/kotlin/junit/TockJUnit5ExtensionBase.kt b/bot/test-base/src/main/kotlin/junit/TockJUnit5ExtensionBase.kt index 4d947f9915..c2c4c3ba5d 100644 --- a/bot/test-base/src/main/kotlin/junit/TockJUnit5ExtensionBase.kt +++ b/bot/test-base/src/main/kotlin/junit/TockJUnit5ExtensionBase.kt @@ -71,7 +71,7 @@ open class TockJUnit5ExtensionBase( * @param locale see [BotBusMock.userLocale] * @param userId see [BotBusMock.userId] * @param botId see [BotBusMock.botId] - * @param applicationId see [BotBusMock.applicationId] + * @param connectorId see [BotBusMock.connectorId] * @param userPreferences see [BotBusMock.userPreferences] * @param tests a callback defining the assertions to execute after sending the choice */ @@ -83,7 +83,7 @@ open class TockJUnit5ExtensionBase( locale: Locale = testContext.defaultLocale(), userId: PlayerId = testContext.defaultPlayerId(), botId: PlayerId = PlayerId("bot", PlayerType.bot), - applicationId: String = botDefinition.botId, + connectorId: String = botDefinition.botId, userPreferences: UserPreferences = UserPreferences(locale = locale), tests: BotBusMock.() -> Unit ): BotBusMock { @@ -99,7 +99,7 @@ open class TockJUnit5ExtensionBase( { SendChoice( userId, - applicationId, + connectorId, botId, intent.wrappedIntent().name, parameters.toMap() @@ -119,7 +119,7 @@ open class TockJUnit5ExtensionBase( * @param locale see [BotBusMock.userLocale] * @param userId see [BotBusMock.userId] * @param botId see [BotBusMock.botId] - * @param applicationId see [BotBusMock.applicationId] + * @param connectorId see [BotBusMock.connectorId] * @param userPreferences see [BotBusMock.userPreferences] * @param tests a callback containing the assertions to execute after sending the message */ @@ -131,7 +131,7 @@ open class TockJUnit5ExtensionBase( locale: Locale = testContext.defaultLocale(), userId: PlayerId = testContext.defaultPlayerId(), botId: PlayerId = PlayerId("bot", PlayerType.bot), - applicationId: String = botDefinition.botId, + connectorId: String = botDefinition.botId, userPreferences: UserPreferences = UserPreferences(locale = locale), tests: BotBusMock.() -> Unit ): BotBusMock { @@ -144,7 +144,7 @@ open class TockJUnit5ExtensionBase( botId, userPreferences, listOf(), - { message.toAction(userId, applicationId, botId) }, + { message.toAction(userId, connectorId, botId) }, tests ) } @@ -191,7 +191,7 @@ open class TockJUnit5ExtensionBase( * @param locale see [BotBusMock.userLocale] * @param userId see [BotBusMock.userId] * @param botId see [BotBusMock.botId] - * @param applicationId see [BotBusMock.applicationId] + * @param connectorId see [BotBusMock.connectorId] * @param userPreferences see [BotBusMock.userPreferences] * @param tests a callback containing the assertions to execute after sending the text */ @@ -204,7 +204,7 @@ open class TockJUnit5ExtensionBase( locale: Locale = testContext.defaultLocale(), userId: PlayerId = testContext.defaultPlayerId(), botId: PlayerId = PlayerId("bot", PlayerType.bot), - applicationId: String = botDefinition.botId, + connectorId: String = botDefinition.botId, userPreferences: UserPreferences = UserPreferences(locale = locale), secondaryConnectorTypes: List = listOf(), metadata: ActionMetadata = ActionMetadata(), @@ -222,7 +222,7 @@ open class TockJUnit5ExtensionBase( { SendSentence( userId, - applicationId, + connectorId, botId, text, state = EventState( @@ -257,12 +257,12 @@ open class TockJUnit5ExtensionBase( testContext.botBusMockContext } else { newBusMockContext( - findStoryDefinition(intent, action.applicationId), + findStoryDefinition(intent, action.connectorId), connectorType, locale, userId, botId, - action.applicationId, + action.connectorId, action, userInterfaceType, userPreferences, @@ -285,7 +285,7 @@ open class TockJUnit5ExtensionBase( * @param locale see [BotBusMock.userLocale] * @param userId see [BotBusMock.userId] * @param botId see [BotBusMock.botId] - * @param applicationId see [BotBusMock.applicationId] + * @param connectorId see [BotBusMock.connectorId] * @param userPreferences see [BotBusMock.userPreferences] * @param tests a callback containing the test code to execute in the context of the newly setup [BotBusMock] */ @@ -297,7 +297,7 @@ open class TockJUnit5ExtensionBase( locale: Locale = testContext.defaultLocale(), userId: PlayerId = testContext.defaultPlayerId(), botId: PlayerId = PlayerId("bot", PlayerType.bot), - applicationId: String = botDefinition.botId, + connectorId: String = botDefinition.botId, userPreferences: UserPreferences = UserPreferences(locale = locale), tests: BotBusMock.() -> Unit ) { @@ -312,7 +312,7 @@ open class TockJUnit5ExtensionBase( { SendChoice( userId, - applicationId, + connectorId, botId, intent.wrappedIntent().name, parameters.toMap() @@ -334,7 +334,7 @@ open class TockJUnit5ExtensionBase( locale: Locale = testContext.defaultLocale(), userId: PlayerId = testContext.defaultPlayerId(), botId: PlayerId = PlayerId("bot", PlayerType.bot), - applicationId: String = botDefinition.botId, + connectorId: String = botDefinition.botId, userPreferences: UserPreferences = UserPreferences(locale = locale), tests: BotBusMock.() -> Unit ) { @@ -349,7 +349,7 @@ open class TockJUnit5ExtensionBase( { SendSentence( userId, - applicationId, + connectorId, botId, text, state = EventState( @@ -383,12 +383,12 @@ open class TockJUnit5ExtensionBase( testContext.botBusMockContext } else { newBusMockContext( - findStoryDefinition(intent, action.applicationId), + findStoryDefinition(intent, action.connectorId), connectorType, locale, userId, botId, - action.applicationId, + action.connectorId, action, userInterfaceType, userPreferences @@ -399,7 +399,7 @@ open class TockJUnit5ExtensionBase( ) } - private fun findStoryDefinition(intent: IntentAware, applicationId: String): StoryDefinition = + private fun findStoryDefinition(intent: IntentAware, connectorId: String): StoryDefinition = if (intent is StoryDefinition) { intent } else { @@ -408,7 +408,7 @@ open class TockJUnit5ExtensionBase( ) { testContext.defaultStoryDefinition(botDefinition) } else { - botDefinition.findStoryDefinition(intent, applicationId) + botDefinition.findStoryDefinition(intent, connectorId) } } @@ -441,8 +441,8 @@ open class TockJUnit5ExtensionBase( locale: Locale = testContext.defaultLocale(), userId: PlayerId = testContext.defaultPlayerId(), botId: PlayerId = PlayerId("bot", PlayerType.bot), - applicationId: String = botDefinition.botId, - action: Action = SendSentence(userId, applicationId, botId, ""), + connectorId: String = botDefinition.botId, + action: Action = SendSentence(userId, connectorId, botId, ""), userInterfaceType: UserInterfaceType = UserInterfaceType.textChat, userPreferences: UserPreferences = UserPreferences(locale = locale), secondaryConnectorTypes: List = listOf(), @@ -454,7 +454,7 @@ open class TockJUnit5ExtensionBase( locale, userId, botId, - applicationId, + connectorId, action, userInterfaceType, userPreferences, diff --git a/bot/test-base/src/main/kotlin/mock/BotBusMocked.kt b/bot/test-base/src/main/kotlin/mock/BotBusMocked.kt index ae3e0d17e9..a6722a06ea 100644 --- a/bot/test-base/src/main/kotlin/mock/BotBusMocked.kt +++ b/bot/test-base/src/main/kotlin/mock/BotBusMocked.kt @@ -155,7 +155,7 @@ fun provideMockedBusCommon(bus: BotBus = mockk()): BotBus { every { bus.userId } returns playerId val botId = PlayerId("bot") every { bus.botId } returns botId - every { bus.applicationId } returns "appId" + every { bus.connectorId } returns "appId" val userTimeline: UserTimeline = mockk() val userState = UserState(Instant.now()) @@ -193,7 +193,7 @@ fun provideMockedBusCommon(bus: BotBus = mockk()): BotBus { (args[3] as? Map) ?: emptyMap(), null, null, - bus.applicationId + bus.connectorId ) } every { @@ -206,7 +206,7 @@ fun provideMockedBusCommon(bus: BotBus = mockk()): BotBus { (args[3] as? Map) ?: emptyMap(), null, null, - bus.applicationId + bus.connectorId ) } val state = mockk(relaxed = true)