11// Copyright (c) Microsoft Corporation. All rights reserved.
22// Licensed under the MIT License.
33
4+ using System ;
45using System . Collections . Generic ;
56using EnterpriseBotSample . Middleware . Telemetry ;
67using Microsoft . ApplicationInsights ;
8+ using Microsoft . ApplicationInsights . Extensibility ;
79using Microsoft . Bot . Builder . AI . Luis ;
810using Microsoft . Bot . Builder . AI . QnA ;
911using Microsoft . Bot . Configuration ;
@@ -32,14 +34,44 @@ public BotServices(BotConfiguration botConfiguration)
3234 {
3335 case ServiceTypes . AppInsights :
3436 {
35- var appInsights = service as AppInsightsService ;
36- TelemetryClient = new TelemetryClient ( ) ;
37+ var appInsights = ( AppInsightsService ) service ;
38+ if ( appInsights == null )
39+ {
40+ throw new InvalidOperationException ( "The Application Insights is not configured correctly in your '.bot' file." ) ;
41+ }
42+
43+ if ( string . IsNullOrWhiteSpace ( appInsights . InstrumentationKey ) )
44+ {
45+ throw new InvalidOperationException ( "The Application Insights Instrumentation Key ('instrumentationKey') is required to run this sample. Please update your '.bot' file." ) ;
46+ }
47+
48+ var telemetryConfig = new TelemetryConfiguration ( appInsights . InstrumentationKey ) ;
49+ TelemetryClient = new TelemetryClient ( telemetryConfig )
50+ {
51+ InstrumentationKey = appInsights . InstrumentationKey ,
52+ } ;
53+
3754 break ;
3855 }
3956
4057 case ServiceTypes . Dispatch :
4158 {
4259 var dispatch = service as DispatchService ;
60+ if ( dispatch == null )
61+ {
62+ throw new InvalidOperationException ( "The Dispatch service is not configured correctly in your '.bot' file." ) ;
63+ }
64+
65+ if ( string . IsNullOrWhiteSpace ( dispatch . AppId ) )
66+ {
67+ throw new InvalidOperationException ( "The Dispatch Luis Model Application Id ('appId') is required to run this sample. Please update your '.bot' file." ) ;
68+ }
69+
70+ if ( string . IsNullOrWhiteSpace ( dispatch . SubscriptionKey ) )
71+ {
72+ throw new InvalidOperationException ( "The Subscription Key ('subscriptionKey') is required to run this sample. Please update your '.bot' file." ) ;
73+ }
74+
4375 var dispatchApp = new LuisApplication ( dispatch . AppId , dispatch . SubscriptionKey , dispatch . GetEndpoint ( ) ) ;
4476 DispatchRecognizer = new TelemetryLuisRecognizer ( dispatchApp ) ;
4577 break ;
@@ -48,8 +80,34 @@ public BotServices(BotConfiguration botConfiguration)
4880 case ServiceTypes . Luis :
4981 {
5082 var luis = service as LuisService ;
83+ if ( luis == null )
84+ {
85+ throw new InvalidOperationException ( "The Luis service is not configured correctly in your '.bot' file." ) ;
86+ }
87+
88+ if ( string . IsNullOrWhiteSpace ( luis . AppId ) )
89+ {
90+ throw new InvalidOperationException ( "The Luis Model Application Id ('appId') is required to run this sample. Please update your '.bot' file." ) ;
91+ }
92+
93+ if ( string . IsNullOrWhiteSpace ( luis . AuthoringKey ) )
94+ {
95+ throw new InvalidOperationException ( "The Luis Authoring Key ('authoringKey') is required to run this sample. Please update your '.bot' file." ) ;
96+ }
97+
98+ if ( string . IsNullOrWhiteSpace ( luis . SubscriptionKey ) )
99+ {
100+ throw new InvalidOperationException ( "The Subscription Key ('subscriptionKey') is required to run this sample. Please update your '.bot' file." ) ;
101+ }
102+
103+ if ( string . IsNullOrWhiteSpace ( luis . Region ) )
104+ {
105+ throw new InvalidOperationException ( "The Region ('region') is required to run this sample. Please update your '.bot' file." ) ;
106+ }
107+
51108 var luisApp = new LuisApplication ( luis . AppId , luis . SubscriptionKey , luis . GetEndpoint ( ) ) ;
52- LuisServices . Add ( service . Id , new TelemetryLuisRecognizer ( luisApp ) ) ;
109+ var recognizer = new TelemetryLuisRecognizer ( luisApp ) ;
110+ LuisServices . Add ( service . Id , recognizer ) ;
53111 break ;
54112 }
55113
0 commit comments