theopenconversationkit / tock

Tock, the open source conversational AI toolkit.
https://doc.tock.ai
Apache License 2.0
466 stars 126 forks source link

[Bot API] Locale cannot be updated from within a story handler #1662

Closed Fabilin closed 2 days ago

Fabilin commented 3 days ago

A somewhat common request in a multilingual bot is for the bot to "switch language", where the user expects the bot to start talking in the language of their choice. As far as I know, the typical way to perform this operation is to set the user's locale as follows:

userTimeline.userPreferences.locale = locale

However this change is only taken into account the next time a TockBotBus is created, which means the answer to the "switch language" intent is improperly translated:

image

A simple fix for this would be to make the BotBus#userLocale field mutable, and add a way to simultaneously set the locale in both the bus and the UserPreferences.

vsct-jburet commented 3 days ago

why not using bus#userPreferences.locale ? Is this solving the issue ?

vsct-jburet commented 3 days ago

I would say that the best fix would be to change in TockBotBus

override val userLocale: Locale =

by

override val userLocale: Locale get() =

This is already done in BotBusMock, and I think perf cost is ok