我已经编写了基于在bot框架中使用LUIS进行意图匹配来发送消息的代码。 这是我的代码。
[LuisIntent("Skype for Business")]
public async Task Skype4Business(IDialogContext context, LuisResult result)
{
var connector = new ConnectorClient(new Uri(context.Activity.ServiceUrl));
try
{
// return our reply to the user
List<CardImage> cardImageList = new List<CardImage>();
List<CardAction> buttons = new List<CardAction>();
CardImage cardImage = new CardImage { Alt = "SpeechPic", Url = @"C:\Users\Rock\Documents\Visual Studio 2015\Projects\Text Analytics\Text Analytics\Resources\Skype-for-business-2.jpg" };
cardImages = new List<CardImage>();
cardImages.Add(cardImage);
CardAction skypeButton = new CardAction()
{
Value = "example.com/",
Type = "openUrl",
Title = "Skype for Business"
};
buttons.Add(skypeButton);
HeroCard heroCard = new HeroCard()
{
Title = "Skype For Business",
Images = cardImages,
Buttons = buttons
};
var message = context.MakeMessage();
message.Attachments = new List<Attachment>();
message.AttachmentLayout = AttachmentLayoutTypes.List;
message.Attachments.Add(heroCard.ToAttachment());
await context.PostAsync(message);
context.Wait(MessageReceived);
}
所以每当我发送机器人的回复时,如果意图匹配,例如:Skype for business。所以我通过制作卡片并在其中添加cardimage和按钮来回复。它发送没有任何错误但发送成功后它也显示异常。
我被困在这里,即使我已经添加了try / catch子句来处理异常,但我仍然得到异常。 怎么解决这个? 任何帮助或指导将不胜感激。
答案 0 :(得分:0)
问题是,您似乎有一个全局变量cardImages
,因此,您遇到了序列化问题,因为CardImage
不可序列化。
您有两张卡片图片列表:
List<CardImage> cardImageList = new List<CardImage>();
cardImages = new List<CardImage>();
您应该使用您在方法范围(cardImageList
)中创建的图像列表而不是全局变量。确保也删除全局变量。