【问题标题】:HTTP Post with ContentURL带有 ContentURL 的 HTTP 发布
【发布时间】:2017-09-09 04:10:00
【问题描述】:

我使用 Microsoft Bot Framework,并尝试使用作为附件发送到机器人的图像进行 HTTP Post。我在 Attachment 对象中看到一个 ContentURL,但不知道如何使用 RestSharp 将图像发布到我的 API?

有什么想法吗?

【问题讨论】:

  • 您能提供您的代码并说明进度和问题吗?

标签: api http post botframework restsharp


【解决方案1】:

这里有几种可能性。

首先是将图像作为附件发送。请参阅this documentation 你的 JSON 看起来像这样:

{
    "type": "message",
    "from": {
        "id": "12345678",
        "name": "sender's name"
    },
    "conversation": {
        "id": "abcd1234",
        "name": "conversation's name"
   },
   "recipient": {
        "id": "1234abcd",
        "name": "recipient's name"
    },
    "text": "Here's a picture of the duck I was telling you about.",
    "attachments": [
        {
            "contentType": "image/png",
            "contentUrl": "http://aka.ms/Fo983c",
            "name": "duck-on-a-rock.jpg"
        }
    ],
    "replyToId": "5d5cdc723
}

另一种可能性是您可以在卡片中发送图像(它本身有两种可能性)。为此,您可以查看this documentation for rich cards。这里是一个 JSON 的例子

{
    "type": "message",
    "from": {
        "id": "12345678",
        "name": "sender's name"
    },
    "conversation": {
        "id": "abcd1234",
        "name": "conversation's name"
    },
    "recipient": {
        "id": "1234abcd",
        "name": "recipient's name"
    },
    "attachments": [
        {
            "contentType": "application/vnd.microsoft.card.hero",
            "content": {
                "title": "title goes here",
                "subtitle": "subtitle goes here",
                "text": "descriptive text goes here",
                "images": [
                    {
                        "url": "http://aka.ms/Fo983c",
                        "alt": "picture of a duck",
                        "tap": {
                            "type": "playAudio",
                            "value": "url to an audio track of a duck call goes here"
                        }
                    }
                ],
                "buttons": [
                    {
                        "type": "playAudio",
                        "title": "Duck Call",
                        "value": "url to an audio track of a duck call goes here"
                    },
                    {
                        "type": "openUrl",
                        "title": "Watch Video",
                        "image": "http://aka.ms/Fo983c",
                        "value": "url goes here of the duck in flight"
                    }
                ]
            }
        }
    ],
    "replyToId": "5d5cdc723"
}

卡片的第二个选项是adaptive cards。通过使用visualizer,您实际上可以操作 JSON 并查看它在不同通道中的呈现方式。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-07-30
    • 1970-01-01
    • 2012-06-04
    • 2017-01-20
    • 2023-03-08
    • 2016-01-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多