QnA bot on Microsoft Teams will not return more than one answer - azure

I've created QnA bot on Azure and integrated it with Teams. I'm built a knowledge base and it's able to return answers based on the knowledge base.
For training, I would like the bot to turn the top 5 answers regardless if there's a match. It will help me train the model if I can select which one is actually the best match.
I've updated the default responses to return the top 5 if there's no response, but I don't see where to always return the top 5 responses and invoke feedback from the user.
From the qnamakerBaseDialog.js in App Server Editor:
const {
QnAMakerDialog
} = require('botbuilder-ai');
const {
ActivityFactory
} = require('botbuilder-core');
// Default parameters
const DefaultThreshold = 0.0;
const DefaultTopN = 5;
const DefaultNoAnswer = 'No answers found. Please rephrase the question.';

Related

XERO-NODE SDK => How to choose a specific email template

I am using the Xero-node SDK to automatically create client invoices which works well.
At the end of the process, I would like to automatically email the client the invoice.
In the documentation it has the following example:
const xeroTenantId = 'YOUR_XERO_TENANT_ID';
const invoiceID = '00000000-0000-0000-0000-000000000000';
const requestEmpty: RequestEmpty = { };
try {
const response = await xero.accountingApi.emailInvoice(xeroTenantId, invoiceID, requestEmpty);
console.log(response.body || response.response.statusCode)
} catch (err) {
const error = JSON.stringify(err.response.body, null, 2)
console.log(`Status Code: ${err.response.statusCode} => ${error}`);
}
I have 2 questions:
The requestEmpty method does not work in javascript. Does anyone know the correct structure of requestEmpty?
I have used requestEmpty = { } but this throws an error => even though the system does actually send an email (probably a bug)
AND....
Is there a way for me to specify the email template that I would like the invoice to use (if I have specific templates setup in the web version)? Currently it seems to use the default Xero email template.
If you don't get an answer to your first query here, please can you raise it on the SDK page in Github and the Xero SDK team will look into this for you.
With regards to point 2, it is not possible to choose the email template when sending through the API, a basic template is used.

How to call a handler from another handler deploying an Alexa Skill?

Hello everyone,
i am working on an Alexa Skill at the moment and I have the problem, that I need to call a handler from another one.
I read several posts but there was no clear answer to my problem. I have a handler "AskForEmployeeInformation_Handler" which deals with several intents which answer several questions about a person. But if the user only says the surname or name instead of the full name then Alexa prompts out if there are persons which match to the given name. The user should now say one of the proposed names. While saying this name another handler "SetName_Handler" is called, which sets the chosen name as a session attribute. Now I want to call in the return statement the "AskForEmployeeInformation_Handler" again because it includes the whole logic to prompt out the wanted informations.
I saw some solutions to call the handler like you can see in the following code and the logic was executed but Alexa did not say anything and do not prompt the answer to the user.
Do you have an idea what I can do to solve the problem?
Thanks for your help.
const SetName_Handler = {
canHandle(handlerInput){
const request = handlerInput.requestEnvelope.request;
let sessionAttributes = handlerInput.attributesManager.getSessionAttributes();
return sessionAttributes.event === 'AskForEmployee_Name' || sessionAttributes.event === 'AskForPhoneNumber_Name' || sessionAttributes.event === 'AskForRole_Name';
},
handle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
const responseBuilder = handlerInput.responseBuilder;
let sessionAttributes = handlerInput.attributesManager.getSessionAttributes();
let say = '';
let slotValues = getSlotValues(request.intent.slots);
console.log('***** slotValues: ' + JSON.stringify(slotValues, null, 2));
//save person for the session - maybe for further questions
sessionAttributes['employeeSurname'] = slotValues.employeeSurname.resolved;
sessionAttributes['employeeName'] = slotValues.employeeName.resolved;
handlerInput.attributesManager.setSessionAttributes(sessionAttributes);
return AskForEmployeeInformation_Handler.handle(handlerInput;
}
};
I think your best bet is to separate the logic out of your handlers. I have never seen the need to call another Intent's handle method from another, and I find that this would add complications and odd errors.
The flat IntentHandler way of doing things is a recipe for disaster once your skill needs to know about session states and context (for example, what the user was doing previous to this IntentHandler being invoked).
Instead, you might find the Dialog Interface way of confirming slots to be exactly what you are looking for: https://developer.amazon.com/en-US/docs/alexa/custom-skills/dialog-interface-reference.html
Check out this article for a good overview of why/how to manage state and context in Alexa apps: https://medium.com/hackernoon/lessons-learned-moving-from-web-to-voice-development-35daa1d301db

