How to add LUIS intent in bot framework locally? - node.js

I am developing a chatbot using bot framework. I have already developed a basic Node Echo Bot and also basic QnA Bot. I am currently developing a LUIS bot of which i already created an intents on luis.ai. I have created the bot on Azure and downloaded the source code. Now, my instructor asked me to develop a bot that works with the LUIS app. How can I do this?

I'm not entirely sure that I understand your unedited question, so I will answer it for both of the two ways that I interpret it.
Add LUIS to a Bot
See the Core Bot Sample for reference.
Add your LUIS connection information to your .env file
MicrosoftAppId=
MicrosoftAppPassword=
LuisAppId=<AddMe>
LuisAPIKey=<AddMe>
LuisAPIHostName=<AddMe>
Instantiate a LuisRecognizer
const recognizer = new LuisRecognizer({
applicationId: process.env.LuisAppId,
endpointKey: process.env.LuisAPIKey,
endpoint: `https://${ process.env.LuisAPIHostName }`
}, {}, true);
Get the result and intent of user input
const recognizerResult = await recognizer.recognize(context);
const intent = LuisRecognizer.topIntent(recognizerResult);
Note: Core Bot does all of this in luisHelper.js. It then calls it with something like bookingDetails = await LuisHelper.executeLuisQuery(this.logger, stepContext.context);. You can do this, too. An alternative method, if you want to get the intent of every user message, is to include steps 2 and 3 (recognizer, recognizerResult, intent) in onMessage(), instead.
Additional Note: If you want to start with LUIS from a pre-built sample, the following samples use LUIS:
Core Bot
NLP with Dispatch
Virtual Assistant
Run LUIS Locally
Follow the LUIS Container How-To to run LUIS out of a Docker Container.
Basically, instead of querying your app on luis.ai, you set your bot up to query your docker container, which is running an exported, containerized version of your LUIS app. If you need to improve the app's prediction accuracy after your bot's been running awhile, you re-upload the query logs from your container back to LUIS.
It's a pretty difficult and extensive tutorial, so there's no point in me posting it here. If you run into trouble, feel free to open a new Stack Overflow ticket.

Related

How to set confidence score settings/score threshold to 60% in qna maker azure web app bot using node.js

