You use the Microsoft Bot Framework Composer to build a chatbot that enables users to purchase items. You need to ensure that the users can cancel in-progress t...


Microsoft AI-102 Exam

Questions Number: 196 out of 241 Questions
81.33%

Question 196
You use the Microsoft Bot Framework Composer to build a chatbot that enables users to purchase items.
You need to ensure that the users can cancel in-progress transactions. The solution must minimize development effort.
What should you add to the bot?



Handling interruptions is an important aspect of a robust bot. Users will not always follow your defined conversation flow, step by step. They may try to ask a question in the middle of the process, or simply want to cancel it instead of completing it.
Example:
If the user types "cancel", it calls CancelAllDialogsAsync on its inner dialog context, which clears its dialog stack and causes it to exit with a canceled status and no result value. To the MainDialog (shown later on), it will appear that the booking dialog ended and returned null, similar to when the user chooses not to confirm their booking. private async Task<DialogTurnResult> InterruptAsync(DialogContext innerDc, CancellationToken cancellationToken)
{
if (innerDc.Context.Activity.Type == ActivityTypes.Message)
{
var text = innerDc.Context.Activity.Text.ToLowerInvariant();
switch (text)
{
case "cancel":
case "quit":
var cancelMessage = MessageFactory.Text(CancelMsgText, CancelMsgText, InputHints.IgnoringInput); await innerDc.Context.SendActivityAsync(cancelMessage, cancellationToken); return await innerDc.CancelAllDialogsAsync(cancellationToken);
}
}
return null;
}
Reference:
https://docs.microsoft.com/en-us/azure/bot-service/bot-builder-howto-handle-user-interrupt





Previous Questions Next Questions



Premium Version