How can i set default answer in Q&A Azure bot

I want change Default Answer in Q&A Maker Azure Framework Bot, but I cant find field that respond this value. I'm reading documentation (but it looks like it uses an older interface), and I'm trying to find this field but with result.
Here's my current configuration screen:
I'm assuming that you're referring to these docs: QnaMaker - Change Default Answer
They're a little confusing, but they key part is:
You can override this default response in the bot or application code
calling the endpoint.
Where the docs have this image:
What they actually mean is that in the QnAMaker Test Console, you can edit the default answer from your Application Settings. Be sure to Save, Train, and Publish your app or the setting may not show.
There's also kind of a way that you can use this setting for your default answer in a bot:
In Node/JS, your bot will not receive that DefaultAnswer at all. It receives nothing if there isn't a match, so you have to hard code it with something like:
const qnaResults = await this.qnaMaker.getAnswers(context);
// If an answer was received from QnA Maker, send the answer back to the user.
if (qnaResults[0]) {
await context.sendActivity(qnaResults[0].answer);
// If no answers were returned from QnA Maker, show this reply.
// Note: .getAnswers() does NOT return the default answer from the App Service's Application Settings
} else {
const defaultAnswer = 'No QnA Maker answers were found. This example uses a QnA Maker Knowledge Base that focuses on smart light bulbs. To see QnA Maker in action, ask the bot questions like "Why won\'t it turn on?" or "I need help."'
await context.sendActivity(defaultAnswer);
}
When creating an Azure Web Bot, one of the default Web Chat clients is a fork of microsoft's BotBuilder-Samples project, specifically 49 - QnAMaker All Features
The source code for Dialog/QnAMakerBaseDialog.cs defines the constant DefaultNoAnswer:
public const string DefaultNoAnswer = "No QnAMaker answers found.";
And then uses that value when returning a response from GetQnAResponseOptionsAsync:
protected async override Task<QnADialogResponseOptions> GetQnAResponseOptionsAsync(DialogContext dc)
{
var noAnswer = (Activity)Activity.CreateMessageActivity();
noAnswer.Text = DefaultNoAnswer; // <- used right here
var cardNoMatchResponse = (Activity)MessageFactory.Text(DefaultCardNoMatchResponse);
var responseOptions = new QnADialogResponseOptions
{
ActiveLearningCardTitle = DefaultCardTitle,
CardNoMatchText = DefaultCardNoMatchText,
NoAnswer = noAnswer,
CardNoMatchResponse = cardNoMatchResponse,
};
return responseOptions;
}
This particular sample repo doesn't appear to leverage the DefaultAnswer configuration key anywhere.
You can opt to include it when available by updating the noAnswer.Text like this:
- noAnswer.Text = DefaultNoAnswer;
+ noAnswer.Text = this._configuration["DefaultAnswer"] ?? DefaultNoAnswer;
You'll also have to pass in the configuration object through the dependency management system. See this commit for a full example.
Change the line in qamakerBaseDialog.js as below
var noAnswer = ActivityFactory.DefaultNoAnswer;
Remove ActivityFactory. and rebuild the code.
constructor(knowledgebaseId, authkey, host) {
//ActivityFactory.
var noAnswer = DefaultNoAnswer;
var filters = [];
super(knowledgebaseId, authkey, host, noAnswer, DefaultThreshold, DefaultCardTitle, DefaultCardNoMatchText,
DefaultTopN, ActivityFactory.cardNoMatchResponse, filters, QNAMAKER_BASE_DIALOG);
this.id = QNAMAKER_BASE_DIALOG;
}

