Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Documentation/implementation-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ Brand Concierge expects the following keys to be present in the Configuration sh

- **`concierge.server`**: String (server host or base domain used by Brand Concierge requests)
- **`concierge.configId`**: String (datastream ID)
- **`concierge.region`**: String, optional (region identifier, e.g. `va6`, inserted into the Brand Concierge request path; omit to use the default unqualified endpoint)

ECID is read from Edge Identity shared state.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ object ConciergeConstants {
const val EXTENSION_NAME = "com.adobe.module.configuration"
const val CONCIERGE_SERVER = "concierge.server"
const val CONCIERGE_CONFIG_ID = "concierge.configId"
const val CONCIERGE_REGION = "concierge.region"
}
object Consent {
const val EXTENSION_NAME = "com.adobe.edge.consent"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import kotlinx.coroutines.flow.update
* @property surfaces List of surface URLs set via the [ConciergeChat] surfaces parameter.
* @property conciergeServer Server URL from concierge.server configuration.
* @property conciergeConfigId Configuration ID from concierge.configId configuration.
* @property conciergeRegion Region from concierge.region configuration. Null when not configured.
* @property consent Consent value from the Consent extension. Default is "in".
*/
internal data class ConciergeState(
Expand All @@ -39,6 +40,7 @@ internal data class ConciergeState(
val surfaces: List<String> = emptyList(),
val conciergeServer: String? = null,
val conciergeConfigId: String? = null,
val conciergeRegion: String? = null,
val consent: String? = ConciergeConstants.ConsentValues.DEFAULT_VALUE
)

Expand Down Expand Up @@ -143,7 +145,8 @@ internal class ConciergeStateRepository internal constructor(
it.copy(
configurationReady = false,
conciergeServer = "",
conciergeConfigId = ""
conciergeConfigId = "",
conciergeRegion = null
)
}

Expand Down Expand Up @@ -176,18 +179,28 @@ internal class ConciergeStateRepository internal constructor(
?.takeIf { it.isNotEmpty() }
}

val region: String? = configMap?.let { map ->
DataReader.optString(
map,
ConciergeConstants.SharedState.Configuration.CONCIERGE_REGION,
null
)
?.takeIf { it.isNotEmpty() }
}

_state.update {
it.copy(
configurationReady = true,
conciergeServer = server,
conciergeConfigId = configId
conciergeConfigId = configId,
conciergeRegion = region
)
}

Log.debug(
ConciergeConstants.EXTENSION_NAME,
LOG_TAG,
"Updated ConciergeState with configId: $configId, server: $server"
"Updated ConciergeState with configId: $configId, server: $server, region: $region"
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ internal class ConciergeConversationServiceClient(
get() {
val currentState = conciergeState.value
val sessionId = sessionManager.getSessionId()
return "https://${currentState.conciergeServer}/brand-concierge/conversations" +
val regionSegment = currentState.conciergeRegion?.let { "/$it" }.orEmpty()
return "https://${currentState.conciergeServer}/brand-concierge$regionSegment/conversations" +
"?configId=${currentState.conciergeConfigId}" +
"&sessionId=$sessionId" +
"&requestId=${UUID.randomUUID()}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,42 @@ class ConciergeStateRepositoryTest {
assertTrue(state.configurationReady)
assertEquals("test-server.com", state.conciergeServer)
assertEquals("test-config-123", state.conciergeConfigId)
assertNull(state.conciergeRegion)
}

@Test
fun `updateConfiguration sets region when present in config`() = runTest {
val configMap = mapOf<String?, Any?>(
"concierge.server" to "test-server.com",
"concierge.configId" to "test-config-123",
"concierge.region" to "va6"
)

val sharedStateResult = mockk<SharedStateResult>()
every { sharedStateResult.value } returns configMap

repository.updateConfiguration(sharedStateResult)

val state = repository.state.first()
assertTrue(state.configurationReady)
assertEquals("va6", state.conciergeRegion)
}

@Test
fun `updateConfiguration treats empty region string as absent`() = runTest {
val configMap = mapOf<String?, Any?>(
"concierge.server" to "test-server.com",
"concierge.configId" to "test-config-123",
"concierge.region" to ""
)

val sharedStateResult = mockk<SharedStateResult>()
every { sharedStateResult.value } returns configMap

repository.updateConfiguration(sharedStateResult)

val state = repository.state.first()
assertNull(state.conciergeRegion)
}

@Test
Expand All @@ -186,6 +222,7 @@ class ConciergeStateRepositoryTest {
assertFalse(state.configurationReady)
assertEquals("", state.conciergeServer)
assertEquals("", state.conciergeConfigId)
assertNull(state.conciergeRegion)
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1049,6 +1049,45 @@ class ConciergeConversationServiceClientTest {
assertTrue(url.contains("requestId="))
}

@Test
fun `endpoint includes region segment when region is configured`() = runTest {
val requestSlot = slot<NetworkRequest>()
val connection = mockk<HttpConnecting>(relaxed = true)
every { connection.responseCode } returns 200
every { connection.inputStream } returns ByteArrayInputStream(ByteArray(0))
every { networkService.connectAsync(capture(requestSlot), any()) } answers {
val cb = secondArg<NetworkCallback>()
cb.call(connection)
}

val stateWithRegion = testState.copy(conciergeRegion = "va6")
every { mockStateRepository.state } returns MutableStateFlow(stateWithRegion)

val client = ConciergeConversationServiceClient(mockStateRepository, mockSessionManager)
client.chat("test").toList()

val url = requestSlot.captured.url
assertTrue(url.startsWith("https://https://test-server.com/brand-concierge/va6/conversations"))
}

@Test
fun `endpoint omits region segment when region is not configured`() = runTest {
val requestSlot = slot<NetworkRequest>()
val connection = mockk<HttpConnecting>(relaxed = true)
every { connection.responseCode } returns 200
every { connection.inputStream } returns ByteArrayInputStream(ByteArray(0))
every { networkService.connectAsync(capture(requestSlot), any()) } answers {
val cb = secondArg<NetworkCallback>()
cb.call(connection)
}

val client = ConciergeConversationServiceClient(mockStateRepository, mockSessionManager)
client.chat("test").toList()

val url = requestSlot.captured.url
assertTrue(url.startsWith("https://https://test-server.com/brand-concierge/conversations"))
}

@Test
fun `multiple sequential chat calls work correctly`() = runTest {
val json = """
Expand Down
Loading