将可操作邮件卡片发布到 Office 365 组Post an actionable message card to an Office 365 group

创建可操作邮件卡Create an actionable message card

我们从创建可操作邮件卡开始。我们将从简单的内容开始,即一个包含 HttpPOST 操作和 OpenUri 操作的简单卡片。我们将使用卡片样本设计此卡片。Let's start by creating an actionable message card. We'll start with something simple, just a basic card with an HttpPOST action and an OpenUri action. We'll use the Card Playground to design the card.

重要

Office 连接器仅支持卡的 旧 MessageCard 格式Office connectors only support the legacy MessageCard format for cards. 它们不支持自适应卡格式。They do not support the Adaptive Card format.

转到卡片样本,并粘贴以下 JSON:Go to Card Playground and paste in the following JSON:

{
  "@context": "https://schema.org/extensions",
  "@type": "MessageCard",
  "themeColor": "0072C6",
  "title": "Visit the Outlook Dev Portal",
  "text": "Click **Learn More** to learn more about Actionable Messages!",
  "potentialAction": [
    {
      "@type": "ActionCard",
      "name": "Send Feedback",
      "inputs": [
        {
          "@type": "TextInput",
          "id": "feedback",
          "isMultiline": true,
          "title": "Let us know what you think about Actionable Messages"
        }
      ],
      "actions": [
        {
          "@type": "HttpPOST",
          "name": "Send Feedback",
          "isPrimary": true,
          "target": "http://..."
        }
      ]
    },
    {
      "@type": "OpenUri",
      "name": "Learn More",
      "targets": [
        { "os": "default", "uri": "https://docs.microsoft.com/outlook/actionable-messages" }
      ]
    }
  ]
}

请在样本中随意使用此简单示例进行试验。可参阅邮件卡片参考了解可用字段的详细信息。制作出满意的卡片后,就可以发送了。Feel free to experiment with this simple example in the playground. You can see the message card reference for details on the available fields. Once you have a card you're happy with, you can move on to sending it.

通过 Office 连接器发送可操作邮件Sending actionable messages via Office connectors

连接器使用 webhook 在 Office 365 组内创建“连接器卡片”邮件。开发人员可以通过向 Office 365 组 webhook 地址发送包含简单的 JSON 负载的 HTTP 请求来创建这些卡片。我们来尝试将一些简单的卡片发布到组。Connectors use webhooks to create Connector Card messages within an Office 365 group. Developers can create these cards by sending an HTTP request with a simple JSON payload to an Office 365 group webhook address. Let's try posting some basic cards to a group.

需要具备 Microsoft 365 订阅才能继续。You'll need an Microsoft 365 subscription to proceed. 如果你没有 Microsoft 365 订阅,可以从 Microsoft 365 开发人员计划获得 Microsoft 365 开发人员If you do not have an Microsoft 365 subscription, you can get a Microsoft 365 developer subscription from the Microsoft 365 Developer Program.

获取 Microsoft 365 组的连接器 webhook URLGet a connector webhook URL for a Microsoft 365 Group

  1. https://outlook.office.com登录 Outlook 网页版。Log on to Outlook on the web at https://outlook.office.com.

  2. 在文件夹列表中,从“”部分选择组。In the folder list, select a group under the Groups section. 在组的菜单中,依次选择省略号 (“...”) 和“设置”。In the group's menu, select the ellipses (...), then select Settings.

    Microsoft 365 组中“设置”菜单位置的屏幕截图。

  3. 在“组设置”窗格中,选择“连接器”。In the Group Settings pane, select Connectors.

  4. 在可用连接器列表中查找并选择“传入 Webhook”连接器。Locate and select the Incoming Webhook connector in the list of available connectors.

    可用连接器列表中的“传入 Webhook”项屏幕截图

  5. 为此连接器输入名称,并选择“创建”。Enter a name for this connector and choose Create.

  6. 复制并保存显示的 webhook URL。选择“完成”。Copy the webhook URL that is displayed and save it. Choose Done.

    传入 Webhook URL 的屏幕截图

webhook URL 应如下所示:The webhook URL should look similar to the following:

https://outlook.office365.com/webhook/a1269812-6d10-44b1-abc5-b84f93580ba0@9e7b80c7-d1eb-4b52-8582-76f921e416d9/IncomingWebhook/3fdd6767bae44ac58e5995547d66a4e4/f332c8d9-3397-4ac5-957b-b8e3fc465a8c

发送邮件Send the message

使用 Postman 将可操作邮件负载发布到 webhook URL。打开 Postman。如果需要,则新建一个选项卡并如下配置该选项卡:Use Postman to post an actionable message payload to the webhook URL. Open Postman. Create a new tab if needed and configure the tab as follows:

  1. 单击“获取”,然后更改为“发布”。Click the GET and change to POST.

  2. 在标有 Enter request URL 的文本框中粘贴 webhook URL。In the text box labeled Enter request URL paste the webhook URL.

  3. 单击 URL 下面的“正文”,然后选择“原始”选项。Click Body underneath the URL, then select the raw option.

  4. 单击“文本”,然后更改为“JSON (application/json)”。Click Text and change to JSON (application/json).

  5. 在下方的文本区域中输入邮件卡片 JSON。Enter the message card JSON in the text area below.

    完成后,Postman 窗口应如下所示:The Postman window should look like this when you are done:

    已配置为将示例可操作邮件发布到 webhook URL 的 Postman 请求窗口

  6. 单击“发送”发布邮件。Click Send to post the message.