我有一个Bot,我启用了Facebook频道。当我使用自适应卡片的轮播向用户发送回复时......
Failed with error: Microsoft.Rest.HttpOperationException: SendActivityToUserAsync FAILED: {"error":{"message":"(#194) param name_placeholder[elements] has too few elements.","type":"OAuthException","code":194,"fbtrace_id":"EvKMopV4m\/J"}}
我尝试搜索错误消息,但无法找到任何答案。你能指点我正确的方向吗?
这就是我的附件:
[LuisIntent("GetAllCards")]
public async Task GetAllCards(IDialogContext context, LuisResult result)
{
var reply = context.MakeMessage();
reply.Text = "Here's a few sample of cards..."; //does not appear in facebook?
reply.Attachments = new List<Attachment>();
reply.AttachmentLayout = AttachmentLayoutTypes.Carousel;
if (context.ConversationData.GetValue<string>(ContextKeys.ChannelId) == "facebook")
{
await context.PostAsync("Here's a few sample of cards...");
}
using (var entities = new MyEntities())
{
var query = ...get stuff...
var cpList = query.ToList();
//each item is an attachment in carousel
foreach (var cp in cpList)
{
var card = GetSingleCard(cp);
var attachment = new Attachment()
{
Content = card,
ContentType = "application/vnd.microsoft.card.adaptive",
Name = cp.DisplayName //this does not actually appear anywhere on the bot when I tested
};
reply.Attachments.Add(attachment);
}
await context.PostAsync(reply);
}
private AdaptiveCard GetSingleCard(MyProduct cc)
{
var card = new AdaptiveCard();
card.Title = cc.DisplayName; //this is not shown anywhere in my bot test
//title
var title = new Container();
card.Body.Add(title);
var titleText = new TextBlock();
title.Items.Add(titleText);
titleText.Size = TextSize.Large;
titleText.Text = $"**{cc.Title}**";
var subTitleText = new TextBlock();
title.Items.Add(subTitleText);
subTitleText.Size = TextSize.Medium;
subTitleText.Text = cc.SubTitle;
subTitleText.Wrap = true;
subTitleText.MaxLines = 1;
//image
var cpImage = new AdaptiveCards.Image();
card.Body.Add(cpImage);
cpImage.Url = cc.ImageUrl;
cpImage.Size = ImageSize.Large;
//details
var details = new FactSet();
card.Body.Add(details);
details.Facts.Add(new AdaptiveCards.Fact("Customer Rating", cc.Rating);
details.Facts.Add(new AdaptiveCards.Fact("Detail A", cc.DetailA));
details.Facts.Add(new AdaptiveCards.Fact("Detail B", cc.DetailB));
var action = new OpenUrlAction();
action.Url = $"https://google.com";
action.Title = $"Read more";
card.Actions.Add(action);
return card;
}