You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Microsoft Bot Framework中以表格格式展示数据

Hey there! Displaying tabular data in Microsoft Bot Framework depends a lot on which channel your bot is targeting (Teams, Web Chat, Slack, etc.), but I'll walk you through the most reliable methods, starting with the cross-channel go-to solution:

1. Adaptive Cards (Best Cross-Channel Solution)

Adaptive Cards have native support for tables (via the Table element in Adaptive Cards v1.5+), which works across most major channels like Teams, Web Chat, and Outlook. This is the most consistent way to render tables across different platforms.

First, define your Adaptive Card JSON with a table structure:

{
  "type": "AdaptiveCard",
  "version": "1.5",
  "body": [
    {
      "type": "TextBlock",
      "text": "Order Summary",
      "size": "Large",
      "weight": "Bolder"
    },
    {
      "type": "Table",
      "columns": [
        {
          "width": "auto",
          "items": [
            { "type": "TextBlock", "text": "Product ID", "weight": "Bolder" },
            { "type": "TextBlock", "text": "P1001" },
            { "type": "TextBlock", "text": "P1002" }
          ]
        },
        {
          "width": "auto",
          "items": [
            { "type": "TextBlock", "text": "Product Name", "weight": "Bolder" },
            { "type": "TextBlock", "text": "Wireless Headphones" },
            { "type": "TextBlock", "text": "Bluetooth Speaker" }
          ]
        },
        {
          "width": "auto",
          "items": [
            { "type": "TextBlock", "text": "Price", "weight": "Bolder" },
            { "type": "TextBlock", "text": "$99.99" },
            { "type": "TextBlock", "text": "$49.99" }
          ]
        }
      ]
    }
  ]
}

Then, send this card as an attachment in your bot code (C# example):

var adaptiveCardAttachment = new Attachment
{
    ContentType = "application/vnd.microsoft.card.adaptive",
    Content = JsonConvert.DeserializeObject(yourAdaptiveCardJsonString)
};

await turnContext.SendActivityAsync(MessageFactory.Attachment(adaptiveCardAttachment), cancellationToken);

Note: Double-check that your target channel supports Adaptive Cards v1.5+—most modern channels do, but quick testing never hurts!

2. Channel-Specific Markdown Tables

If you're building for channels that support Markdown tables (like Microsoft Teams, Web Chat, or Discord), you can skip Adaptive Cards and send a plain Markdown-formatted message:

For example, use this Markdown structure:

| Product ID | Product Name          | Price  |
|------------|-----------------------|--------|
| P1001      | Wireless Headphones   | $99.99 |
| P1002      | Bluetooth Speaker     | $49.99 |

Send it in C# like this:

var tableMessage = MessageFactory.Text(@"
| Product ID | Product Name          | Price  |
|------------|-----------------------|--------|
| P1001      | Wireless Headphones   | $99.99 |
| P1002      | Bluetooth Speaker     | $49.99 |");
tableMessage.TextFormat = TextFormat.Markdown;

await turnContext.SendActivityAsync(tableMessage, cancellationToken);

Important: Channels like Slack use a slightly different table syntax (stricter spacing rules), so you'll need to adjust if targeting those platforms—alternatively, use Slack's Block Kit for native table support.

3. Fallback for Channels Without Table Support

If you're working with channels that don't support tables (like some SMS or legacy platforms), simulate a table using formatted text or structured lists to keep data readable:

Formatted Text Fallback:

Product ID | Product Name          | Price
-----------|-----------------------|------
P1001      | Wireless Headphones   | $99.99
P1002      | Bluetooth Speaker     | $49.99

Structured List Fallback:

  • Product ID: P1001
    • Product Name: Wireless Headphones
    • Price: $99.99
  • Product ID: P1002
    • Product Name: Bluetooth Speaker
    • Price: $49.99

This ensures your data stays organized even without native table rendering.


内容的提问来源于stack exchange,提问作者Vigneswaran A

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 07:42:18