在Bot Framework中向Hero Cards发送附件列表

时间:2017-08-10 07:53:16

标签: c# botframework

我想在一张英雄卡中显示特定医生的Sessions并将其发送给机器人。

这是代码

private async Task ShowSessionsHeroCard(IDialogContext context)
    {
        var replyToConversation = context.MakeMessage();
        replyToConversation.AttachmentLayout = AttachmentLayoutTypes.Carousel;
        replyToConversation.Attachments = GetSessionHeroCard();
        await context.PostAsync(replyToConversation);
    }

private Attachment GetSessionHeroCard()
    {
        var heroCard = new HeroCard();
        foreach (var sessionDetails in scheduleList)
        {
            string[] session = GetSplittedDetails(sessionDetails);

            string hospitalName = session[0]; //Hospital Name: {0}
            string availableDay = session[1]; //Available Day: {1}
            string appointmentNo = session[2]; // Appoinment No: {2}
            string sessionAvailable = session[3]; // Session: {3}

            heroCard.Title = hospitalName;
            heroCard.Subtitle = availableDay;
            heroCard.Text = sessionAvailable + appointmentNo;
        }
        return heroCard.ToAttachment();
    }


private string[] GetSplittedDetails(string sessionDetails)
    {
        return sessionDetails.Split(',');
    }

当我做回复ToConversation.Attachments = GetSessionHeroCard();

我收到以下错误

Cannot implicitly convert type 'Microsoft.Bot.Connector.Attachment' to 'System.Collections.Generic.List<Microsoft.Bot.Connector.Attachment>'

请帮我解决这个问题。我挣扎着几个小时。在此先感谢:)

1 个答案:

答案 0 :(得分:4)

Attachments属性为List<Attachment>,这就是您看到错误的原因,您尝试将附件分配给列表。

你可以这样做:

replyToConversation.Attachments = new List<Attachment>();
replyToConversation.Attachments.Add(GetSessionHeroCard());