语法help - 添加附件以缓解传入的webhook

时间:2017-09-26 21:02:51

标签: curl slack-api

我正在写一个松散的集成,我正在尝试添加一个消息附件,但我仍然坚持将它们全部放在一个卷曲语句中的语法。

这是我现在想要添加附件的基本卷曲声明:

curl \
-X POST \
-H "Content-type: application/json" \
--data "{\"text\":\"$MESSAGE\"}" \
https://hooks.slack.com/services/code1/code2/code3

以下是附件的示例:

{
    "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
        }
    ]
}

但是,我对如何将该附件块放在curl语句中感到困惑。有人可以写一个完整的卷曲声明,其中包含我的附件块,以便我可以看到它是如何完成的?

1 个答案:

答案 0 :(得分:1)

实际上非常简单。 63只是JSON数组中的另一个键,与attachments处于同一级别。

所以你的新JSON数组应该看起来像这样(在字符转义之前的obv。):

text

顺便说一下。您可以同样的方式添加其他键,例如{ "text": "here goes your message text", "attachments": [ { "text": "Optional text that appears within the attachment", ... } ] } channel