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

Feature/set asr properties #263

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open

Conversation

Yamakuprina
Copy link
Contributor

No description provided.

@Yamakuprina Yamakuprina self-assigned this May 17, 2024
@Yamakuprina
Copy link
Contributor Author

Изменения позволят использовать данный функционал JAICP:
https://help.cloud.just-ai.com/jaicp/JS_API/built_in_services/dialer/setAsrProperty/

fun setAsrProperties(properties: Map<String, String>) {
val propertiesJson = JsonObject(properties.toMutableMap().mapValues { entry -> JsonPrimitive(entry.value) })
asrConfig = (executionContext.request as TelephonyBotRequest).asrConfig
when (checkNotNull(asrConfig?.type)) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Это копипаст с JAICP?
Так-то просится ввернуть какую-нибудь chain of responsibility или иным образом инкапсулировать логику выбора конфига.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Частично копипаст с JAICP, да. Вынести логику выбора конфига можно в другое место, но вроде особо некуда

fun handle(properties: Map<String, String>, asrConfig: AsrConfig): AsrConfig {
val propertiesJson = JsonObject(properties.toMutableMap().mapValues { entry -> JsonPrimitive(entry.value) })
return when (checkNotNull(asrConfig.type)) {
AsrConfig.AsrProviderType.SBER -> {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Главная идея - избавиться от этого when.

Условно нужно несколько моментов:

  1. Вынести конфигурацию списка хендлеров вне этого класса, т.е. будет что-то вида SetAsrPropertiesHandler(listOfActualHandlers)
  2. Сделать общий интерфейс хендлера с методами canHandle(...) и handle(...)
  3. Центральный хендлер (этот класс) делегирует canHandle() и handle() в лежащие внутри него хендлеры - кто первый ответит, что может захендлить, тот и хендлит.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Реализовал как описано выше

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants