Skip to content

Commit 9ba365f

Browse files
committed
[DERCBOT-1755] KPI Satisfaction
[DERCBOT-1752] Add feedback dialog filter
1 parent 2241a15 commit 9ba365f

File tree

18 files changed

+235
-8
lines changed

18 files changed

+235
-8
lines changed

bot/admin/server/src/main/kotlin/BotAdminService.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,8 @@ object BotAdminService {
624624
val knownIntentUserActionsGroup = groupByAppConfigType(stats.knownIntentUserActions)
625625
val unknownIntentUserActionsGroup = groupByAppConfigType(stats.unknownIntentUserActions)
626626
val unknownIntentUserActionsExceptRagGroup = groupByAppConfigType(stats.unknownIntentUserActionsExceptRag)
627+
val allFeedbackUp = groupByAppConfigType(stats.allFeedbackUp)
628+
val allFeedbackDown = groupByAppConfigType(stats.allFeedbackDown)
627629

628630
fun buildResult(env: String) =
629631
DialogStatsQueryResult(
@@ -633,6 +635,8 @@ object BotAdminService {
633635
knownIntentUserActions = knownIntentUserActionsGroup[env] ?: emptyList(),
634636
unknownIntentUserActions = unknownIntentUserActionsGroup[env] ?: emptyList(),
635637
unknownIntentUserActionsExceptRag = unknownIntentUserActionsExceptRagGroup[env] ?: emptyList(),
638+
allFeedbackUp = allFeedbackUp[env] ?: emptyList(),
639+
allFeedbackDown = allFeedbackDown[env] ?: emptyList(),
636640
)
637641

638642
return DialogStatsGroupResponse(

bot/admin/server/src/main/kotlin/model/DialogsSearchQuery.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import ai.tock.bot.admin.annotation.BotAnnotationReasonType
2020
import ai.tock.bot.admin.annotation.BotAnnotationState
2121
import ai.tock.bot.admin.dialog.DialogReportQuery
2222
import ai.tock.bot.connector.ConnectorType
23+
import ai.tock.bot.engine.action.FeedbackVote
2324
import ai.tock.bot.engine.dialog.SortDirection
2425
import ai.tock.bot.engine.user.PlayerId
2526
import ai.tock.nlp.admin.model.PaginatedQuery
@@ -50,6 +51,7 @@ data class DialogsSearchQuery(
5051
val annotationCreationDateTo: ZonedDateTime? = null,
5152
val dialogCreationDateFrom: ZonedDateTime? = null,
5253
val dialogCreationDateTo: ZonedDateTime? = null,
54+
val feedback: FeedbackVote? = null,
5355
) : PaginatedQuery() {
5456
fun toDialogReportQuery(): DialogReportQuery {
5557
return DialogReportQuery(
@@ -79,6 +81,7 @@ data class DialogsSearchQuery(
7981
annotationCreationDateTo = annotationCreationDateTo,
8082
dialogCreationDateFrom = dialogCreationDateFrom,
8183
dialogCreationDateTo = dialogCreationDateTo,
84+
feedback = feedback,
8285
)
8386
}
8487
}

bot/connector-web-model/src/main/kotlin/ai/tock/bot/connector/web/WebConnectorRequest.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ package ai.tock.bot.connector.web
1818

1919
import java.util.Locale
2020

21+
data class FeedbackParams(
22+
val actionId: String,
23+
val vote: String? = null,
24+
)
25+
2126
interface WebConnectorRequestContract {
2227
val query: String?
2328
val payload: String?
@@ -28,6 +33,7 @@ interface WebConnectorRequestContract {
2833
val returnsHistory: Boolean get() = false
2934
val sourceWithContent: Boolean get() = false
3035
val streamedResponse: Boolean get() = false
36+
val feedback: FeedbackParams?
3137
}
3238

3339
data class WebConnectorRequestContent(
@@ -40,4 +46,5 @@ data class WebConnectorRequestContent(
4046
override val returnsHistory: Boolean = false,
4147
override val sourceWithContent: Boolean = false,
4248
override val streamedResponse: Boolean = false,
49+
override val feedback: FeedbackParams? = null,
4350
) : WebConnectorRequestContract

bot/connector-web-model/src/main/kotlin/ai/tock/bot/connector/web/send/WebMessageContent.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ interface WebMessageContract {
2626
val widget: WebWidget?
2727
val image: WebImage?
2828
val version: String
29+
val actionId: String?
2930
}
3031

3132
data class WebMessageContent(
@@ -38,4 +39,5 @@ data class WebMessageContent(
3839
override val image: WebImage? = null,
3940
override val version: String = "1",
4041
override val footnotes: List<Footnote> = emptyList(),
42+
override val actionId: String? = null,
4143
) : WebMessageContract

bot/connector-web/src/main/kotlin/WebConnectorCallback.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import ai.tock.bot.connector.ConnectorCallbackBase
2020
import ai.tock.bot.connector.web.WebConnector.Companion.sendSseResponse
2121
import ai.tock.bot.engine.action.Action
2222
import ai.tock.bot.engine.action.SendSentence
23+
import ai.tock.bot.engine.event.Event
2324
import ai.tock.bot.engine.event.MetadataEvent
2425
import ai.tock.bot.engine.event.hasStreamMetadata
2526
import ai.tock.shared.booleanProperty
@@ -81,4 +82,9 @@ internal class WebConnectorCallback(
8182
context?.response()
8283
?.sendSseResponse(createResponse(listOf(action)))
8384
}
85+
86+
override fun eventSkipped(event: Event) {
87+
super.eventSkipped(event)
88+
sendResponse()
89+
}
8490
}

bot/connector-web/src/main/kotlin/WebConnectorRequest.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,14 @@
1616

1717
package ai.tock.bot.connector.web
1818

19+
import ai.tock.bot.engine.action.ActionFeedback
1920
import ai.tock.bot.engine.action.ActionMetadata
21+
import ai.tock.bot.engine.action.FeedbackVote
2022
import ai.tock.bot.engine.action.SendChoice
2123
import ai.tock.bot.engine.action.SendChoice.Companion.REFERRAL_PARAMETER
2224
import ai.tock.bot.engine.action.SendSentence
2325
import ai.tock.bot.engine.event.Event
26+
import ai.tock.bot.engine.event.FeedbackEvent
2427
import ai.tock.bot.engine.event.ReferralParametersEvent
2528
import ai.tock.bot.engine.user.PlayerId
2629
import ai.tock.bot.engine.user.PlayerType.bot
@@ -37,6 +40,7 @@ data class WebConnectorRequest(
3740
override val returnsHistory: Boolean = false,
3841
override val sourceWithContent: Boolean = false,
3942
override val streamedResponse: Boolean = false,
43+
override val feedback: FeedbackParams? = null,
4044
) : WebConnectorRequestContract {
4145
fun toEvent(applicationId: String): Event =
4246
if (query != null) {
@@ -52,6 +56,14 @@ data class WebConnectorRequest(
5256
streamedResponse = streamedResponse,
5357
),
5458
)
59+
} else if (feedback != null) {
60+
FeedbackEvent(
61+
userId = PlayerId(userId),
62+
applicationId = applicationId,
63+
recipientId = PlayerId(applicationId, bot),
64+
actionId = feedback.actionId,
65+
feedback = feedback.vote?.let { ActionFeedback(vote = FeedbackVote.valueOf(it)) },
66+
)
5567
} else if (payload != null) {
5668
val (intent, parameters) = SendChoice.decodeChoiceId(payload)
5769
SendChoice(

bot/connector-web/src/main/kotlin/WebMessage.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ data class WebMessage(
4242
override val version: String = "1",
4343
override val deepLink: WebDeepLink? = null,
4444
override val footnotes: List<Footnote> = emptyList(),
45+
override val actionId: String? = null,
4546
) : WebMessageContract, WebConnectorMessage {
4647
constructor(content: WebMessageContent) : this(
4748
content.text,
@@ -53,6 +54,7 @@ data class WebMessage(
5354
content.version,
5455
content.deepLink,
5556
content.footnotes,
57+
content.actionId,
5658
)
5759

5860
@get:JsonIgnore

bot/connector-web/src/main/kotlin/WebMessageProcessor.kt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ internal class WebMessageProcessor(private val processMarkdown: Boolean) {
2828
val stringText = action.stringText
2929

3030
if (stringText != null) {
31-
WebMessage(postProcess(stringText))
31+
WebMessage(text = postProcess(stringText), actionId = action.id.toString())
3232
} else {
33-
postProcess(action.message(webConnectorType) as? WebMessage)
33+
postProcess(action.message(webConnectorType) as? WebMessage, actionId = action.id.toString())
3434
}
3535
}
3636
is SendSentenceWithFootnotes -> {
3737
val stringText = action.text.toString()
3838
WebMessage(
39-
postProcess(stringText),
39+
text = postProcess(stringText),
4040
footnotes =
4141
action.footnotes.map { footnote ->
4242
Footnote(
@@ -47,15 +47,19 @@ internal class WebMessageProcessor(private val processMarkdown: Boolean) {
4747
footnote.score,
4848
)
4949
},
50+
actionId = action.id.toString(),
5051
)
5152
}
5253
else -> null
5354
}
5455
}
5556

56-
private fun postProcess(message: WebMessage?): WebMessage? {
57+
private fun postProcess(
58+
message: WebMessage?,
59+
actionId: String,
60+
): WebMessage? {
5761
if (message?.text != null) {
58-
return message.copy(text = postProcess(message.text))
62+
return message.copy(text = postProcess(message.text), actionId = actionId)
5963
}
6064

6165
return message

bot/engine/src/main/kotlin/admin/dialog/DialogReportQuery.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package ai.tock.bot.admin.dialog
1919
import ai.tock.bot.admin.annotation.BotAnnotationReasonType
2020
import ai.tock.bot.admin.annotation.BotAnnotationState
2121
import ai.tock.bot.connector.ConnectorType
22+
import ai.tock.bot.engine.action.FeedbackVote
2223
import ai.tock.bot.engine.dialog.SortDirection
2324
import ai.tock.bot.engine.user.PlayerId
2425
import java.time.ZonedDateTime
@@ -69,4 +70,5 @@ data class DialogReportQuery(
6970
val annotationCreationDateTo: ZonedDateTime? = null,
7071
val dialogCreationDateFrom: ZonedDateTime? = null,
7172
val dialogCreationDateTo: ZonedDateTime? = null,
73+
val feedback: FeedbackVote? = null,
7274
)

bot/engine/src/main/kotlin/admin/dialog/DialogStatsQueryResult.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,6 @@ data class DialogStatsQueryResult(
4747
val knownIntentUserActions: List<CountResult> = emptyList(),
4848
val unknownIntentUserActions: List<CountResult> = emptyList(),
4949
val unknownIntentUserActionsExceptRag: List<CountResult> = emptyList(),
50+
val allFeedbackUp: List<CountResult> = emptyList(),
51+
val allFeedbackDown: List<CountResult> = emptyList(),
5052
)

0 commit comments

Comments
 (0)