I'm facing an issue whereby unable to use triggerAction to match with luis intent when inside the prompt choice. For my current code, triggerAction will begin the dialog if word(s) keyed by user matches exact statement that I hardcoded such as "Card1".
When user reaches card2 dialog it will display message follow by a dialog (Card2Link) that contain the prompt question and choices.
Desired: If the user decides that he/she wants to type a random word(s) which should try to match with luis intent and trigger the intent dialog. If the random word(s) does not fit into any of the luis intents or none luis intent, it will trigger "please pick your choice again".
Actual: When user type random word(s), it does not search through luis intent and instantly provide with the error msg "Please pick your choice. 1. Card3".
Please advise on the issue. I have been stuck with this issue for quite some time.
var restify = require('restify');
var builder = require('botbuilder');
var botbuilder_azure = require("botbuilder-azure");
var server = restify.createServer();
server.listen(process.env.port || process.env.PORT || 3978, function () {
console.log('%s listening to %s', server.name, server.url);
});
var connector = new builder.ChatConnector({
appId: process.env.MicrosoftAppId,
appPassword: process.env.MicrosoftAppPassword,
openIdMetadata: process.env.BotOpenIdMetadata
});
server.post('/api/messages', connector.listen());
var tableName = 'dataBT';
var azureTableClient = new botbuilder_azure.AzureTableClient(tableName, process.env['AzureWebJobsStorage']);
var tableStorage = new botbuilder_azure.AzureBotStorage({ gzipData: false }, azureTableClient);
bot.beginDialogAction('Card1', '/Card1')
// Make sure you add code to validate these fields
var luisAppId = process.env.LuisAppId;
var luisAPIKey = process.env.LuisAPIKey;
var luisAPIHostName = process.env.LuisAPIHostName || 'westus.api.cognitive.microsoft.com';
const LuisModelUrl = 'https://' + luisAPIHostName + '/luis/v1/application?id=' + luisAppId + '&subscription-key=' + luisAPIKey;
// Main dialog with LUIS
var recognizer = new builder.LuisRecognizer(LuisModelUrl);
var intents = new builder.IntentDialog({ recognizers: [recognizer] })
.matches('Card1', (session) => {
session.beginDialog('/Card1')
})
// Create your bot with a function to receive messages from the user
var bot = new builder.UniversalBot(connector);
bot.set('storage', tableStorage);
bot.dialog('/', intents);
bot.dialog('/cards', [
function (session) {
session.send('Test1');
var msg = new builder.Message(session)
.attachmentLayout(builder.AttachmentLayout.carousel)
.textFormat(builder.TextFormat.xml)
.attachments([
new builder.HeroCard(session)
.title('Test1')
.images([
builder.CardImage.create(session, 'imgURL')
])
.buttons([builder.CardAction.dialogAction(session, 'Card1', null, 'Here')
])
]);
msg.addAttachment (
new builder.HeroCard(session)
.title("Test2")
.images([
builder.CardImage.create(session, "imgUrl")
])
.buttons([
builder.CardAction.dialogAction(session, "Card2", null, "Here")
])
);
session.endDialog(msg)
}
]).triggerAction({ matches: /^hi/i });
//Adding of new card
bot.dialog('/Card1', [
function (session) {
var msg1 = new builder.Message(session).sourceEvent({
//specify the channel
facebook: {
text:"Card1"
}
});
session.endDialog(msg1)
session.beginDialog('/card1link');
}
]).triggerAction({ matches: /^Card1/i });
bot.dialog('/card1link', [
function (session, args, next) {
builder.Prompts.choice(session, '1. Card2\n2. Card3\n', ['1', '2'], {
retryPrompt: "Please pick your choice.\n1. Card2\n2. Card3\n",
maxRetries: 1
});
},
function (session, args, next) {
if (args.response) {
var choice = args.response.entity;
switch (choice) {
case '1':
session.replaceDialog('Card2');
break;
case '2':
session.replaceDialog('Card3');
break;
}
}
else{
session.send("Sorry");
}
}
]);
bot.dialog('/Card2', [
function (session) {
var msg1 = new builder.Message(session).sourceEvent({
//specify the channel
facebook: {
text:"Card2"
}
});
session.endDialog(msg1)
session.beginDialog('/card2link');
}
]).triggerAction({ matches: /^Card2/i });
bot.dialog('/card2link', [
function (session, args, next) {
builder.Prompts.choice(session, '1. Card3\n', ['1'], {
retryPrompt: "Please pick your choice.\n1. Card3\n",
maxRetries: 1
});
},
function (session, args, next) {
if (args.response) {
var choice = args.response.entity;
switch (choice) {
case '1':
session.replaceDialog('Card3');
break;
}
}
else{
session.send("Sorry");
}
}
]);