当我在瀑布对话框中使用自适应卡片的输入形式时,ContinueDialogAsync 不起作用
ContinueDialogAsync does not work when I use the input form of adaptive-cards in the waterfall dialog
我一直在使用 EchoBot 模板,最近使用了 VirtualAssistant 模板。在之前的模板中,提交输入表单数据是没有问题的,但是这个模板仅仅通过提交输入表单数据就无法使用ContinueDialogAsync。我们如何解决这个问题?请帮助我。
WaterfallStep的输入形式
card.Body.Add(new AdaptiveTextBlock()
{
HorizontalAlignment = AdaptiveHorizontalAlignment.Left,
Spacing = AdaptiveSpacing.None,
Size = AdaptiveTextSize.Small,
Weight = AdaptiveTextWeight.Bolder,
Color = AdaptiveTextColor.Accent,
Text = Common.PurchaseDialog_DepartureDate
});
card.Body.Add(new AdaptiveDateInput()
{
Id = "GoDateVal",
Value = DateTime.Now.AddDays(4).ToString("yyyy-MM-dd"),
Spacing = AdaptiveSpacing.None
});
if (lowestPriceQuery.tripType == "RT")
{
card.Body.Add(new AdaptiveTextBlock()
{
HorizontalAlignment = AdaptiveHorizontalAlignment.Left,
Spacing = AdaptiveSpacing.None,
Size = AdaptiveTextSize.Small,
Weight = AdaptiveTextWeight.Bolder,
Color = AdaptiveTextColor.Accent,
Text = Common.PurchaseDialog_CommingDate
});
card.Body.Add(new AdaptiveDateInput()
{
Id = "ComeDateVal",
Value = DateTime.Now.AddDays(8).ToString("yyyy-MM-dd"),
Spacing = AdaptiveSpacing.None,
});
}
if (lowestPriceQuery.tripType == "DS")
{
card.Body.Add(new AdaptiveTextBlock()
{
HorizontalAlignment = AdaptiveHorizontalAlignment.Left,
Spacing = AdaptiveSpacing.None,
Size = AdaptiveTextSize.Small,
Weight = AdaptiveTextWeight.Bolder,
Color = AdaptiveTextColor.Accent,
Text = "ReturnDate"
});
card.Body.Add(new AdaptiveDateInput()
{
Id = "ComeDateVal",
Value = DateTime.Now.AddDays(8).ToString("yyyy-MM-dd"),
Spacing = AdaptiveSpacing.None,
});
}
card.Actions.Add(new AdaptiveSubmitAction()
{
Type = AdaptiveSubmitAction.TypeName,
Title = "submit",
Id = "submit",
});
reply.Attachments = new List<Attachment>
{
new Attachment()
{
ContentType = "application/vnd.microsoft.card.adaptive",
Content = JsonConvert.DeserializeObject(JsonConvert.SerializeObject(card))
}
};
await turnContext.SendActivityAsync(reply, cancellationToken: cancellationToken);
DilaogBot,
调试时,从输入表单提交时 var result = await dc.ContinueDialogAsync ();
没有任何反应。
var dc = await _dialogs.CreateContextAsync(turnContext);
if (turnContext.Activity.Type == ActivityTypes.Message)
{
// Ensure that message is a postBack (like a submission from Adaptive Cards)
var channelData = JObject.Parse(dc.Context.Activity.ChannelData.ToString());
if (channelData.ContainsKey("postback"))
{
var postbackActivity = dc.Context.Activity;
// Convert the user's Adaptive Card input into the input of a Text Prompt
// Must be sent as a string
postbackActivity.Text = postbackActivity.Value.ToString();
await dc.Context.SendActivityAsync(postbackActivity);
}
}
if (dc.ActiveDialog != null)
{
var result = await dc.ContinueDialogAsync();
}
else
{
await dc.BeginDialogAsync(typeof(T).Name);
}
您需要删除:
await dc.Context.SendActivityAsync(postbackActivity);
当机器人发送消息时,它会将对话标记为已响应并且不会继续适当地继续。
此外,您的“//Ensure message is a PostBack”代码应该更像这样:
var activity = turnContext.Activity;
if (activity.Type == ActivityTypes.Message)
{
if (string.IsNullOrWhiteSpace(activity.Text) && activity.Value != null)
{
activity.Text = JsonConvert.SerializeObject(activity.Value);
}
}
我相信你是从我的一个旧答案中得到的代码,我已经改进了它。
我一直在使用 EchoBot 模板,最近使用了 VirtualAssistant 模板。在之前的模板中,提交输入表单数据是没有问题的,但是这个模板仅仅通过提交输入表单数据就无法使用ContinueDialogAsync。我们如何解决这个问题?请帮助我。
WaterfallStep的输入形式
card.Body.Add(new AdaptiveTextBlock()
{
HorizontalAlignment = AdaptiveHorizontalAlignment.Left,
Spacing = AdaptiveSpacing.None,
Size = AdaptiveTextSize.Small,
Weight = AdaptiveTextWeight.Bolder,
Color = AdaptiveTextColor.Accent,
Text = Common.PurchaseDialog_DepartureDate
});
card.Body.Add(new AdaptiveDateInput()
{
Id = "GoDateVal",
Value = DateTime.Now.AddDays(4).ToString("yyyy-MM-dd"),
Spacing = AdaptiveSpacing.None
});
if (lowestPriceQuery.tripType == "RT")
{
card.Body.Add(new AdaptiveTextBlock()
{
HorizontalAlignment = AdaptiveHorizontalAlignment.Left,
Spacing = AdaptiveSpacing.None,
Size = AdaptiveTextSize.Small,
Weight = AdaptiveTextWeight.Bolder,
Color = AdaptiveTextColor.Accent,
Text = Common.PurchaseDialog_CommingDate
});
card.Body.Add(new AdaptiveDateInput()
{
Id = "ComeDateVal",
Value = DateTime.Now.AddDays(8).ToString("yyyy-MM-dd"),
Spacing = AdaptiveSpacing.None,
});
}
if (lowestPriceQuery.tripType == "DS")
{
card.Body.Add(new AdaptiveTextBlock()
{
HorizontalAlignment = AdaptiveHorizontalAlignment.Left,
Spacing = AdaptiveSpacing.None,
Size = AdaptiveTextSize.Small,
Weight = AdaptiveTextWeight.Bolder,
Color = AdaptiveTextColor.Accent,
Text = "ReturnDate"
});
card.Body.Add(new AdaptiveDateInput()
{
Id = "ComeDateVal",
Value = DateTime.Now.AddDays(8).ToString("yyyy-MM-dd"),
Spacing = AdaptiveSpacing.None,
});
}
card.Actions.Add(new AdaptiveSubmitAction()
{
Type = AdaptiveSubmitAction.TypeName,
Title = "submit",
Id = "submit",
});
reply.Attachments = new List<Attachment>
{
new Attachment()
{
ContentType = "application/vnd.microsoft.card.adaptive",
Content = JsonConvert.DeserializeObject(JsonConvert.SerializeObject(card))
}
};
await turnContext.SendActivityAsync(reply, cancellationToken: cancellationToken);
DilaogBot,
调试时,从输入表单提交时 var result = await dc.ContinueDialogAsync ();
没有任何反应。
var dc = await _dialogs.CreateContextAsync(turnContext);
if (turnContext.Activity.Type == ActivityTypes.Message)
{
// Ensure that message is a postBack (like a submission from Adaptive Cards)
var channelData = JObject.Parse(dc.Context.Activity.ChannelData.ToString());
if (channelData.ContainsKey("postback"))
{
var postbackActivity = dc.Context.Activity;
// Convert the user's Adaptive Card input into the input of a Text Prompt
// Must be sent as a string
postbackActivity.Text = postbackActivity.Value.ToString();
await dc.Context.SendActivityAsync(postbackActivity);
}
}
if (dc.ActiveDialog != null)
{
var result = await dc.ContinueDialogAsync();
}
else
{
await dc.BeginDialogAsync(typeof(T).Name);
}
您需要删除:
await dc.Context.SendActivityAsync(postbackActivity);
当机器人发送消息时,它会将对话标记为已响应并且不会继续适当地继续。
此外,您的“//Ensure message is a PostBack”代码应该更像这样:
var activity = turnContext.Activity;
if (activity.Type == ActivityTypes.Message)
{
if (string.IsNullOrWhiteSpace(activity.Text) && activity.Value != null)
{
activity.Text = JsonConvert.SerializeObject(activity.Value);
}
}
我相信你是从我的一个旧答案中得到的代码,我已经改进了它。