I have created a web app bot for qna maker knowledge base in azure using node.js.
Now I want my bot to give answers from knowledge base whose score is above 60%.
For the answers below 60% the bot has to give the default answer.
For this I tried changing the default parameters value in online code editor as shown below.
But on changing the const DefaultThreshold = 0.6 and running deploy.cmd in console. My bot gives same answer as previous.
How to make the bot to reply only if score is above 60%.
You can specify a minimum confidence score via the scoreThreshold option in a QnAMakerOption.
See the botbuilder-js repo for what options are available in QnAMakerOptions, including scoreThreshold.
Now where you could actually pass in the QnAMakerOptions, to ensure your answers have at least 60% confidence, you have a couple of options:
In the constructor of creating a new QnAMaker instance:
const endpoint = {
knowledgeBaseId: process.env.QnAKnowledgebaseId,
endpointKey: process.env.QnAEndpointKey,
host: process.env.QnAEndpointHostName
};
const options = { scoreThreshold: .6 };
const qna = new QnAMaker(endpoint, options);
Pass in QnAMakerOptions when you call QnAMaker.getAnswers() method:
const qna = new QnAMaker(endpoint);
const options = { scoreThreshold: .6 }
const qnaResults = await qna.getAnswers(context, options); // context is the TurnContext received in the callback of your bot's message handler
See sample 11.qnamaker in the official BotBuilder-Samples repo for basics on how to set up a QnA Maker bot. To deploy local changes to Azure (if you have the bot locally and aren't just using the online web editor to update your bot), follow Deploy your bot docs.
In the sample it just returns "No QnA Maker answers were found" if no QnA Maker answers were found within the scoreThreshold, but you could easily change this to instead send your desired default answer.

Multi Tenancy in Microsoft bot framework webchat

I have successfully hosted an instance of microsoft's Botframework web chat using directline on public domain, I want to make a chatbot in such a way that my customers can have their own channels completely separated from each other and I cannot find any kind of documentation anywhere, Kindly suggest me if this is possible and how?
I have written the complete code in Node.js and have very less idea about c#.
It seems that there is no such feature for uniform customized chat channel in bot framework. So we can leverage new builder.Message().address(address) to send messages to specific users from the official sample at https://github.com/Microsoft/BotBuilder-Samples/blob/master/Node/core-proactiveMessages/simpleSendMessage/index.js.
So I had a quick test which will save the users' addresses into an address list in server memory as a "customize channel", and trigger a key work to send message to these addresses in list as a broadcast in this "customize channel":
let channel_address = [];
bot.dialog('joinChannel',(session)=>{
channel_address.push(session.message.address);
}).triggerAction({
matches:/join/i
})
bot.dialog('broadcast',(session)=>{
channel_address.forEach((address)=>{
bot.send(
new builder.Message(session).address(address).text(session.message.text)
)
})
}).triggerAction({
matches:/^broadcast: .*/
})
Test Step:
Open two emulators connect to your local bot
in both emulators, type "join"
in either emulator, type text like broadcast: hi there

Create bot that supports two LUIS apps in Microsoft Bot Framework

I need to make a bilingual bot using Node.js and Microsoft Bot Framework. The bot uses LUIS for natural language.
I use the standard way to plug in LUIS:
// Create bot, send welcome message:
let bot = new builder.UniversalBot(connector, NoneIntentHandler);
// Plug in LUIS:
bot.recognizer(new builder.LuisRecognizer(config.luis.url));
However, I need to support two languages, English and Chinese. It's not a problem for me to detect a language. I have two separate LUIS apps, one for English and one for Chinese, and they return the same intents and entities.
But the problem is how to dynamically switch between two different apps, depending on the language of the user's input. The bot.recognizer doesn't accept two URLs or any other parameters. So it seems there is no built in support for that.
Is there some way to dynamically kill and recreate the bot object with another recognizer? Or reassign the recognizer depending on the LUIS language? Or any other way to do it?
You can try the following:
var recognizer1 = new builder.LuisRecognizer('<model 1>');
var recognizer2 = new builder.LuisRecognizer('<model 2>');
var intents = new builder.IntentDialog({ recognizers: [recognizer1, recognizer2] });

Bot framework to work with LUIS intent & match intent & pro-active dialog

I've built a bot using LUIS framework which works fine.
while working on it came through few points as mentioned below
After connecting with LUIS intent; bot is unable to check with regex intents
like
for ex dialog.matches('^helpdesk/i',function()) which i'm trying to setup
var dialog = new builder.IntentDialog({ recognizers: [recognizer] });
How to proactively send greetings message to user before inititates conversation like i would send prompt of choices to user which user can select. If nothing is fitting to that requirement i want LUIS to work and understand on that
How to know the logged in user context in Skype for Business channel
cards are not working in skype for business
For your code; I'm assuming your recognizer is your only IntentRecognizer and is the LUIS model you mention.
In this case, dialog.matches('^helpdesk/i',function()) is incorrect; your code to match against a regex should be dialog.matches(/^helpdesk/i, function())
Alternatively you could add a RegExpRecognizer to your IntentDialog:
var helpdesk = new builder.RegExpRecognizer('HelpDeskIntent', /^helpdesk/i);
var dialog = new builder.IntentDialog({ recognizers: [helpdesk, recognizer] });
As Bob said you're looking for conversationUpdate, here's an example on it sending a message when a user joins
To clarify, is this a question on having your bot know when a user is logged in? Or are you asking about session.userData?
Skype for Business does not currently support cards.
You can catch when the user is added to conversation. Check conversation.update.
Each activity has its own properties. One of them is serviceUrl.
For the third question, please provide your code.

How to detect when bot was added to conversation and other events?

I am testing a bot that I am building using the Bot Framework. The emulator for local testing that Microsoft created has several events that can be provided to the bot to solicit a response.
I looked at the GitHub samples provided for Node.js here, but I can not find any example that responds to the different events within the Bot Framework Emulator.
The states are:
Bot Added to Conversation
Bot Removed from Conversation
User Added to Conversation
User Removed from Conversation
End of Conversation
Ping
Delete User Data
The API also does not make it clear how to achieve any of these actions.
Does anyone have any insight on where I should be looking for a example, or the API entries that I should be using?
In response to one of the answers, I did try code -
.onDefault(function (session) { console.log(session.message.type); }
But it only ever display "message" if a message was sent by the user.
The incoming message.type field will have "BotAddedToConversation" etc.
For the Node SDK, the botConnectorBot is able to trigger custom listeners on events using the on() handler.
Example
var builder = require('botbuilder');
var bot = new builder.BotConnectorBot({ appId: 'APPID', appSecret: 'APPSECRET' });
bot.on('DeleteUserData', function(message) {
// Handle Deleting User Data
});
More information can be found here.
You are also able to configure some standard messages using the configure() method.
Example
bot.configure({
userWelcomeMessage: "Hello... Welcome to the group.",
goodbyeMessage: "Goodbye..."
});
More information on what can be configured through options is located here.
Concerns
This is not part of the question, as the question was to identify how to listen to these events. But as a general concern, the event listener does not return a session object. It is unclear how to act once you handle the event.

Resources