Skip to content
This repository has been archived by the owner on Jun 30, 2022. It is now read-only.

Commit

Permalink
Updated template to 4.2 SDK (#456)
Browse files Browse the repository at this point in the history
Passing IBotTelemetryClient through all waterfall dialogs
Additional middleware updates for advanced conversational analytics
  • Loading branch information
ryanisgrig authored Dec 17, 2018
1 parent 6e44560 commit a0491c8
Show file tree
Hide file tree
Showing 33 changed files with 318 additions and 248 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,30 +31,85 @@ public BotServices(BotConfiguration botConfiguration)
{
switch (service.Type)
{
case ServiceTypes.AppInsights:
case ServiceTypes.AppInsights:
{
var appInsights = (AppInsightsService)service;
if (appInsights == null)
{
var appInsights = service as AppInsightsService;
var telemetryConfig = new TelemetryConfiguration(appInsights.InstrumentationKey);
TelemetryClient = new TelemetryClient(telemetryConfig);
break;
throw new InvalidOperationException("The Application Insights is not configured correctly in your '.bot' file.");
}

case ServiceTypes.Dispatch:
if (string.IsNullOrWhiteSpace(appInsights.InstrumentationKey))
{
var dispatch = service as DispatchService;
var dispatchApp = new LuisApplication(dispatch.AppId, dispatch.SubscriptionKey, dispatch.GetEndpoint());
DispatchRecognizer = new TelemetryLuisRecognizer(dispatchApp);
break;
throw new InvalidOperationException("The Application Insights Instrumentation Key ('instrumentationKey') is required to run this sample. Please update your '.bot' file.");
}

case ServiceTypes.Luis:
var telemetryConfig = new TelemetryConfiguration(appInsights.InstrumentationKey);
TelemetryClient = new TelemetryClient(telemetryConfig)
{
var luis = service as LuisService;
var luisApp = new LuisApplication(luis.AppId, luis.SubscriptionKey, luis.GetEndpoint());
LuisServices.Add(service.Id, new TelemetryLuisRecognizer(luisApp));
break;
InstrumentationKey = appInsights.InstrumentationKey,
};

break;
}

case ServiceTypes.Dispatch:
{
var dispatch = service as DispatchService;
if (dispatch == null)
{
throw new InvalidOperationException("The Dispatch service is not configured correctly in your '.bot' file.");
}

if (string.IsNullOrWhiteSpace(dispatch.AppId))
{
throw new InvalidOperationException("The Dispatch Luis Model Application Id ('appId') is required to run this sample. Please update your '.bot' file.");
}

if (string.IsNullOrWhiteSpace(dispatch.SubscriptionKey))
{
throw new InvalidOperationException("The Subscription Key ('subscriptionKey') is required to run this sample. Please update your '.bot' file.");
}

var dispatchApp = new LuisApplication(dispatch.AppId, dispatch.SubscriptionKey, dispatch.GetEndpoint());
DispatchRecognizer = new TelemetryLuisRecognizer(dispatchApp);
break;
}

case ServiceTypes.Luis:
{
var luis = service as LuisService;
if (luis == null)
{
throw new InvalidOperationException("The Luis service is not configured correctly in your '.bot' file.");
}

if (string.IsNullOrWhiteSpace(luis.AppId))
{
throw new InvalidOperationException("The Luis Model Application Id ('appId') is required to run this sample. Please update your '.bot' file.");
}

if (string.IsNullOrWhiteSpace(luis.AuthoringKey))
{
throw new InvalidOperationException("The Luis Authoring Key ('authoringKey') is required to run this sample. Please update your '.bot' file.");
}

if (string.IsNullOrWhiteSpace(luis.SubscriptionKey))
{
throw new InvalidOperationException("The Subscription Key ('subscriptionKey') is required to run this sample. Please update your '.bot' file.");
}

if (string.IsNullOrWhiteSpace(luis.Region))
{
throw new InvalidOperationException("The Region ('region') is required to run this sample. Please update your '.bot' file.");
}

var luisApp = new LuisApplication(luis.AppId, luis.SubscriptionKey, luis.GetEndpoint());
var recognizer = new TelemetryLuisRecognizer(luisApp);
LuisServices.Add(service.Id, recognizer);
break;
}

case ServiceTypes.QnA:
{
var qna = service as QnAMakerService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class CustomerSupportTemplate : IBot
private readonly BotServices _services;
private readonly ConversationState _conversationState;
private readonly UserState _userState;
private readonly IBotTelemetryClient _telemetryClient;
private DialogSet _dialogs;

/// <summary>
Expand All @@ -27,14 +28,16 @@ public class CustomerSupportTemplate : IBot
/// <param name="botServices">Bot services.</param>
/// <param name="conversationState">Bot conversation state.</param>
/// <param name="userState">Bot user state.</param>
public CustomerSupportTemplate(BotServices botServices, ConversationState conversationState, UserState userState)
public CustomerSupportTemplate(BotServices botServices, ConversationState conversationState, UserState userState, IBotTelemetryClient telemetryClient)
{
_conversationState = conversationState ?? throw new ArgumentNullException(nameof(conversationState));
_userState = userState ?? throw new ArgumentNullException(nameof(userState));
_services = botServices ?? throw new ArgumentNullException(nameof(botServices));
_telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient));


_dialogs = new DialogSet(_conversationState.CreateProperty<DialogState>(nameof(CustomerSupportTemplate)));
_dialogs.Add(new MainDialog(_services, _conversationState, _userState));
_dialogs.Add(new MainDialog(_services, _conversationState, _userState, _telemetryClient));
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,25 @@

<ItemGroup>
<PackageReference Include="AdaptiveCards" Version="1.0.0" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.1.1" />
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.8.1" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.5.1" />
<PackageReference Include="Microsoft.ApplicationInsights.DependencyCollector" Version="2.8.1" />
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.1.5" />
<PackageReference Include="Microsoft.Azure.CognitiveServices.ContentModerator" Version="0.12.1-preview" />
<PackageReference Include="Microsoft.Azure.CognitiveServices.Language" Version="1.0.1-preview" />
<PackageReference Include="Microsoft.Bot.Builder" Version="4.0.7" />
<PackageReference Include="Microsoft.Bot.Builder.AI.Luis" Version="4.0.7" />
<PackageReference Include="Microsoft.Bot.Builder.AI.QnA" Version="4.0.7" />
<PackageReference Include="Microsoft.Bot.Builder.Azure" Version="4.0.7" />
<PackageReference Include="Microsoft.Bot.Builder.Dialogs" Version="4.0.7" />
<PackageReference Include="Microsoft.Bot.Builder.Integration.AspNet.Core" Version="4.0.7" />
<PackageReference Include="Microsoft.Bot.Builder.TemplateManager" Version="4.0.7" />
<PackageReference Include="Microsoft.Bot.Configuration" Version="4.0.7" />
<PackageReference Include="Microsoft.Bot.Connector" Version="4.0.7" />
<PackageReference Include="Microsoft.Bot.Schema" Version="4.0.7" />
<PackageReference Include="Microsoft.Graph" Version="1.10.0" />
<PackageReference Include="Microsoft.Bot.Builder" Version="4.2.0" />
<PackageReference Include="Microsoft.Bot.Builder.AI.Luis" Version="4.2.0" />
<PackageReference Include="Microsoft.Bot.Builder.AI.QnA" Version="4.2.0" />
<PackageReference Include="Microsoft.Bot.Builder.ApplicationInsights" Version="4.2.0" />
<PackageReference Include="Microsoft.Bot.Builder.Azure" Version="4.2.0" />
<PackageReference Include="Microsoft.Bot.Builder.Dialogs" Version="4.2.0" />
<PackageReference Include="Microsoft.Bot.Builder.Integration.ApplicationInsights.Core" Version="4.2.0" />
<PackageReference Include="Microsoft.Bot.Builder.Integration.AspNet.Core" Version="4.2.0" />
<PackageReference Include="Microsoft.Bot.Builder.TemplateManager" Version="4.2.0" />
<PackageReference Include="Microsoft.Bot.Configuration" Version="4.2.0" />
<PackageReference Include="Microsoft.Bot.Connector" Version="4.2.0" />
<PackageReference Include="Microsoft.Bot.Schema" Version="4.2.0" />
<PackageReference Include="Microsoft.Graph" Version="1.12.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,21 @@ public class PayBillDialog : CustomerSupportDialog

public PayBillDialog(
BotServices services,
IStatePropertyAccessor<CustomerSupportTemplateState> stateAccessor)
: base(services, nameof(PayBillDialog))
IStatePropertyAccessor<CustomerSupportTemplateState> stateAccessor,
IBotTelemetryClient telemetryClient)
: base(services, nameof(PayBillDialog), telemetryClient)
{
_services = services;
_stateAccessor = stateAccessor;
TelemetryClient = telemetryClient;

var payBill = new WaterfallStep[]
{
ShowPayBillOptions
};

InitialDialogId = nameof(PayBillDialog);
AddDialog(new WaterfallDialog(InitialDialogId, payBill));
AddDialog(new WaterfallDialog(InitialDialogId, payBill) { TelemetryClient = telemetryClient });
}

private async Task<DialogTurnResult> ShowPayBillOptions(WaterfallStepContext sc, CancellationToken cancellationToken)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ public class ResetPasswordDialog : CustomerSupportDialog

public ResetPasswordDialog(
BotServices services,
IStatePropertyAccessor<CustomerSupportTemplateState> stateAccessor)
: base(services, nameof(ResetPasswordDialog))
IStatePropertyAccessor<CustomerSupportTemplateState> stateAccessor,
IBotTelemetryClient telemetryClient)
: base(services, nameof(ResetPasswordDialog), telemetryClient)
{
_client = new DemoServiceClient();
_services = services;
_stateAccessor = stateAccessor;
TelemetryClient = telemetryClient;

var resetPassword = new WaterfallStep[]
{
Expand All @@ -33,7 +35,7 @@ public ResetPasswordDialog(
};

InitialDialogId = nameof(ResetPasswordDialog);
AddDialog(new WaterfallDialog(InitialDialogId, resetPassword));
AddDialog(new WaterfallDialog(InitialDialogId, resetPassword) { TelemetryClient = telemetryClient });
AddDialog(new TextPrompt(DialogIds.AccountIdPrompt));
AddDialog(new TextPrompt(DialogIds.EmailPrompt, EmailValidator));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ public class UpdateAccountDialog : CustomerSupportDialog

public UpdateAccountDialog(
BotServices services,
IStatePropertyAccessor<CustomerSupportTemplateState> stateAccessor)
: base(services, nameof(UpdateAccountDialog))
IStatePropertyAccessor<CustomerSupportTemplateState> stateAccessor,
IBotTelemetryClient telemetryClient)
: base(services, nameof(UpdateAccountDialog), telemetryClient)
{
_client = new DemoServiceClient();
_services = services;
_stateAccessor = stateAccessor;
TelemetryClient = telemetryClient;

var updateAccount = new WaterfallStep[]
{
Expand All @@ -34,7 +36,7 @@ public UpdateAccountDialog(
};

InitialDialogId = nameof(UpdateAccountDialog);
AddDialog(new WaterfallDialog(InitialDialogId, updateAccount));
AddDialog(new WaterfallDialog(InitialDialogId, updateAccount) { TelemetryClient = telemetryClient });
AddDialog(new FormPrompt(DialogIds.UpdateContactInfoPrompt, ContactInfoValidator));
AddDialog(new OAuthPrompt(DialogIds.AuthPrompt, new OAuthPromptSettings()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Threading;
using System.Threading.Tasks;
using CustomerSupportTemplate.Dialogs.Shared;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Dialogs;

namespace CustomerSupportTemplate
Expand All @@ -12,18 +13,19 @@ public class CancelDialog : ComponentDialog
{
private static CancelResponses _responder = new CancelResponses();

public CancelDialog()
public CancelDialog(IBotTelemetryClient telemetryClient)
: base(nameof(CancelDialog))
{
InitialDialogId = nameof(CancelDialog);
TelemetryClient = telemetryClient;

var cancel = new WaterfallStep[]
{
AskToCancel,
FinishCancelDialog,
};

AddDialog(new WaterfallDialog(InitialDialogId, cancel));
AddDialog(new WaterfallDialog(InitialDialogId, cancel) { TelemetryClient = telemetryClient });
AddDialog(new ConfirmPrompt(DialogIds.CancelPrompt, SharedValidators.ConfirmValidator));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System.Threading;
using System.Threading.Tasks;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Dialogs;

namespace CustomerSupportTemplate
Expand All @@ -12,7 +13,7 @@ public class EscalateDialog : ComponentDialog
// Fields
private EscalateResponses _responder = new EscalateResponses();

public EscalateDialog(BotServices botServices)
public EscalateDialog(BotServices botServices, IBotTelemetryClient telemetryClient)
: base(nameof(EscalateDialog))
{
var escalate = new WaterfallStep[]
Expand All @@ -21,7 +22,7 @@ public EscalateDialog(BotServices botServices)
};

InitialDialogId = nameof(EscalateDialog);
AddDialog(new WaterfallDialog(InitialDialogId, escalate));
AddDialog(new WaterfallDialog(InitialDialogId, escalate) { TelemetryClient = telemetryClient });
}

private async Task<DialogTurnResult> SendEscalationMessage(WaterfallStepContext stepContext, CancellationToken cancellationToken)
Expand Down
Loading

0 comments on commit a0491c8

Please sign in to comment.