From 19d82a228289be88bb323891641d1ce542f48d45 Mon Sep 17 00:00:00 2001 From: Tagir Fayzullin Date: Wed, 15 May 2024 12:35:39 +0300 Subject: [PATCH] feature: add set asr properties telephony reaction --- .../channel/jaicp/dto/config/AsrConfig.kt | 5 ++++- .../jaicp/reactions/TelephonyReactions.kt | 21 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/channels/jaicp/src/main/kotlin/com/justai/jaicf/channel/jaicp/dto/config/AsrConfig.kt b/channels/jaicp/src/main/kotlin/com/justai/jaicf/channel/jaicp/dto/config/AsrConfig.kt index da49afaa..e997906b 100644 --- a/channels/jaicp/src/main/kotlin/com/justai/jaicf/channel/jaicp/dto/config/AsrConfig.kt +++ b/channels/jaicp/src/main/kotlin/com/justai/jaicf/channel/jaicp/dto/config/AsrConfig.kt @@ -2,6 +2,7 @@ package com.justai.jaicf.channel.jaicp.dto.config import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable +import kotlinx.serialization.json.JsonObject /** * Configuration parameters for the automatic speech recognition (ASR) provider used in a telephone channel. @@ -18,6 +19,7 @@ import kotlinx.serialization.Serializable * @param azure configuration options for the Azure ASR provider, if used. * @param asm configuration options for the ASM ASR provider, if used. * @param sber configuration options for the Sber ASR provider, if used. + * @param asrProperties special properties used with selected ASR, if used. **/ @Serializable data class AsrConfig( @@ -30,7 +32,8 @@ data class AsrConfig( val mts: AsrMtsConfig? = null, val azure: AsrAzureConfig? = null, val asm: AsrAsmConfig? = null, - val sber: AsrSberConfig? = null + val sber: AsrSberConfig? = null, + val asrProperties: JsonObject? = null ) { @Serializable enum class AsrProviderType { 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 276bda16..3b24e7d7 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 @@ -10,6 +10,8 @@ import com.justai.jaicf.logging.SayReaction import com.justai.jaicf.logging.currentState import com.justai.jaicf.plugin.PathValue import com.justai.jaicf.reactions.Reactions +import kotlinx.serialization.json.JsonObject +import kotlinx.serialization.json.JsonPrimitive import java.time.DayOfWeek import java.time.Duration import java.time.Instant @@ -201,6 +203,25 @@ class TelephonyReactions(private val bargeInDefaultProps: BargeInProperties) : J ) } + /** + * This method overrides the ASR properties of the ASR used for the current call. + * example usage: + * ``` + * state("asr") { + * action { + * reactions.telephony?.setAsrProperties( + * mapOf("enable_profanity_filter" to "true") + * ) + * } + * } + * ``` + * @param properties map of properties names with its assigned values. + * */ + fun setAsrProperties(properties: Map) { + val propertiesJson = JsonObject(properties.toMutableMap().mapValues { entry -> JsonPrimitive(entry.value) }) + asrConfig = asrConfig?.copy(asrProperties = propertiesJson) + } + /** * Schedules a redial in outbound call campaign. *