From 757cba57a8ceb787c2215328e2bdbf58184a3025 Mon Sep 17 00:00:00 2001 From: "r.kulbaev" Date: Wed, 16 Oct 2024 17:53:18 +0300 Subject: [PATCH 1/2] add list params to setAsrProperties --- .../jaicp/reactions/TelephonyReactions.kt | 4 +- .../handlers/SetAsrPropertiesHandler.kt | 11 +++- .../jaicp/config/ProviderConfigTest.kt | 13 +++++ .../src/test/resources/config/003/req.json | 44 ++++++++++++++ .../src/test/resources/config/003/resp.json | 57 +++++++++++++++++++ 5 files changed, 125 insertions(+), 4 deletions(-) create mode 100644 channels/jaicp/src/test/resources/config/003/req.json create mode 100644 channels/jaicp/src/test/resources/config/003/resp.json diff --git a/channels/jaicp/src/main/kotlin/com/justai/jaicf/channel/jaicp/reactions/TelephonyReactions.kt b/channels/jaicp/src/main/kotlin/com/justai/jaicf/channel/jaicp/reactions/TelephonyReactions.kt index e6365de5..0a217474 100755 --- a/channels/jaicp/src/main/kotlin/com/justai/jaicf/channel/jaicp/reactions/TelephonyReactions.kt +++ b/channels/jaicp/src/main/kotlin/com/justai/jaicf/channel/jaicp/reactions/TelephonyReactions.kt @@ -229,9 +229,9 @@ class TelephonyReactions(private val bargeInDefaultProps: BargeInProperties) : J * } * } * ``` - * @param properties map of properties names with its assigned values. + * @param properties map of properties names with its assigned values (String or List). * */ - fun setAsrProperties(properties: Map) { + fun setAsrProperties(properties: Map) { asrConfig = setAsrPropertiesHandler.handle( properties, mergeAsrConfigs(asrConfig, (executionContext.request as TelephonyBotRequest).asrConfig) diff --git a/channels/jaicp/src/main/kotlin/com/justai/jaicf/channel/jaicp/reactions/handlers/SetAsrPropertiesHandler.kt b/channels/jaicp/src/main/kotlin/com/justai/jaicf/channel/jaicp/reactions/handlers/SetAsrPropertiesHandler.kt index b5f73ecf..001e726e 100644 --- a/channels/jaicp/src/main/kotlin/com/justai/jaicf/channel/jaicp/reactions/handlers/SetAsrPropertiesHandler.kt +++ b/channels/jaicp/src/main/kotlin/com/justai/jaicf/channel/jaicp/reactions/handlers/SetAsrPropertiesHandler.kt @@ -1,6 +1,7 @@ package com.justai.jaicf.channel.jaicp.reactions.handlers import com.justai.jaicf.channel.jaicp.dto.config.* +import kotlinx.serialization.json.JsonArray import kotlinx.serialization.json.JsonObject import kotlinx.serialization.json.JsonPrimitive @@ -8,8 +9,14 @@ class SetAsrPropertiesHandler( private val listOfActualHandlers: List ) { - fun handle(properties: Map, asrConfig: AsrConfig): AsrConfig { - val propertiesJson = JsonObject(properties.toMutableMap().mapValues { entry -> JsonPrimitive(entry.value) }) + fun handle(properties: Map, asrConfig: AsrConfig): AsrConfig { + val propertiesJson = JsonObject(properties.mapValues { entry -> + when (val value = entry.value) { + is List<*> -> JsonArray(value.map { JsonPrimitive(it.toString()) }) + is String -> JsonPrimitive(value) + else -> throw IllegalArgumentException("Unsupported property type: ${value::class.simpleName}") + } + }) return listOfActualHandlers.first { it.canHandle(checkNotNull(asrConfig.type)) } .handle(asrConfig, propertiesJson) } diff --git a/channels/jaicp/src/test/kotlin/com/justai/jaicf/channel/jaicp/config/ProviderConfigTest.kt b/channels/jaicp/src/test/kotlin/com/justai/jaicf/channel/jaicp/config/ProviderConfigTest.kt index 93c919e3..394a12ab 100644 --- a/channels/jaicp/src/test/kotlin/com/justai/jaicf/channel/jaicp/config/ProviderConfigTest.kt +++ b/channels/jaicp/src/test/kotlin/com/justai/jaicf/channel/jaicp/config/ProviderConfigTest.kt @@ -38,4 +38,17 @@ internal class ProviderConfigTest : JaicpBaseTest() { val response = channel.process(requestFromResources) assertEquals(responseFromResources, response.jaicp) } + + @Test + fun `003 config asr properties`() { + val scenario = echoWithAction { + reactions.telephony?.setAsrProperties(mapOf( + "hints.eou_timeout" to "4s", + "insight_models" to listOf("call_features") + )) + } + val channel = JaicpTestChannel(scenario, TelephonyChannel) + val response = channel.process(requestFromResources) + assertEquals(responseFromResources, response.jaicp) + } } \ No newline at end of file diff --git a/channels/jaicp/src/test/resources/config/003/req.json b/channels/jaicp/src/test/resources/config/003/req.json new file mode 100644 index 00000000..4fd6cefe --- /dev/null +++ b/channels/jaicp/src/test/resources/config/003/req.json @@ -0,0 +1,44 @@ +{ + "data": { + "livechatStatus": { + "enabled": false + } + }, + "version": 1, + "botId": "jaicf_project", + "channelType": "resterisk", + "channelBotId": "jaicf_project", + "channelUserId": "chatapi-jaicf_project-puga", + "questionId": "aaa99bea-aae1-41d2-aede-76e4f13b0ccc", + "query": "/start", + "timestamp": 1583767519.497000000, + "rawRequest": { + "token": "GNVXJdeo:718e36f7005fbba3e2a9696784b83dc3bd0f3d9a", + "clientId": "test", + "questionId": "aaa99bea-aae1-41d2-aede-76e4f13b0ccc", + "query": "/start", + "timestamp": "2020-03-09T15:25:19.497", + "userId": "puga", + "asrTtsProviderData": { + "asr": { + "type": "sber", + "internal": true, + "sber": { + "model": "callcenter", + "language": "ru-RU" + } + }, + "tts": { + "type": "aimyvoice", + "internal": true, + "aimyvoice": { + "voice": "Татьяна" + } + } + } + }, + "userFrom": { + "id": "test", + "firstName": "test" + } +} \ No newline at end of file diff --git a/channels/jaicp/src/test/resources/config/003/resp.json b/channels/jaicp/src/test/resources/config/003/resp.json new file mode 100644 index 00000000..0622b47f --- /dev/null +++ b/channels/jaicp/src/test/resources/config/003/resp.json @@ -0,0 +1,57 @@ +{ + "data": { + "replies": [], + "answer": "", + "dialer": {}, + "asrConfig": { + "type": "sber", + "sber": { + "language": "ru-RU", + "model": "callcenter", + "asrProperties": { + "hints.eou_timeout": "4s", + "insight_models": ["call_features"] + } + }, + "asrProperties": { + "hints.eou_timeout": "4s", + "insight_models": ["call_features"] + } + } + }, + "botId": "jaicf_project", + "accountId": "jaicf_project", + "channelType": "resterisk", + "channelBotId": "jaicf_project", + "channelUserId": "chatapi-jaicf_project-puga", + "questionId": "aaa99bea-aae1-41d2-aede-76e4f13b0ccc", + "query": "/start", + "timestamp": 0, + "currentState": "/fallback", + "processingTime": 0, + "requestData": { + "token": "GNVXJdeo:718e36f7005fbba3e2a9696784b83dc3bd0f3d9a", + "clientId": "test", + "questionId": "aaa99bea-aae1-41d2-aede-76e4f13b0ccc", + "query": "/start", + "timestamp": "2020-03-09T15:25:19.497", + "userId": "puga", + "asrTtsProviderData": { + "asr": { + "type": "sber", + "internal": true, + "sber": { + "model": "callcenter", + "language": "ru-RU" + } + }, + "tts": { + "type": "aimyvoice", + "internal": true, + "aimyvoice": { + "voice": "Татьяна" + } + } + } + } +} \ No newline at end of file From 01976e59b04abd4a63fc6b646744098855100a0b Mon Sep 17 00:00:00 2001 From: "r.kulbaev" Date: Mon, 21 Oct 2024 14:56:27 +0300 Subject: [PATCH 2/2] add collection and map params to setAsrProperties --- .../jaicf/channel/jaicp/reactions/TelephonyReactions.kt | 2 +- .../jaicp/reactions/handlers/SetAsrPropertiesHandler.kt | 3 ++- .../justai/jaicf/channel/jaicp/config/ProviderConfigTest.kt | 3 ++- channels/jaicp/src/test/resources/config/003/resp.json | 6 ++++-- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/channels/jaicp/src/main/kotlin/com/justai/jaicf/channel/jaicp/reactions/TelephonyReactions.kt b/channels/jaicp/src/main/kotlin/com/justai/jaicf/channel/jaicp/reactions/TelephonyReactions.kt index 0a217474..9bc434a8 100755 --- a/channels/jaicp/src/main/kotlin/com/justai/jaicf/channel/jaicp/reactions/TelephonyReactions.kt +++ b/channels/jaicp/src/main/kotlin/com/justai/jaicf/channel/jaicp/reactions/TelephonyReactions.kt @@ -229,7 +229,7 @@ class TelephonyReactions(private val bargeInDefaultProps: BargeInProperties) : J * } * } * ``` - * @param properties map of properties names with its assigned values (String or List). + * @param properties map of properties names with its assigned values (String/Collection/Map). * */ fun setAsrProperties(properties: Map) { asrConfig = setAsrPropertiesHandler.handle( diff --git a/channels/jaicp/src/main/kotlin/com/justai/jaicf/channel/jaicp/reactions/handlers/SetAsrPropertiesHandler.kt b/channels/jaicp/src/main/kotlin/com/justai/jaicf/channel/jaicp/reactions/handlers/SetAsrPropertiesHandler.kt index 001e726e..12159d08 100644 --- a/channels/jaicp/src/main/kotlin/com/justai/jaicf/channel/jaicp/reactions/handlers/SetAsrPropertiesHandler.kt +++ b/channels/jaicp/src/main/kotlin/com/justai/jaicf/channel/jaicp/reactions/handlers/SetAsrPropertiesHandler.kt @@ -12,8 +12,9 @@ class SetAsrPropertiesHandler( fun handle(properties: Map, asrConfig: AsrConfig): AsrConfig { val propertiesJson = JsonObject(properties.mapValues { entry -> when (val value = entry.value) { - is List<*> -> JsonArray(value.map { JsonPrimitive(it.toString()) }) + is Collection<*> -> JsonArray(value.map { JsonPrimitive(it.toString()) }) is String -> JsonPrimitive(value) + is Map<*,*> -> JsonObject(value.mapKeys { it.key.toString() }.mapValues { JsonPrimitive(it.value.toString()) }) else -> throw IllegalArgumentException("Unsupported property type: ${value::class.simpleName}") } }) diff --git a/channels/jaicp/src/test/kotlin/com/justai/jaicf/channel/jaicp/config/ProviderConfigTest.kt b/channels/jaicp/src/test/kotlin/com/justai/jaicf/channel/jaicp/config/ProviderConfigTest.kt index 394a12ab..198a3fc6 100644 --- a/channels/jaicp/src/test/kotlin/com/justai/jaicf/channel/jaicp/config/ProviderConfigTest.kt +++ b/channels/jaicp/src/test/kotlin/com/justai/jaicf/channel/jaicp/config/ProviderConfigTest.kt @@ -44,7 +44,8 @@ internal class ProviderConfigTest : JaicpBaseTest() { val scenario = echoWithAction { reactions.telephony?.setAsrProperties(mapOf( "hints.eou_timeout" to "4s", - "insight_models" to listOf("call_features") + "insight_models" to listOf("call_features"), + "time" to mapOf(("now" to "21:00")) )) } val channel = JaicpTestChannel(scenario, TelephonyChannel) diff --git a/channels/jaicp/src/test/resources/config/003/resp.json b/channels/jaicp/src/test/resources/config/003/resp.json index 0622b47f..1b703d19 100644 --- a/channels/jaicp/src/test/resources/config/003/resp.json +++ b/channels/jaicp/src/test/resources/config/003/resp.json @@ -10,12 +10,14 @@ "model": "callcenter", "asrProperties": { "hints.eou_timeout": "4s", - "insight_models": ["call_features"] + "insight_models": ["call_features"], + "time":{"now":"21:00"} } }, "asrProperties": { "hints.eou_timeout": "4s", - "insight_models": ["call_features"] + "insight_models": ["call_features"], + "time":{"now":"21:00"} } } },