Microsoft Azure LUIS app emulator no reply - node.js

Just set up a Azure Bot essentially following this tutorial https://learn.microsoft.com/en-us/azure/cognitive-services/luis/luis-nodejs-tutorial-build-bot-framework-sample and the code works fine when I test it in the online web chat - intent is recognised and the bot responds.
However, when I try to run the same code copied down and set up as a local git repository through Visual Studio Community 2017, the bot doesn't seem to reply.
I'm not hitting any errors right now when I send the bot a message through the emulator (chatconnector registers it as message received).
Any ideas on how to fix this?
http://i1376.photobucket.com/albums/ah21/michael_liang1/stack%20overflow_zpsrvsazqvt.png
(don't have enough reputation to post images yet - sorry!)

It's possible that you didn't configure the LuisAppId, LuisAPIKey and LuisAPIHostName in the .env file when you copy the code into the local VS.
In portal, it will automatically get these keys from app settings, but on local side, we need to configure them in our code.
According to the tutorial, the LuisAppId, LuisAPIKey and LuisAPIHostName should be configured in .env, for example like this:
# Bot Framework Variables
MICROSOFT_APP_ID=<YOURAPPID>
MICROSOFT_APP_PASSWORD=<YOURAPPPASSWORD>
LuisAppId=<YOURLUISAPPID>
LuisAPIKey=<YOURLUISKEY>
LuisAPIHostName=<YOURAPIHOSTNAME>
Then the code in toturial uses these three parameters to generate a LuisModelUrl, you can actually directly configure this url which is generated after you publish your luis app, into your .env file. For more information, you can refer to the official LUIS Bot Sample.

Solved the issue. It seems you need to add parameters into the AzureTableClient method of botbuilder SDK to include the name and key of an existing storage account hosted in Azure.
var tableName = 'botdata';
var azureTableClient = new botbuilder_azure.AzureTableClient(tableName, process.env.AzureTableName, process.env.AzureTableKey); //process.env['AzureWebJobsStorage']
var tableStorage = new botbuilder_azure.AzureBotStorage({ gzipData: false }, azureTableClient);
I added process.env.AzureTableName and process.env.AzureTableKey which is the name and access key for the Azure Storage Account I created. The variables key and name are specified in my .env file.

Related

BotBuilder Authentication Multitenant

I want to create Microsoft BotBuilder following this tutorial. But it seems SO complicated compared to v3.(BTW: starting a tutorial with 3 authentications that cover 75% of the article is not a good sign)
So I follow the EchoBot sample (I chose MultiTenant because my server is outside AND it seems the most covered):
const credentialsFactory = new BotBuilder.ConfigurationServiceClientCredentialFactory({
MicrosoftAppId: '***',
MicrosoftAppPassword: '***',
MicrosoftAppType: 'MultiTenant',
});
const botFrameworkAuthentication = BotBuilder.createBotFrameworkAuthenticationFromConfiguration(null, credentialsFactory);
const onTurnErrorHandler = async (context, error) => { /* for errors */ }
const adapter = new BotBuilder.CloudAdapter(botFrameworkAuthentication);
adapter.onTurnError = onTurnErrorHandler;
Questions:
How do I test everything is working ? isValidAppId() and isAuthenticationDisabled() are the only available method and seems OK.
How do I get MicrosoftAppPassword ? According to the documentation I have to click manage, then create a value/secret pair. Should I use value ? or secret ? Why none is named password ? Anyway none works ...
To test if it works, I follow the sample:
setup an HTTP POST Endpoint (with Node-RED)
declare the endpoint in Azure Portal Bot Configuration
go to webchat to test
I correctly receive the Messages then try to do some authentication/parisng (I assume) :
await adapter.process(msg.req, msg.res, (context) => {
/* do some stuff */
});
But it fails with a very explicit error :
Error: 1 validation issue(s)
Issue #0: custom_error at [[root]]
Response
I think, the errors is related to an authentication issue, since I don't understand what/how to set the password. I guess I have to go through this CloudAdapter in order to get a parsed context and be able to send messages.
EDIT 07/05/2022:
I use the AppId from here :
I click "Manage" but where is the AppPassword ?
EDIT 12/05/2022:
Using cURL I manage to validate the appID and appPassword (the value (hidden by stars) of the secret).
BotBuilder is mixing the Communication Stack (HTTP / WebSocket) and the Logic stack (Turn Conversation). I think it's a bad habbit but I manage a workaround:
I use a BotFrameworkAdapter instead of CloudAdpater
I call adapter.processActivity() instead of adapter.process()
The adapter still want to end() the request and set deprecated values but it works in Node-RED. The context handle all the requirement to call sendActivity() anywhere multiple times.
To answer second question in your case, kindly go through the link :https://learn.microsoft.com/en-us/azure/bot-service/bot-service-quickstart-registration?view=azure-bot-service-4.0&tabs=multitenant
To answer the first question in your case, kindly check disabling and enabling the authentication to test the app: https://learn.microsoft.com/en-us/azure/bot-service/bot-service-troubleshoot-authentication-problems?view=azure-bot-service-4.0&tabs=csharp
As far as getting the password goes, when you create a new Multi Tenant Azure Bot resource, the app password goes into the Azure Key Vault created alongside it. The AppId and AppPassword are randomly generated by Azure. You can get them from the key vault in the Azure portal in the correct resource group.
If you want to create a resource manually using the CLI and define your own password, you can use this docs page for deploying a bot. Make sure you select the correct tabs. I have pre-selected C# and Multi Tenant in a new resource group for the above link.
Single Tenant is for limiting your bot's connections to Azure resources within the same tenant, and a User Assigned Managed Identity is if you want to make use of an Azure Managed Identity across the bot's resources instead of having a password for each resource.
You should be able to simply add the AppId and AppPassword to the echo bot sample and deploy it.

Google Cloud Vision reverse image search fails on Azure App Service because GOOGLE_APPLICATION_CREDENTIALS file cannot be found

I am attempting to perform a Google reverse image search using Google Cloud Vision on an Azure app service web app.
I have generated a googleCred.json, which the Google client libraries use in order to construct API requests. Google expects it to be available from an environment variable named GOOGLE_APPLICATION_CREDENTIALS.
The Azure app service that runs the web app has settings that mimic environment variables for the Google client libraries. The documentation is here, and I have successfully set the variable here:
Furthermore, the googleCred.json file has been uploaded to the app service. Here is the documentation I followed to use FTP and FileZilla to upload the file:
Also, the file permissions are as open as they can be:
However, when I access the web app in the cloud, I get the following error message:
Error reading credential file from location D:\site\wwwroot\Statics\googleCred.json: Could not find a part of the path 'D:\site\wwwroot\Statics\googleCred.json'. Please check the value of the Environment Variable GOOGLE_APPLICATION_CREDENTIALS
What am I doing wrong? How can I successfully use the Google Cloud Vision API on an Azure web app?
This error message is usually thrown when the application is not being authenticated correctly due to several reasons such as missing files, invalid credential paths, incorrect environment variables assignations, among other causes.
Based on this, I recommend you to validate that the credential file and file path are being correctly assigned, as well as follow the Obtaining and providing service account credentials manually guide in order to explicitly specify your service account file directly into your code; In this way, you will be able to set it permanently and verify if you are passing the service credentials correctly.
Passing the path to the service account key in code example:
// Imports the Google Cloud client library.
const Storage = require('#google-cloud/storage');
// Instantiates a client. Explicitly use service account credentials by
// specifying the private key file. All clients in google-cloud-node have this
// helper, see https://github.com/GoogleCloudPlatform/google-cloud-node/blob/master/docs/authentication.md
const storage = new Storage({
keyFilename: '/path/to/keyfile.json'
});
// Makes an authenticated API request.
storage
.getBuckets()
.then((results) => {
const buckets = results[0];
console.log('Buckets:');
buckets.forEach((bucket) => {
console.log(bucket.name);
});
})
.catch((err) => {
console.error('ERROR:', err);
});
I'm writing here since i can't comment, but at a quick glance, is the "D:" in the path necessary? I assume you uploaded the file to the app service so try with this value for the path "\site\wwwroot\Statics\googleCred.json"

deploy bot without hosting on azure

I have created a bot using Microsoft bot framework (NodeJs) , it working fine on local system. When i deployed with azure functions then also its working fine.
But i'm trying to deploy in some other way like
1) I want to register my bot on azure
2) but want to host somewhere else(SSL Certified server) i.e not on azure (don't want to use azure bot functions)
I have followed the steps got in some articles
My App.js Looks like this
But i'm getting below error when i tried to test with "Test in web Chat"
Can anyone please help me, what i'm doing wrong here ??
Thanks
Not familiar with AWS, but for making restify server support HTTPS, you can try to use:
const restify = require('restify');
const fs = require('fs');
const https_options = {
key: fs.readFileSync('./localhost_3978.key'), //on current folder
certificate: fs.readFileSync('./localhost_3978.cert')
};
server = restify.createServer(https_options);
Create the restify server with your SSL certificate and key files before your bot application.

Mobile Service Configuration: MS_NotificationHubConnectionString Contains Invalid Setting Key "entitypath"

I'm trying to create a new Azure Mobile Service, however when trying to call a Custom API it generates the following error in the logs of the service.
An error occurred creating push for user scripts:
azure.notificationHubService could not be created. HubName:
"servicenamehub" ConnectionString
"Endpoint=sb://servicenamehub-ns.servicebus.windows.net/;
SharedAccessKeyName=DefaultFullSharedAccessSignature;
SharedAccessKey={accesskey};EntityPath=servicenamehub": Error from
create-Error: Invalid connection string setting key "entitypath".
The error only seems to generate when making an API call, not when making a call on a table.
The MS_NotificationHubConnectionString is where this connection string is stored, however it was auto generated along with the service hub and isn't editable in the service configuration.
The EntityPath key doesn't appear in the MS_NotificationHubConnectionString of any of my older services. The Mobile Service has a JavaScript back end.
How do I prevent this error or remove the EntityPath key from the connection string?
Currently, here is a workaround: we login Kudu console site of the Mobile Service backend, modify MS_NotificationHubConnectionString in the script which will create notification hub service directly in source code.
login in Kudu console site, whose url should be https://<your_mobile_service_name>.scm.azure-mobile.net/DebugConsole
In the file system list in the page, enter to the path D:\home\site\wwwroot\node_modules\azure-mobile-services\runtime\push, edit the file pushadapter.js
Add following code to the start of the function PushAdapter in this script around line 22:
var string = options.MS_NotificationHubConnectionString;
var index = string.indexOf('EntityPath');
options.MS_NotificationHubConnectionString = index>0?string.slice(0,string.indexOf('EntityPath')-1):string;
Any further concern, please feel free to let me know.

Xamarin AccountStore/Account not persisting when app is updated

I'm using the Xamarin AccountStore/Account to hold information about the user of my application (their details are stored after they have been authenticated by a remote server)
This works fine if the details are written out, the app killed and then restarted. It finds the existing account store.
However if the app is updated (because I make some changes in Xamarin Studio and redeploy) then it doesn't find any accounts for my service.
This is how I'm requesting the account:
var accountStore = AccountStore.Create(this._context);
var storage = accountStore.FindAccountsForService(this._serviceId);
var account = storage.FirstOrDefault(x => x.Username == username);
And this is how I'm persisting the account settings:
accountStore.Save(account, this._serviceId);
Does anyone know why the AccountStore is not found when the app is updated?
Any idea where it's being stored on the device?
Thanks!
As stated in this answer, checking Preferences --> Android --> check "Preserve data/cache between application deploys" fixes the problem.

Resources