Reputation: 21
I am getting following error message while calling Dispatch/LUIS services from the bot framework. I have configured Microsoft APP ID and Password and I have deployed into web chat also. Error:Operation returned an invalid status code ‘Unauthorized’
Json result from the bot emulator
"Exception Message: Operation returned an invalid status code 'Unauthorized', Stack: at Microsoft.Azure.CognitiveServices.Language.LUIS.Runtime.Prediction.ResolveWithHttpMessagesAsync(String appId, String query, Nullable`1 timezoneOffset, Nullable`1 verbose, Nullable`1 staging, Nullable`1 spellCheck, String bingSpellCheckSubscriptionKey, Nullable`1 log, Dictionary`2 customHeaders, CancellationToken cancellationToken)
at Microsoft.Azure.CognitiveServices.Language.LUIS.Runtime.PredictionExtensions.ResolveAsync(IPrediction operations, String appId, String query, Nullable`1 timezoneOffset, Nullable`1 verbose, Nullable`1 staging, Nullable`1 spellCheck, String bingSpellCheckSubscriptionKey, Nullable`1 log, CancellationToken cancellationToken)
at Microsoft.Bot.Builder.AI.Luis.LuisRecognizer.RecognizeInternalAsync(ITurnContext turnContext, LuisPredictionOptions predictionOptions, Dictionary`2 telemetryProperties, Dictionary`2 telemetryMetrics, CancellationToken cancellationToken)
at Microsoft.Bot.Builder.AI.Luis.LuisRecognizer.RecognizeAsync[T](ITurnContext turnContext, CancellationToken cancellationToken)
at MyAssistant1.Dialogs.MainDialog.OnContinueDialogAsync(DialogContext innerDc, CancellationToken cancellationToken) in C:\Users\Administrator\source\repos\MyAssistant1\MyAssistant1\MyAssistant1\Dialogs\MainDialog.cs:line 80
at Microsoft.Bot.Builder.Dialogs.ComponentDialog.ContinueDialogAsync(DialogContext outerDc, CancellationToken cancellationToken)
at Microsoft.Bot.Builder.Dialogs.DialogContext.ContinueDialogAsync(CancellationToken cancellationToken)
at Microsoft.Bot.Builder.Dialogs.DialogExtensions.RunAsync(Dialog dialog, ITurnContext turnContext, IStatePropertyAccessor`1 accessor, CancellationToken cancellationToken)
at Microsoft.Bot.Builder.Teams.TeamsActivityHandler.OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken)
at MyAssistant1.Bots.DefaultActivityHandler`1.OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken) in C:\Users\Administrator\source\repos\MyAssistant1\MyAssistant1\MyAssistant1\Bots\DefaultActivityHandler.cs:line 34
at Microsoft.Bot.Builder.Solutions.Feedback.FeedbackMiddleware.OnTurnAsync(ITurnContext context, NextDelegate next, CancellationToken cancellationToken)
at Microsoft.Bot.Builder.Solutions.Middleware.EventDebuggerMiddleware.OnTurnAsync(ITurnContext turnContext, NextDelegate next, CancellationToken cancellationToken)
at Microsoft.Bot.Builder.Solutions.Middleware.SetLocaleMiddleware.OnTurnAsync(ITurnContext context, NextDelegate next, CancellationToken cancellationToken)
at Microsoft.Bot.Builder.Solutions.Feedback.FeedbackMiddleware.OnTurnAsync(ITurnContext context, NextDelegate next, CancellationToken cancellationToken)
at Microsoft.Bot.Builder.ShowTypingMiddleware.OnTurnAsync(ITurnContext turnContext, NextDelegate next, CancellationToken cancellationToken)
at Microsoft.Bot.Builder.TranscriptLoggerMiddleware.OnTurnAsync(ITurnContext turnContext, NextDelegate nextTurn, CancellationToken cancellationToken)
at Microsoft.Bot.Builder.TelemetryLoggerMiddleware.OnTurnAsync(ITurnContext context, NextDelegate nextTurn, CancellationToken cancellationToken)
at Microsoft.Bot.Builder.Integration.ApplicationInsights.Core.TelemetryInitializerMiddleware.OnTurnAsync(ITurnContext context, NextDelegate nextTurn, CancellationToken cancellationToken)
at Microsoft.Bot.Builder.BotFrameworkAdapter.TenantIdWorkaroundForTeamsMiddleware.OnTurnAsync(ITurnContext turnContext, NextDelegate next, CancellationToken cancellationToken)
at Microsoft.Bot.Builder.MiddlewareSet.ReceiveActivityWithStatusAsync(ITurnContext turnContext, BotCallbackHandler callback, CancellationToken cancellationToken)
at Microsoft.Bot.Builder.BotAdapter.RunPipelineAsync(ITurnContext turnContext, BotCallbackHandler callback, CancellationToken cancellationToken)"
Below are the code
protected override async Task<DialogTurnResult> OnContinueDialogAsync(DialogContext innerDc, CancellationToken cancellationToken = default)
{
if (innerDc.Context.Activity.Type == ActivityTypes.Message)
{
// Get cognitive models for the current locale.
var localizedServices = _services.GetCognitiveModels();
// Run LUIS recognition and store result in turn state.
var dispatchResult = await localizedServices.DispatchService.RecognizeAsync<DispatchLuis>(innerDc.Context, cancellationToken);
innerDc.Context.TurnState.Add(StateProperties.DispatchResult, dispatchResult);
if (dispatchResult.TopIntent().intent == DispatchLuis.Intent.l_ClientServices)
{
// Run LUIS recognition on General model and store result in turn state.
generalResult = await localizedServices.LuisServices["General"].RecognizeAsync<GeneralLuis>(innerDc.Context, cancellationToken);
innerDc.Context.TurnState.Add(StateProperties.GeneralResult, generalResult);
}
}
// Set up response caching for "repeat" functionality.
innerDc.Context.OnSendActivities(StoreOutgoingActivities);
return await base.OnContinueDialogAsync(innerDc, cancellationToken);
}
please help me on this I am using Microsoft bot framework V4.
Upvotes: 2
Views: 1373
Reputation: 10834
[I think I answered this already, but somehow my answer has vanished]
I think you might be getting a bit confused between authentication for the bot itself (i.e. between user <-> bot) and between the bot and the backend service (in this case LUIS, i.e. bot <-> LUIS). If so, you'll need to get your LUIS Application ID, which you get in the "manage" section of your LUIS app, as shown below.
Then you'll need the Subscription Key, shown below as the "primary key". You'll need the region too, in order to specify the correct endpoint. In my example, this is "westus".
Once you have those, you need to register them into the bot itself, but how you do that depends on how you are configuring your bot's services - have a look into your "_services" and how that is getting created, and perhaps send more details of what it's looking for or where it came from (which starter project you used for instance).
Upvotes: 1