Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add collection and map params to setAsrProperties #267

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
Original file line number Diff line number Diff line change
Expand Up @@ -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/Collection/Map).
* */
fun setAsrProperties(properties: Map<String, String>) {
fun setAsrProperties(properties: Map<String, Any>) {
asrConfig = setAsrPropertiesHandler.handle(
properties,
mergeAsrConfigs(asrConfig, (executionContext.request as TelephonyBotRequest).asrConfig)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
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

class SetAsrPropertiesHandler(
private val listOfActualHandlers: List<SetAsrPropertiesHandlerAbstract>
) {

fun handle(properties: Map<String, String>, asrConfig: AsrConfig): AsrConfig {
val propertiesJson = JsonObject(properties.toMutableMap().mapValues { entry -> JsonPrimitive(entry.value) })
fun handle(properties: Map<String, Any>, asrConfig: AsrConfig): AsrConfig {
val propertiesJson = JsonObject(properties.mapValues { entry ->
when (val value = entry.value) {
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}")
}
})
return listOfActualHandlers.first { it.canHandle(checkNotNull(asrConfig.type)) }
.handle(asrConfig, propertiesJson)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,18 @@ 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"),
"time" to mapOf(("now" to "21:00"))
))
}
val channel = JaicpTestChannel(scenario, TelephonyChannel)
val response = channel.process(requestFromResources)
assertEquals(responseFromResources, response.jaicp)
}
}
44 changes: 44 additions & 0 deletions channels/jaicp/src/test/resources/config/003/req.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
59 changes: 59 additions & 0 deletions channels/jaicp/src/test/resources/config/003/resp.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"data": {
"replies": [],
"answer": "",
"dialer": {},
"asrConfig": {
"type": "sber",
"sber": {
"language": "ru-RU",
"model": "callcenter",
"asrProperties": {
"hints.eou_timeout": "4s",
"insight_models": ["call_features"],
"time":{"now":"21:00"}
}
},
"asrProperties": {
"hints.eou_timeout": "4s",
"insight_models": ["call_features"],
"time":{"now":"21:00"}
}
}
},
"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": "Татьяна"
}
}
}
}
}
Loading