I am looking to add a simple webhook to Slack my team git diffs when certain files on certain branches are updated. The webhook is working, however I am only sending plain text. I'd like to be able to send the payload so it appears the same as if a user were to 'Add Attachment' and set the type to 'Diff'.
All the docs I can find are about sending media or unfurling links like youtube or cnn. Could someone point me in the right direction. I tried creating a bot to read the JSON of a similar message, but it seems much more complex than I expected, with fields like url_private_download
which I wasn't expecting. All I got, was that it is uploaded as an attachment.
Here are two ways how you could send information about a git diff to Slack: Attachments and File uploads
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 you mentioned as requirement.
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, but for a git diff I would recommend "text".