Curl 语法帮助-向传入的Webhook添加附件
我正在编写一个slack集成,并试图添加一个消息附件,但我一直坚持将所有内容组合到一个curl语句中的语法 这是我现在想要添加附件的基本curl语句:Curl 语法帮助-向传入的Webhook添加附件,curl,slack-api,Curl,Slack Api,我正在编写一个slack集成,并试图添加一个消息附件,但我一直坚持将所有内容组合到一个curl语句中的语法 这是我现在想要添加附件的基本curl语句: curl \ -X POST \ -H "Content-type: application/json" \ --data "{\"text\":\"$MESSAGE\"}" \ https://hooks.slack.com/services/code1/code2/code3 以下是附件的示例: { "attachments": [
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语句中放置附件块感到困惑。有没有人能为我写一个完整的curl语句,其中包括附件块,这样我就可以看到它是如何完成的了?其实很简单<代码>附件只是JSON数组中的另一个键,与
文本
处于同一级别
因此,新的JSON数组应该如下所示(obv.在字符转义之前):
顺便说一句,你可以用同样的方法添加其他键,如频道和图标url。其实很简单<代码>附件只是JSON数组中的另一个键,与
文本
处于同一级别
因此,新的JSON数组应该如下所示(obv.在字符转义之前):
顺便说一句,你可以用同样的方法添加其他键,如channel
和icon\u url
{
"text": "here goes your message text",
"attachments":
[
{
"text": "Optional text that appears within the attachment",
...
}
]
}