Azure Bot-Builder : dispatch refresh fails with 401 error - botframework

We provisioned bot services using "msbot clone services ..." command. As part of this command a *.dispatch file is created with all the correct details.
The dispatch aggregates QnAMaker knowledge base and a LUIS app. We have verified the .dispatch file and also the .bot file to ensure correct keys are being used. The only change if any is we are not using starter_key in LUIS, rather we have generated a new key and this new key reflects in .dispatch and .bot file (when decrypted).
We have encrypted the .bot file correctly and tried following commands, and both fail with same error:
dispatch refresh --bot mybot.bot --secret
dispatch refresh --dispatch dispatch-file.dispatch
Error
Exporting LUIS application...
ERROR
One or more errors occurred. (The remote server returned an error: (401) Access Denied.)
Request url: https://westus.api.cognitive.microsoft.com/luis/api/v2.0/apps/<LUIS-APP-ID>/versions/0.1/export
Response: { "statusCode": 401, "message": "Access denied due to invalid subscription key. Make sure to provide a valid key for an active subscription." }

There are two different keys being used to use Dispatch CLI tool. Authoring key and subscription key. Authoring key is the key from luis.ai portal and needed to export the LUIS sources for Dispatch and to upload the newly created Dispatch app to luis portal. Subscription key is optional and is used for hitting luis endpoint/prediction API. If subscription key (created from Azure portal for LUIS Cognitive Service) is put in place of authoring key, Dispatch CLI won't be able to create and upload/refresh Dispatch app into luis. This is the expected behavior at the moment.

Having the exact same issue. With the starter key everything worked fine.
Edit: seems like an issue with Microsoft API.
You can use the starter key to update the dispatch model even though the query limit is reached.
My workaround was:
replace the subscriptionkey with the original starter key (authoringkey in luis)
run dispatch refresh
switch the keys again to allow for queries

Related

How to update Virtual Assistant bot when LUIS endpoint changes

I am trying to switch from using the LUIS Authoring Key to using a Subscription Key for both my Assistant and my Skill. I created a Subscription Key and assigned it to the LUIS app. What do I need to modify in a Virtual Assistant bot to get it to use the new the new key/endpoint?
I changed the prediction endpoint key to use a Subscription Key so I don't hit HTTP 403 and HTTP 429 errors and now I need to understand what I need to change in both the Assistant and Skill projects to use this new endpoint.
You can update the cognitivemodels.json file to use the subscription key assigned. You need to modify the cognitivemodels.json file in both the Virtual Assistant and Skill (or each skill). Then just re-publish your bot.

Teams Webhook gives ReflectionTypeLoadException

Is the webhook connections broken in Microsoft Teams or how do we solve the following issue?
When applying the Microsoft Teams Get Started documentation we get the following response in Postman.
"System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information."
We have set up a webhook in Teams and use it to post Application Insights messages to a Logic App where one of the actions is the webhook to Teams. Everything went fine until now (7/21 and 7/22, 2019) when we saw in Azure the same exception as a response on status 200. To figure this all out we went back to basic and tried to execute the Get Started documentation. The same exception was thrown.
Code that we used was all from the documentation.
After a day or two the exception wasn't returned anymore after NO modifications to the logic app or payload to the Teams webhook. Everything works fine now.
For future use we added an action to the Logic App to read out the webhook's response to determine futher actions, like sending an e-mail if webhook failed.

How do I continue a conversation after my token has expired?

I am trying to use a conversation reference to continue a conversation with a user within my node bot server. This conversation, I assume, is trying to be resumed after the last API token received has expired. When I try to call continueConversation which is defined in botFrameworkAdapter.ts in the botbuilder library (note, that this is not within a turn, so no message has been received from Teams since the API key has expired), with my service URL as https://smba.trafficmanager.net/uk/ which is what I have stored in my conversation reference, I get an unauthorized error.
After digging into the botbuilder library, I have narrowed it down to the shouldSetToken method within microsoftAppCredentials.js. It would seem the issue is that https://smba.trafficmanager.net/uk/ is not a trusted host name, and as a result the connector does not attempt to retrieve a new token for use.
I can verify that changing the shouldSetToken method to always return true solves my issue, but what is the correct approach to do this which does not involve altering the library?
I've managed to get around this for now with MicrosoftAppCredentials.trustServiceUrl(serviceUrl). If there is a better approach it'd be great to hear it.

