Skip to content
Open
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
12 changes: 8 additions & 4 deletions bot/admin/server/src/main/kotlin/verticle/DialogVerticle.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import ai.tock.bot.admin.annotation.BotAnnotationDTO
import ai.tock.bot.admin.annotation.BotAnnotationEventDTO
import ai.tock.bot.admin.annotation.BotAnnotationEventType
import ai.tock.bot.admin.dialog.DialogStatsQuery
import ai.tock.bot.admin.dialog.DialogWithNlpStats
import ai.tock.bot.admin.model.DialogsSearchQuery
import ai.tock.bot.engine.message.Sentence
import ai.tock.nlp.admin.CsvCodec
Expand Down Expand Up @@ -145,13 +146,16 @@ class DialogVerticle {
blockingJsonGet(PATH_DIALOG, setOf(TockUserRole.botUser)) { context ->
val app = FrontClient.getApplicationById(context.pathId("applicationId"))
if (context.organization == app?.namespace) {
BotAdminService.getDialogWithCommentRights(
val dialog = BotAdminService.getDialogWithCommentRights(
context.path("dialogId").toId(),
context.userLogin
)
} else {
unauthorized()
}
dialog?.let {
val stats = BotAdminService.dialogReportDAO
.getNlpStats(listOf(it.id), app.namespace)
DialogWithNlpStats(it, stats)
}
} else unauthorized()
}

blockingJsonPost(PATH_DIALOG_SATISFACTION, setOf(TockUserRole.botUser)) { context, query: Set<String> ->
Expand Down
6 changes: 4 additions & 2 deletions bot/admin/web/src/app/analytics/dialog/dialog.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { ApplicationService } from '../../core-nlp/applications.service';
import { AuthService } from '../../core-nlp/auth/auth.service';
import { SettingsService } from '../../core-nlp/settings.service';
import { copyToClipboard } from '../../shared/utils';
import {BotSharedService} from "../../shared/bot-shared.service";

@Component({
selector: 'tock-dialog',
Expand All @@ -46,6 +47,7 @@ export class DialogComponent implements OnInit, OnDestroy {
private applicationService: ApplicationService,
public auth: AuthService,
public settings: SettingsService,
private botSharedService: BotSharedService,
private router: Router
) {}

Expand Down Expand Up @@ -100,8 +102,8 @@ export class DialogComponent implements OnInit, OnDestroy {
return;
}

this.analytics
.dialog(this.state.currentApplication._id, routeParams.dialogId)
this.botSharedService
.getDialogWithNlpStats(this.state.currentApplication._id, routeParams.dialogId)
.pipe(take(1))
.subscribe((dialog) => {
if (dialog?.actions?.length) {
Expand Down
18 changes: 17 additions & 1 deletion bot/admin/web/src/app/shared/bot-shared.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { Injectable } from '@angular/core';
import { RestService } from '../core-nlp/rest/rest.service';
import { Observable, of } from 'rxjs';
import { ConnectorType, ConnectorTypeConfiguration } from '../core/model/configuration';
import { NlpCallStats } from './model/dialog-data';
import {ActionNlpStats, DialogReport, NlpCallStats} from './model/dialog-data';
import { AdminConfiguration } from './model/conf';

export interface TockSimpleSessionStorage {
Expand Down Expand Up @@ -79,6 +79,22 @@ export class BotSharedService {
}
}

getDialogWithNlpStats(applicationId: string, dialogId: string): Observable<DialogReport> {
return this.rest.get(`/dialog/${applicationId}/${dialogId}`, (json: any) => {
const dialog = DialogReport.fromJSON(json.dialog);
const nlpStats: ActionNlpStats[] = json.nlpStats || [];

dialog.actions.forEach((action) => {
const actionNlpStats = nlpStats.find((ns) => ns.actionId === action.id);
if (actionNlpStats) {
action._nlpStats = actionNlpStats.stats;
}
});

return dialog;
});
}

set session_storage(value: TockSimpleSessionStorage) {
sessionStorage.setItem('TockSimpleSessionStorage', JSON.stringify(value));
}
Expand Down
24 changes: 24 additions & 0 deletions bot/engine/src/main/kotlin/admin/dialog/DialogWithNlpStats.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright (C) 2017/2025 SNCF Connect & Tech
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package ai.tock.bot.admin.dialog

import ai.tock.bot.engine.nlp.NlpStats

data class DialogWithNlpStats(
val dialog: DialogReport,
val nlpStats: List<NlpStats>
)
2 changes: 1 addition & 1 deletion shared/src/main/kotlin/vertx/WebVerticle.kt
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ abstract class WebVerticle : AbstractVerticle() {
) {
router.route(method, "$basePath$path")
.handler { context ->
val u: TockUser? = context.user() as? TockUser ?: context.session().get("tockUser") as? TockUser
val u: TockUser? = context.user() as? TockUser ?: context.session()?.get("tockUser") as? TockUser
if (u == null || roles.isNullOrEmpty()) {
handler.invoke(context)
} else {
Expand Down