使用Json文件开发Hero Card / Video Card

时间:2019-01-22 07:28:43

标签: azure chatbot

chat

如何通过阅读Json文件来开发Hero卡,请共享任何github网址。
我遵循了其中一个链接,并尝试在我的解决方案中实施。在Bot模拟器中进行测试时,我得到了空白卡。

https://docs.microsoft.com/en-us/microsoftteams/platform/concepts/cards/cards-reference#example-1

我的json文件在下面给出

{
  "contentType": "application/vnd.microsoft.card.hero",
  "content": {
    "title": "story telling",
    "subtitle": "story telling",
    "text": "You can’t be an effective leader unless people trust you. And a good way to build trust is by telling stories, because it builds credibility and relationships.",
    "images": [
      {
        "url": "https://imp.SP2013.tp.com/sites/learn/SiteAssets/test.jpg"
      }
    ],
    "buttons": [
      {
        "type": "openUrl",
        "title": "Official website for story telling",
        "value": "www.google.com"
      },
      {
        "type": "openUrl",
        "title": "Wikipeda page",
        "value": "www.google.com"
      }
    ]
  }
}

1 个答案:

答案 0 :(得分:0)

使用以下方法读取和解析JSON。我正在使用它,效果很好:

private HeroCard ParseHeroCard()
        {
            string url = (string)response["content"]["buttons"][0]["value"];
            Debug.Write(url);
            HeroCard card = new HeroCard
            {
                Title = (string)response["content"]["title"],
                Subtitle = "test",
                Text = (string)response["content"]["text"]
            };
            card.Buttons = new List<CardAction>
            {
                new CardAction(ActionTypes.OpenUrl, "Learn More", value: url)
            };

            card.Images = new List<CardImage>
            {
                new CardImage(url = (string)response["content"]["images"][0]["url"])
            };
            return card;
        }