【发布时间】:2020-01-27 07:50:21
【问题描述】:
我使用 c# 使用框架 v4 制作了机器人。我在其中集成了 luis 以实现退出功能,在我的机器人中,当用户键入 exit 时,它会将您从对话中带出,整个机器人将从存在开始。我的案例机器人能够退出但无法从存在开始。我以为我可以使用 CancelallDialogAsync 方法,但我无法在我为退出功能编写代码的 onturnasync 方法中访问它。
public override async Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken = default(CancellationToken))
{
var activity = turnContext.Activity;
// var activity = turnContext.Activity;
var recognizerResult = await _botServices.Dispatch.RecognizeAsync(turnContext, cancellationToken);
// Top intent tell us which cognitive service to use.
var topIntent = recognizerResult.GetTopScoringIntent();
var attachments = new List<Attachment>();
var reply = MessageFactory.Attachment(attachments);
reply.AttachmentLayout = AttachmentLayoutTypes.Carousel;
// First, we use the dispatch model to determine which cognitive service (LUIS or QnA) to use.
if (string.IsNullOrWhiteSpace(activity.Text) && activity.Value != null)
{
activity.Text = JsonConvert.SerializeObject(activity.Value);
}
if (turnContext.Activity.Text == "Yes")
{
await turnContext.SendActivityAsync($"Good bye. I will be here if you need me. ", cancellationToken: cancellationToken);
await turnContext.SendActivityAsync($"Say Hi to wake me up.", cancellationToken: cancellationToken);
}
else if (topIntent.intent == "OrderStatusintent")
{
reply.Attachments.Add(Cards.GetHeroCard6().ToAttachment());
await turnContext.SendActivityAsync(reply, cancellationToken);
}
else if (topIntent.intent == "Exitintent")
{
await turnContext.SendActivityAsync($"Good bye. Say Hi if you need more help.", cancellationToken: cancellationToken);
}
else if (activity.ChannelId != "webchat")
{
await base.OnTurnAsync(turnContext, cancellationToken);
}
await ConversationState.SaveChangesAsync(turnContext, false, cancellationToken);
await UserState.SaveChangesAsync(turnContext, false, cancellationToken);
}
【问题讨论】:
-
我没有这样做,但听起来你可以使用主动消息传递和基于计时器的功能来实现这一点。有人可能有他们为此使用的模板,但如果您可以尝试解决方案,然后让我们知道您在实施该解决方案时遇到了什么困难,那么您将更有幸获得回复。
标签: c# asp.net botframework azure-language-understanding qnamaker