Slack Webhook - 附加 git diff

Slack Web hook - Attach a git diff

我希望在我的团队 Slack 中添加一个简单的 webhook git 当更新某些分支上的某些文件时出现差异。 Webhook 正在运行,但我只发送纯文本。我希望能够发送有效载荷,使其看起来与用户 'Add Attachment' 并将类型设置为 'Diff'.

一样

我能找到的所有文档都是关于发送媒体或展开链接(如 youtube 或 cnn)的。有人能指出我正确的方向吗?我尝试创建一个机器人来读取类似消息的 JSON,但它似乎比我预期的要复杂得多,其中包含我没有预料到的 url_private_download 之类的字段。我得到的只是它是作为附件上传的。

您可以通过以下两种方式将有关 git 差异的信息发送到 Slack:附件和文件上传

Attachments can contain text and one image. They are limited in size, but you can add up to 20 (official recommendation) / 100 (hard limit) to one message. They work with all methods for sending messages, including the incoming webhook 您提到的要求。

File uploads mean that you are literally uploading a file to you Slack team. You need to share it in a channel to make it visible as new post. It can not be attached to a normal message, but you can add comments to it. This will not work with incoming webhooks though. You will need need to use the API method file.upload to upload and share your file. Slack supports a variety of file types,但对于 git 差异,我建议 "text"。