【问题标题】:How do I deal with rich content with the Microsoft Bot Framework?如何使用 Microsoft Bot Framework 处理丰富的内容?
【发布时间】:2016-03-31 22:46:00
【问题描述】:

我不确定如何处理丰富的内容。我想返回的一些示例是超链接列表或/一些图像缩略图。我该怎么做呢?我尝试将我的文本格式化为 HTML,这导致 Bot Emulator 崩溃并导致网络聊天客户端仅显示编码的 HTML。

这是否有秘密或一些解释这一点的文档?

【问题讨论】:

  • 是的,有文档,但祝你好运找到告诉你实际如何实现它的位。我发现了这个:docs.botframework.com/en-us/csharp/builder/sdkreference/…,它向您展示了降价是什么,但没有向您展示如何在您的代码中实现它。微软文档毫无用处而且很糟糕。

标签: botframework


【解决方案1】:

降价。 Bot Framework 将 Markdown 转换为每个频道的丰富原生格式。

某些频道通过 ChannelData 字段支持更丰富的内容(例如,您可以通过 ChannelData 字段中的 Slack 频道发送 Slack 卡片),但如果您发送 Markdown,我们所有的频道都会为该频道做正确的事情。

编辑:此处的文档:http://docs.botframework.com/connector/message-content/#the-text-property-is-markdown

【讨论】:

  • 请更新您的答案以包含示例,因为该链接的内容已更改。 (这就是为什么通常不鼓励只包含没有示例的链接的原因)。
  • 这使得处理包含 等的多行内容非常痛苦。您必须拆分每一行,用反引号将其包围,并为每行发送两个 EOL 字符。如果我们可以发布 元素会更好;至少尝试使用多行预格式化(3 个反引号)来支持“github 风味”降价。
  • 是的,需要一个例子!文档绝对是可怕的——其中一些是最糟糕的。没有提供任何真实的例子,而且通常没有帮助。我真的认为微软的人甚至不了解自己。
【解决方案2】:

你可能会发现 github 的链接很有帮助:

https://guides.github.com/features/mastering-markdown/

Style               Markdown    Description Example
Bold                **text**    make the text bold  
Italic              *text*      make the text italic    
Header1-5           # H1        Mark a line as a header 
Strikethrough       ~~text~~    make the text strikethrough 
Hr                  ---         insert a horizontal rule    
Unordered list      *           Make an unordered list item 
Ordered list        1.          Make an ordered list item starting at 1 
Pre                 `text`      Preformatted text(can be inline)    
Block quote         > text      quote a section of text 

link               [bing](http://bing.com)  
image link         ![duck](http://aka.ms/Fo983c)    

请注意,渠道会因它们支持的降价子集而异。

【讨论】:

  • +1,这更有帮助(因为内容仍然存在)——我没有意识到“降价”是一个标准的东西,所以谢谢你。 -- 但请务必更新您的答案以包含示例,而不仅仅是链接(通常不鼓励仅使用链接回答)。
【解决方案3】:

https://docs.botframework.com/en-us/core-concepts/channeldata 示例附件https://api.slack.com/docs/message-attachments 您必须在下面的代码中更改源和扭曲附件。 我能够在 slack 中处理丰富的文档 使用 Microsoft bot 框架参考这个具有丰富内容的 slack 示例

enter code here
bot.dialog('/', function (session) {

    session.send('Looking into your upcoming flights to see if you check-in on any of those...');
    var card =  {
  slack: {
    "attachments": [
        {
            "fallback": "Required plain-text summary of the attachment.",
            "color": "#36a64f",
            "pretext": "Optional text that appears above the attachment block",
            "author_name": "Bobby Tables",
            "author_link": "http://flickr.com/bobby/",
            "author_icon": "http://flickr.com/icons/bobby.jpg",
            "title": "Slack API Documentation",
            "title_link": "https://api.slack.com/",
            "text": "Optional text that appears within the attachment",
            "fields": [
                {
                    "title": "Priority",
                    "value": "High",
                    "short": false
                }
            ],
            "image_url": "http://my-website.com/path/to/image.jpg",
            "thumb_url": "http://example.com/path/to/thumb.png",
            "footer": "Slack API",
            "footer_icon": "https://platform.slack-edge.com/img/default_application_icon.png",
            "ts": 123456789
        }
    ]
}
}
var msg = new builder.Message(session).sourceEvent(card);
session.send(msg);
});

【讨论】:

    【解决方案4】:

    您可能会发现此线程对一些示例很有用,Yes MD 就是答案。

    https://github.com/microsoft/BotFramework-WebChat/issues/2289

    所以说如果你想做一个无序列表。

    Unordered list\r\n\r\n* An item\r\n* Another item\r\n* Yet another item\r\n* And there\'s more...\r\n\r\n
    

    无序列表

    • 一个项目
    • 另一个项目
    • 还有更多...

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-02-09
      • 2023-03-05
      • 1970-01-01
      • 2021-10-31
      • 1970-01-01
      • 1970-01-01
      • 2023-03-21
      • 2020-11-14
      相关资源
      最近更新 更多