共用方式為


機器人開發者的自適應卡

自適應卡非常適合機器人。 他們讓你只寫一張卡片,就能在多個應用程式中漂亮地呈現,例如 Microsoft Teams、你自己的網站等等。

備註

目前預覽版不支援 Skype。 最新資訊 請參閱合作夥伴狀態 頁面。

機器人框架整合

有了 Bot Framework ,你可以寫一個能跨多個「管道」與使用者聊天的單一機器人,例如 Skype、Microsoft Teams、Facebook Messenger 等。

操作指南

在你的機器人中加入自適應卡相當簡單。

步驟0:從一個基本訊息開始

這是一個標準的 Bot Framework message 資料包,可以傳送到任何通道,並向使用者顯示文字。

{
   "type": "message",
   "text": "Plain text is ok, but sometimes I long for more..."
}

步驟 1:新增自適應卡 attachment

為了增添除了純文字以外的豐富性,機器人框架中還有一個稱為attachments的概念。

我們來附加一張顯示自訂文字的自適應卡。

基本自適應卡

{
  "type": "message",
  "text": "Plain text is ok, but sometimes I long for more...",
  "attachments": [
    {
      "contentType": "application/vnd.microsoft.card.adaptive",
      "content": {
        "type": "AdaptiveCard",
        "version": "1.0",
        "body": [
          {
            "type": "TextBlock",
            "text": "Hello World!",
            "size": "large"
          },
          {
            "type": "TextBlock",
            "text": "*Sincerely yours,*"
          },
          {
            "type": "TextBlock",
            "text": "Adaptive Cards",
            "separation": "none"
          }
        ],
        "actions": [
          {
            "type": "Action.OpenUrl",
            "url": "http://adaptivecards.io",
            "title": "Learn More"
          }
        ]
      }
    }
  ]
}

步驟二:打造更豐富的卡牌

自適應卡片提供的不僅僅是可自訂的文字。

您可以:

  • Images 加到你的卡片上
  • 使用ContainersColumns來組織你的內容
  • 加入多種類型的 Actions
  • 向用戶收集Input
  • 只拿一張牌 show another card
  • 快來看看完整的結構探索器吧!

平台 SDK

如果你的機器人是用 .NET 或 NodeJS 開發的,我們有函式庫讓建立 Adaptive Cards 變得更簡單。

平台 Install 瞭解詳情
.NET Install-Package AdaptiveCards -IncludePrerelease Bot Framework .NET 指南
NodeJS npm install adaptivecards 機器人框架 NodeJS 文件

頻道狀況

機器人框架允許你將機器人發佈到多個頻道。 我們正與多個管道合作,提供對 Adaptive Cards 的完整支援。 最新資訊 請參閱合作夥伴狀態 頁面。

全情投入!

我們在這個教程中只是觸及了表面的部分,請參考以下連結,以探索更多使用自適應卡來提升你的機器人的方法。