Reputation: 11
I am trying to achieve something similar to what has been done on this topic Begin Dialog with QnA Maker Bot Framework recognizer (Node JS)
The suggestion works as per having the bot sending first a welcome message, then waiting for the questions. However the bot now Says 'Hj! How can I help you?", waits for the questions, then it comes back to the welcome again.
Something like
A: Hi! How can I help you? Q: What is the number for Car repair A: Call 500-XXXX etc.. Q: Who should I contact for vacation days? A: Hi! How can I help you?
I played with beginDialog, End conversation, replace conversation.. however with no luck.
This is the latest code.
bot.dialog('/', [
function (session ) {
session.beginDialog('/welcome');
},
function (session) {
session.beginDialog('/qna');
}
]) ;
bot.dialog('/welcome', [
function (session) {
// Send a greeting and show help.
builder.Prompts.text(session, "Hi! How can I help you?");
// session.endDialog();
}
]);
bot.dialog('/qna', basicQnAMakerDialog ) ;
Upvotes: 1
Views: 1417
Reputation: 4635
Here's a code example showing how to listen for the conversationUpdate
event that is fired when a new user connects to the bot. Aka the "welcome message":
// Listen for 'conversationUpdate' event to detect members joining conversation.
bot.on('conversationUpdate', function (message) {
if (message.membersAdded) {
message.membersAdded.forEach(function (identity) {
if (identity.id == message.address.bot.id) {
// Bot is joining conversation
// - For WebChat channel you'll get this on page load.
var reply = new builder.Message()
.address(message.address)
.text("Welcome to my page");
bot.send(reply);
} else {
// User is joining conversation
// - For WebChat channel this will be sent when user sends first message.
// - When a user joins a conversation the address.user field is often for
// essentially a system account so to ensure we're targeting the right
// user we can tweek the address object to reference the joining user.
// - If we wanted to send a private message to teh joining user we could
// delete the address.conversation field from the cloned address.
var address = Object.create(message.address);
address.user = identity;
var reply = new builder.Message()
.address(address)
.text("Hello %s", identity.name);
bot.send(reply);
}
});
}
});
Upvotes: 1