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

Commit a0491c8

Browse files
authored
Updated template to 4.2 SDK (#456)
Passing IBotTelemetryClient through all waterfall dialogs Additional middleware updates for advanced conversational analytics
1 parent 6e44560 commit a0491c8

33 files changed

+318
-248
lines changed

templates/Customer-Support-Template/CustomerSupportTemplate/BotServices.cs

Lines changed: 70 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,30 +31,85 @@ public BotServices(BotConfiguration botConfiguration)
3131
{
3232
switch (service.Type)
3333
{
34-
case ServiceTypes.AppInsights:
34+
case ServiceTypes.AppInsights:
35+
{
36+
var appInsights = (AppInsightsService)service;
37+
if (appInsights == null)
3538
{
36-
var appInsights = service as AppInsightsService;
37-
var telemetryConfig = new TelemetryConfiguration(appInsights.InstrumentationKey);
38-
TelemetryClient = new TelemetryClient(telemetryConfig);
39-
break;
39+
throw new InvalidOperationException("The Application Insights is not configured correctly in your '.bot' file.");
4040
}
4141

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

50-
case ServiceTypes.Luis:
47+
var telemetryConfig = new TelemetryConfiguration(appInsights.InstrumentationKey);
48+
TelemetryClient = new TelemetryClient(telemetryConfig)
5149
{
52-
var luis = service as LuisService;
53-
var luisApp = new LuisApplication(luis.AppId, luis.SubscriptionKey, luis.GetEndpoint());
54-
LuisServices.Add(service.Id, new TelemetryLuisRecognizer(luisApp));
55-
break;
50+
InstrumentationKey = appInsights.InstrumentationKey,
51+
};
52+
53+
break;
54+
}
55+
56+
case ServiceTypes.Dispatch:
57+
{
58+
var dispatch = service as DispatchService;
59+
if (dispatch == null)
60+
{
61+
throw new InvalidOperationException("The Dispatch service is not configured correctly in your '.bot' file.");
5662
}
5763

64+
if (string.IsNullOrWhiteSpace(dispatch.AppId))
65+
{
66+
throw new InvalidOperationException("The Dispatch Luis Model Application Id ('appId') is required to run this sample. Please update your '.bot' file.");
67+
}
68+
69+
if (string.IsNullOrWhiteSpace(dispatch.SubscriptionKey))
70+
{
71+
throw new InvalidOperationException("The Subscription Key ('subscriptionKey') is required to run this sample. Please update your '.bot' file.");
72+
}
73+
74+
var dispatchApp = new LuisApplication(dispatch.AppId, dispatch.SubscriptionKey, dispatch.GetEndpoint());
75+
DispatchRecognizer = new TelemetryLuisRecognizer(dispatchApp);
76+
break;
77+
}
78+
79+
case ServiceTypes.Luis:
80+
{
81+
var luis = service as LuisService;
82+
if (luis == null)
83+
{
84+
throw new InvalidOperationException("The Luis service is not configured correctly in your '.bot' file.");
85+
}
86+
87+
if (string.IsNullOrWhiteSpace(luis.AppId))
88+
{
89+
throw new InvalidOperationException("The Luis Model Application Id ('appId') is required to run this sample. Please update your '.bot' file.");
90+
}
91+
92+
if (string.IsNullOrWhiteSpace(luis.AuthoringKey))
93+
{
94+
throw new InvalidOperationException("The Luis Authoring Key ('authoringKey') is required to run this sample. Please update your '.bot' file.");
95+
}
96+
97+
if (string.IsNullOrWhiteSpace(luis.SubscriptionKey))
98+
{
99+
throw new InvalidOperationException("The Subscription Key ('subscriptionKey') is required to run this sample. Please update your '.bot' file.");
100+
}
101+
102+
if (string.IsNullOrWhiteSpace(luis.Region))
103+
{
104+
throw new InvalidOperationException("The Region ('region') is required to run this sample. Please update your '.bot' file.");
105+
}
106+
107+
var luisApp = new LuisApplication(luis.AppId, luis.SubscriptionKey, luis.GetEndpoint());
108+
var recognizer = new TelemetryLuisRecognizer(luisApp);
109+
LuisServices.Add(service.Id, recognizer);
110+
break;
111+
}
112+
58113
case ServiceTypes.QnA:
59114
{
60115
var qna = service as QnAMakerService;

templates/Customer-Support-Template/CustomerSupportTemplate/CustomerSupportTemplate.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public class CustomerSupportTemplate : IBot
1919
private readonly BotServices _services;
2020
private readonly ConversationState _conversationState;
2121
private readonly UserState _userState;
22+
private readonly IBotTelemetryClient _telemetryClient;
2223
private DialogSet _dialogs;
2324

2425
/// <summary>
@@ -27,14 +28,16 @@ public class CustomerSupportTemplate : IBot
2728
/// <param name="botServices">Bot services.</param>
2829
/// <param name="conversationState">Bot conversation state.</param>
2930
/// <param name="userState">Bot user state.</param>
30-
public CustomerSupportTemplate(BotServices botServices, ConversationState conversationState, UserState userState)
31+
public CustomerSupportTemplate(BotServices botServices, ConversationState conversationState, UserState userState, IBotTelemetryClient telemetryClient)
3132
{
3233
_conversationState = conversationState ?? throw new ArgumentNullException(nameof(conversationState));
3334
_userState = userState ?? throw new ArgumentNullException(nameof(userState));
3435
_services = botServices ?? throw new ArgumentNullException(nameof(botServices));
36+
_telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient));
37+
3538

3639
_dialogs = new DialogSet(_conversationState.CreateProperty<DialogState>(nameof(CustomerSupportTemplate)));
37-
_dialogs.Add(new MainDialog(_services, _conversationState, _userState));
40+
_dialogs.Add(new MainDialog(_services, _conversationState, _userState, _telemetryClient));
3841
}
3942

4043
/// <summary>

templates/Customer-Support-Template/CustomerSupportTemplate/CustomerSupportTemplate.csproj

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,25 @@
1212

1313
<ItemGroup>
1414
<PackageReference Include="AdaptiveCards" Version="1.0.0" />
15-
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.1.1" />
15+
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.8.1" />
16+
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.5.1" />
17+
<PackageReference Include="Microsoft.ApplicationInsights.DependencyCollector" Version="2.8.1" />
1618
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.1.5" />
1719
<PackageReference Include="Microsoft.Azure.CognitiveServices.ContentModerator" Version="0.12.1-preview" />
1820
<PackageReference Include="Microsoft.Azure.CognitiveServices.Language" Version="1.0.1-preview" />
19-
<PackageReference Include="Microsoft.Bot.Builder" Version="4.0.7" />
20-
<PackageReference Include="Microsoft.Bot.Builder.AI.Luis" Version="4.0.7" />
21-
<PackageReference Include="Microsoft.Bot.Builder.AI.QnA" Version="4.0.7" />
22-
<PackageReference Include="Microsoft.Bot.Builder.Azure" Version="4.0.7" />
23-
<PackageReference Include="Microsoft.Bot.Builder.Dialogs" Version="4.0.7" />
24-
<PackageReference Include="Microsoft.Bot.Builder.Integration.AspNet.Core" Version="4.0.7" />
25-
<PackageReference Include="Microsoft.Bot.Builder.TemplateManager" Version="4.0.7" />
26-
<PackageReference Include="Microsoft.Bot.Configuration" Version="4.0.7" />
27-
<PackageReference Include="Microsoft.Bot.Connector" Version="4.0.7" />
28-
<PackageReference Include="Microsoft.Bot.Schema" Version="4.0.7" />
29-
<PackageReference Include="Microsoft.Graph" Version="1.10.0" />
21+
<PackageReference Include="Microsoft.Bot.Builder" Version="4.2.0" />
22+
<PackageReference Include="Microsoft.Bot.Builder.AI.Luis" Version="4.2.0" />
23+
<PackageReference Include="Microsoft.Bot.Builder.AI.QnA" Version="4.2.0" />
24+
<PackageReference Include="Microsoft.Bot.Builder.ApplicationInsights" Version="4.2.0" />
25+
<PackageReference Include="Microsoft.Bot.Builder.Azure" Version="4.2.0" />
26+
<PackageReference Include="Microsoft.Bot.Builder.Dialogs" Version="4.2.0" />
27+
<PackageReference Include="Microsoft.Bot.Builder.Integration.ApplicationInsights.Core" Version="4.2.0" />
28+
<PackageReference Include="Microsoft.Bot.Builder.Integration.AspNet.Core" Version="4.2.0" />
29+
<PackageReference Include="Microsoft.Bot.Builder.TemplateManager" Version="4.2.0" />
30+
<PackageReference Include="Microsoft.Bot.Configuration" Version="4.2.0" />
31+
<PackageReference Include="Microsoft.Bot.Connector" Version="4.2.0" />
32+
<PackageReference Include="Microsoft.Bot.Schema" Version="4.2.0" />
33+
<PackageReference Include="Microsoft.Graph" Version="1.12.0" />
3034
</ItemGroup>
3135

3236
<ItemGroup>

templates/Customer-Support-Template/CustomerSupportTemplate/Dialogs/Account/PayBillDialog.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,21 @@ public class PayBillDialog : CustomerSupportDialog
1414

1515
public PayBillDialog(
1616
BotServices services,
17-
IStatePropertyAccessor<CustomerSupportTemplateState> stateAccessor)
18-
: base(services, nameof(PayBillDialog))
17+
IStatePropertyAccessor<CustomerSupportTemplateState> stateAccessor,
18+
IBotTelemetryClient telemetryClient)
19+
: base(services, nameof(PayBillDialog), telemetryClient)
1920
{
2021
_services = services;
2122
_stateAccessor = stateAccessor;
23+
TelemetryClient = telemetryClient;
2224

2325
var payBill = new WaterfallStep[]
2426
{
2527
ShowPayBillOptions
2628
};
2729

2830
InitialDialogId = nameof(PayBillDialog);
29-
AddDialog(new WaterfallDialog(InitialDialogId, payBill));
31+
AddDialog(new WaterfallDialog(InitialDialogId, payBill) { TelemetryClient = telemetryClient });
3032
}
3133

3234
private async Task<DialogTurnResult> ShowPayBillOptions(WaterfallStepContext sc, CancellationToken cancellationToken)

templates/Customer-Support-Template/CustomerSupportTemplate/Dialogs/Account/ResetPasswordDialog.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@ public class ResetPasswordDialog : CustomerSupportDialog
1818

1919
public ResetPasswordDialog(
2020
BotServices services,
21-
IStatePropertyAccessor<CustomerSupportTemplateState> stateAccessor)
22-
: base(services, nameof(ResetPasswordDialog))
21+
IStatePropertyAccessor<CustomerSupportTemplateState> stateAccessor,
22+
IBotTelemetryClient telemetryClient)
23+
: base(services, nameof(ResetPasswordDialog), telemetryClient)
2324
{
2425
_client = new DemoServiceClient();
2526
_services = services;
2627
_stateAccessor = stateAccessor;
28+
TelemetryClient = telemetryClient;
2729

2830
var resetPassword = new WaterfallStep[]
2931
{
@@ -33,7 +35,7 @@ public ResetPasswordDialog(
3335
};
3436

3537
InitialDialogId = nameof(ResetPasswordDialog);
36-
AddDialog(new WaterfallDialog(InitialDialogId, resetPassword));
38+
AddDialog(new WaterfallDialog(InitialDialogId, resetPassword) { TelemetryClient = telemetryClient });
3739
AddDialog(new TextPrompt(DialogIds.AccountIdPrompt));
3840
AddDialog(new TextPrompt(DialogIds.EmailPrompt, EmailValidator));
3941
}

templates/Customer-Support-Template/CustomerSupportTemplate/Dialogs/Account/UpdateAccountDialog.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@ public class UpdateAccountDialog : CustomerSupportDialog
1818

1919
public UpdateAccountDialog(
2020
BotServices services,
21-
IStatePropertyAccessor<CustomerSupportTemplateState> stateAccessor)
22-
: base(services, nameof(UpdateAccountDialog))
21+
IStatePropertyAccessor<CustomerSupportTemplateState> stateAccessor,
22+
IBotTelemetryClient telemetryClient)
23+
: base(services, nameof(UpdateAccountDialog), telemetryClient)
2324
{
2425
_client = new DemoServiceClient();
2526
_services = services;
2627
_stateAccessor = stateAccessor;
28+
TelemetryClient = telemetryClient;
2729

2830
var updateAccount = new WaterfallStep[]
2931
{
@@ -34,7 +36,7 @@ public UpdateAccountDialog(
3436
};
3537

3638
InitialDialogId = nameof(UpdateAccountDialog);
37-
AddDialog(new WaterfallDialog(InitialDialogId, updateAccount));
39+
AddDialog(new WaterfallDialog(InitialDialogId, updateAccount) { TelemetryClient = telemetryClient });
3840
AddDialog(new FormPrompt(DialogIds.UpdateContactInfoPrompt, ContactInfoValidator));
3941
AddDialog(new OAuthPrompt(DialogIds.AuthPrompt, new OAuthPromptSettings()
4042
{

templates/Customer-Support-Template/CustomerSupportTemplate/Dialogs/Cancel/CancelDialog.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Threading;
55
using System.Threading.Tasks;
66
using CustomerSupportTemplate.Dialogs.Shared;
7+
using Microsoft.Bot.Builder;
78
using Microsoft.Bot.Builder.Dialogs;
89

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

15-
public CancelDialog()
16+
public CancelDialog(IBotTelemetryClient telemetryClient)
1617
: base(nameof(CancelDialog))
1718
{
1819
InitialDialogId = nameof(CancelDialog);
20+
TelemetryClient = telemetryClient;
1921

2022
var cancel = new WaterfallStep[]
2123
{
2224
AskToCancel,
2325
FinishCancelDialog,
2426
};
2527

26-
AddDialog(new WaterfallDialog(InitialDialogId, cancel));
28+
AddDialog(new WaterfallDialog(InitialDialogId, cancel) { TelemetryClient = telemetryClient });
2729
AddDialog(new ConfirmPrompt(DialogIds.CancelPrompt, SharedValidators.ConfirmValidator));
2830
}
2931

templates/Customer-Support-Template/CustomerSupportTemplate/Dialogs/Escalate/EscalateDialog.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System.Threading;
55
using System.Threading.Tasks;
6+
using Microsoft.Bot.Builder;
67
using Microsoft.Bot.Builder.Dialogs;
78

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

15-
public EscalateDialog(BotServices botServices)
16+
public EscalateDialog(BotServices botServices, IBotTelemetryClient telemetryClient)
1617
: base(nameof(EscalateDialog))
1718
{
1819
var escalate = new WaterfallStep[]
@@ -21,7 +22,7 @@ public EscalateDialog(BotServices botServices)
2122
};
2223

2324
InitialDialogId = nameof(EscalateDialog);
24-
AddDialog(new WaterfallDialog(InitialDialogId, escalate));
25+
AddDialog(new WaterfallDialog(InitialDialogId, escalate) { TelemetryClient = telemetryClient });
2526
}
2627

2728
private async Task<DialogTurnResult> SendEscalationMessage(WaterfallStepContext stepContext, CancellationToken cancellationToken)

0 commit comments

Comments
 (0)