LUIS App created using "msbot clone services" not getting published to "PRODUCTION"

I have created LUIS App using following command msbot clone services --folder Export --name <NAME_OF_BOT> --groupName <NAME_OF_GROUP> --luisAuthoringKey <LUIS_AUTHORING_KEY> --location westus --subscriptionId <AZURE_SUBSCRIPTION_ID> --sdkLanguage Node --sdkVersion v4 --appId <APPLICATION_ID> --appSecret <APPLICATION_PASSWORD>
Everything worked as expected except one thing. The LUIS App created is not available for consumption and always throws the error "model not published. please publish your model before hitting the endpoint."
Logged in to https://luis.ai > Selected the LUIS App > Clicked on Manage tab > Clicked on Keys and Endpoints on the left panel > Ensured URL reference slot has "Production" selected > Clicked on the Endpoint URL for "Starter_Key" Resource Name > appended a sample questions next to q= in the URL payload opened in browser
Expected Result: LUIS will be able to evaluate my utterance
Actual Result: model not published. please publish your model before hitting the endpoint.
For argument purpose tried to change the "URL referencing slot" from Production to Staging and retried. The expectation was met. Republish the already published app to Production and retried but the behavior was exactly same.
Just to ensure this is not a known problem even with Apps created directly on LUIS, went ahead and created a sample app using LUIS portal directly. Published only to Staging and tried to invoke the URL while "URL referencing slot" had Production selected. Got exact same error message. The published to Production and retried and everything worked as expected.
In summary this issue seem to be only with LUIS apps published using "msbot clone services ..." command. We are just not able to publish the app to production slot even though LUIS portal says it has been published.
This issue was a bug in LUIS and has been fixed.

Luis: Access denied due to invalid subscription key

I am facing following issue when i try to update application on Luis using following request:
https://westus.api.cognitive.microsoft.com/luis/api/v2.0/apps/app-id-here
header:
Ocp-Apim-Subscription-Key:paid-subscription key
body:
{
"name": "Name of luis app",
"description": "string"
}
I am getting following error:
{
"statusCode": 401,
"message": "Access denied due to invalid subscription key. Make sure to provide a valid key for an active subscription."
}
I am using paid subscription from Azure portal with westus region. Still facing this issue.
However, This key works when I try to get top scoring intent using following request:
https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/luis-app-id?subscription-key=subscription-key-azure&timezoneOffset=-360&q=hi
This is really weird as sunscription key works for GET request but not for PUT or POST request.
Any suggestions?
PS: I am using paid subscription key.
The (subscription) keys created with a Cognitive Service LUIS resource in Azure Portal, even when added to with Assign resource in luis.ai, can only be used for runtime queries on a defined app.
The authoring endpoints on LUIS Programmatic APIs v2.0 - to create and manage apps and their elements - can only be used with the Authoring Key available in the luis.ai portal.
More information can be found in Authoring and query prediction endpoint keys in LUIS
It looks like you have two issues you are working thru here.
First, the API you are trying to post to should read "https://[location].api.cognitive.microsoft.com/luis/api/v2.0/apps/{appId}/publish". From the looks of it, you are missing the 'publish' at the end of your API call.
Second, the paid subscription key needs to be added to your LUIS app. Can you confirm it has been added? If not, follow these steps to do so:
Click Manage => Keys and Endpoints.
Next, click 'Assign resource'.
A window will pop up allowing you to select the tenant, subscription, and the key to use.
Click OK.
Click 'Publish' to make the newly generated endpoint accessible.
Make sure you add subscription primary key value in my request and also make sure you have associated your API with the product which you used the Primary key

Resources