将附件发布到 Slack API
Posting attachments to Slack API
所以我只知道 Slack Web API 不 支持 JSON 超过 POST 的数据。这意味着我必须对复杂的嵌套 JSON 对象进行编码,以适应 GET 上的查询参数。问题是,附件似乎不起作用。有人有解决办法吗?
So I just understood that the Slack Web API does not support JSON data over POST. Which means I have to encode my complex and nested JSON object to fit in query parameters over GET.
我不确定我是否理解您的意思。你当然可以使用 POST。 Slack API 调用的主体应该是形式编码的,但参数值有时是 JSON(例如 attachments
)。
这是一个有效的 curl
命令,它使用 HTTP POST 到 post 带有简单附件的消息。
$ curl -d token=<REDACTED> -d channel=<REDACTED> \
-d text="This is the main text." \
-d attachments='[{"text": "This is an attachment."}]' \
https://slack.com/api/chat.postMessage
我建议使用 POST,但 GET 也能正常工作。如果您填写 https://api.slack.com/methods/chat.postMessage/test 中的值,该工具将在底部为您提供一个 URL,您可以使用 HTTP GET。
所以我只知道 Slack Web API 不 支持 JSON 超过 POST 的数据。这意味着我必须对复杂的嵌套 JSON 对象进行编码,以适应 GET 上的查询参数。问题是,附件似乎不起作用。有人有解决办法吗?
So I just understood that the Slack Web API does not support JSON data over POST. Which means I have to encode my complex and nested JSON object to fit in query parameters over GET.
我不确定我是否理解您的意思。你当然可以使用 POST。 Slack API 调用的主体应该是形式编码的,但参数值有时是 JSON(例如 attachments
)。
这是一个有效的 curl
命令,它使用 HTTP POST 到 post 带有简单附件的消息。
$ curl -d token=<REDACTED> -d channel=<REDACTED> \
-d text="This is the main text." \
-d attachments='[{"text": "This is an attachment."}]' \
https://slack.com/api/chat.postMessage
我建议使用 POST,但 GET 也能正常工作。如果您填写 https://api.slack.com/methods/chat.postMessage/test 中的值,该工具将在底部为您提供一个 URL,您可以使用 HTTP GET。