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

Track unhandled events in dialog container #2645

Merged
merged 5 commits into from
Aug 7, 2020
Merged
Show file tree
Hide file tree
Changes from 4 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
24 changes: 22 additions & 2 deletions libraries/botbuilder-dialogs/src/dialogContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
import { BotTelemetryClient, NullTelemetryClient } from 'botbuilder-core';
import { Dialog } from './dialog';
import { BotTelemetryClient, NullTelemetryClient, Severity } from 'botbuilder-core';
import { Dialog, DialogEvent } from './dialog';
import { DialogSet } from './dialogSet';
import { DialogContext } from './dialogContext';
import { DialogEvents } from './dialogEvents';
Expand All @@ -32,6 +32,26 @@ export abstract class DialogContainer<O extends object = {}> extends Dialog<O> {
return this.dialogs.find(dialogId);
}

/**
* Called when an event has been raised, using `DialogContext.emitEvent()`,
* by either the current dialog or a dialog that the current dialog started.
*
* @param dc The dialog context for the current turn of conversation.
* @param e The event being raised.
*/
public async onDialogEvent(dc: DialogContext, e: DialogEvent): Promise<boolean> {
const handled = await super.onDialogEvent(dc, e);
if (!handled && e.name === DialogEvents.versionChanged) {
const traceMessage = `Unhandled dialog event: ${ e.name }. Active Dialog: ${ dc.activeDialog.id }`;
dc.dialogs.telemetryClient.trackTrace({
message: traceMessage,
severityLevel: Severity.Warning
});
await dc.context.sendTraceActivity(traceMessage);
}
return handled;
}

/**
* Returns internal version identifier for this container.
*
Expand Down
30 changes: 11 additions & 19 deletions libraries/botbuilder-dialogs/tests/componentDialog.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { ConversationState, MemoryStorage, TestAdapter } = require('botbuilder-core');
const { ConversationState, MemoryStorage, TestAdapter, Severity } = require('botbuilder-core');
const { Dialog, DialogReason, DialogSet, DialogTurnStatus, ComponentDialog, WaterfallDialog } = require('../');
const assert = require('assert');

Expand Down Expand Up @@ -363,11 +363,19 @@ describe('ComponentDialog', function () {
return await step.endDialog();
}
]);
const component = new ChangedDialog('test', true);
const component = new ComponentDialog('test');
component.addDialog(childDialog);

const dialogs = new DialogSet(dialogState);
dialogs.add(component);
dialogs.telemetryClient = {
trackEvent: function(telemetry) {},
trackTrace: function(telemetry) {
if (telemetry.severityLevel === Severity.Warning) {
assert.equal(telemetry.message, 'Unhandled dialog event: versionChanged. Active Dialog: test');
}
}
};

const adapter = new TestAdapter(async turnContext => {
const dc = await dialogs.createContext(turnContext);
Expand All @@ -387,9 +395,8 @@ describe('ComponentDialog', function () {
adapter.send('Hi')
.assertReply('First step.')
.send('Hi again')
.assertReply('Version Changed.')
.assertReply('Second step.')
.assertReply('Done.')
.assertReply('Done.');
});
});

Expand All @@ -404,18 +411,3 @@ class ContinueDialog extends ComponentDialog {
return await innerDC.continueDialog();
}
}

class ChangedDialog extends ComponentDialog {
constructor(dialogId, handle) {
super(dialogId);
this.handle = handle;
}

async onPreBubbleEvent(dc, event) {
if (event.name == 'versionChanged' && this.handle) {
await dc.context.sendActivity('Version Changed.');
return true;
}
return false;
}
}