dialogflow Webhookclient "request_" property

I am trying to build up a facebook messenger chatbot using Dialogflow. In the dialogflow fulfillment inline editor, I found that I can use agent.request_.body to get the body of the request. I assume "request_" is a property of WebhoodClient object? But I couldn't find any documentation elaborate that, could you please advise if my understanding is correct and where I can find the reference or documentation?
const agent = new WebhookClient({ request, response });
console.log(JSON.stringify(agent.request_.body));
Thanks
Google provides documentation for Dialogflow webhooks here, which include this sample webhook to inspect parameters and dynamically create slot filling prompts:
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
const agent = new WebhookClient({ request, response });
function flight(agent) {
const city = agent.parameters['geo-city'];
const time = agent.parameters['time'];
const gotCity = city.length > 0;
const gotTime = time.length > 0;
if(gotCity && gotTime) {
agent.add(`Nice, you want to fly to ${city} at ${time}.`);
} else if (gotCity && !gotTime) {
agent.add('Let me know which time you want to fly');
} else if (gotTime && !gotCity) {
agent.add('Let me know which city you want to fly to');
} else {
agent.add('Let me know which city and time you want to fly');
}
}
let intentMap = new Map();
intentMap.set('flight', flight);
agent.handleRequest(intentMap);
});
My guess would be to add
console.log(agent);
right before defining the flight function, then checking the logs to see which objects agent contains, then adding iterations of console.log(agent.fakeObjectName) until you find the information you're looking for.
If you're following the deployment process recommended in Actions on Google's Codelabs level 2, your logs will show up in the Firebase console, like this:
Hope that helps!
Just a note.
I had a code similar to this:
const city = agent.parameters['geo-city'];
There is an icon that suggest it's better written in dot notation.
that is gone after I changed it to:
const city = agent.parameters.geo-city;

args not returning expected LUIS result after implementing BotAuth

I have been creating a chat bot with MS Bot Framework in Nodejs and LUIS. I am recently trying to get certain information from the MS Graph API, and have (sort of) successfully implemented BotAuth and am able to get the information I want.
The issue I am facing now is that for the dialog that implements BotAuth, I am not able to get the usual args that comes with LUIS-intents triggered dialogs. Thus, I am not able to get any entities that the user might have entered. Other dialogs that do not implement BotAuth have no issues with this.
What I am getting now from args is:
{ response: undefined, resumed: 4 }
I am guessing that the issue lies with the [].concat part in this section:
bot.dialog('refreshSchDialog-oauth', [].concat(
ba.authenticate("aadv2"),
(session, args, skip) => {
let user = ba.profile(session, "aadv2");
session.endDialog(user.displayName);
session.userData.accessToken = user.accessToken;
session.userData.refreshToken = user.refreshToken;
console.log('args');
console.log(args);
if (user.accessToken) {
session.send('got leh');
// valid access token, check if luis has any entities (MV name)
// if there is, store conversationData and move to next dialog
if (args.entities) {
for (i = 0; i < args.entities.length; i++) {
if (args.entities[i].type == 'dbName') {
session.conversationData.mvName = args.entities[i].entity;
session.send(args.entities[i].entity);
}
}
}
session.beginDialog('refreshSchDialog');
} else {
// no valid access token
// TODO error message
}
}))
.triggerAction({
matches: 'refreshSchema',
intentThreshold: 0.3
});
May I know why the args is not returning the information from LUIS?
Looking at the BotAuth code it appears that the Auth dialog returns the user if properly authenticated or false if the dialog failed. It doesn’t copy over the args from LUIS. I would change your code so that the first function in your waterfall stores the LUIS data into session.dialogData, then call ba.authenticate and then use both results in your last waterfall step.

Resources