42wim/matterircd

Add support for message attachments

hloeung opened this issue · 0 comments

This is documented in https://developers.mattermost.com/integrate/reference/message-attachments/

It is used in various integrations such as that from Flux - https://github.com/fluxcd/notification-controller/blob/main/internal/notifier/slack.go

I think it would be nice to add support for it. Messages from Flux CD uses color "good" and "danger" e.g.

[2024-02-13T23:47:24Z] DEBUG matterclient: WsReceiver event: &model.WebSocketEvent{event:"posted", data:map[string]interface {}{"channel_display_name":"IS Notifications", "channel_name":"is-notifications", "channel_type":"P", "post":"{\"id\":\"pwmaszqpy7re9npgpr687ansua\",\"create_at\":1707868043816,\"update_at\":1707868043816,\"edit_at\":0,\"delete_at\":0,\"is_pinned\":false,\"user_id\":\"55n7z5xprfrj5qza7m1rqj7zpe\",\"channel_id\":\"s1e989b14b8g3yhkuco8dnb5qy\",\"root_id\":\"\",\"original_id\":\"\",\"message\":\"\",\"type\":\"slack_attachment\",\"props\":{\"attachments\":[{\"id\":0,\"fallback\":\"\",\"color\":\"danger\",\"pretext\":\"\",\"author_name\":\"terraform/prod-temporal.fluxsystem\",\"author_link\":\"\",\"author_icon\":\"\",\"title\":\"\",\"title_link\":\"\",\"text\":\"Drift detected.\\n\\nNote:...\\n\",\"fields\":[{\"title\":\"revision\",\"value\":\"main@sha1:a0f7095d8d855e988337b7cd18432c17d3d0a70f\",\"short\":false},{\"title\":\"summary\",\"value\":\"Terraform event detected\",\"short\":false}],\"image_url\":\"\",\"thumb_url\":\"\",\"footer\":\"\",\"footer_icon\":\"\",\"ts\":null}],\"from_bot\":\"true\",\"from_webhook\":\"true\",\"webhook_display_name\":\"IS Flux Notifications\"},\"hashtags\":\"\",\"pending_post_id\":\"\",\"reply_count\":0,\"last_reply_at\":0,\"participants\":null,\"metadata\":{\"embeds\": [{\"type\":\"message_attachment\"}]}}", "sender_name":"@is-flux-bot", "set_online":false, "team_id":"sqmc4sz45prypmkfctwynm5yjr"}, broadcast:(*model.WebsocketBroadcast)(0xc0002ee040), sequence:3334, precomputedJSON: *model.precomputedWebSocketEventJSON)(nil)}

And:

[2024-02-13T23:47:31Z] DEBUG matterclient: WsReceiver event: &model.WebSocketEvent{event:"posted", data:map[string]interface {}{"channel_display_name":"IS Notifications", "channel_name":"is-notifications", "channel_type":"P", "post":"{\"id\":\"tacyqhdk1jdhtg5zgornn7tnay\",\"create_at\":1707868050914,\"update_at\":1707868050914,\"edit_at\":0,\"delete_at\":0,\"is_pinned\":false,\"user_id\":\"55n7z5xprfrj5qza7m1rqj7zpe\",\"channel_id\":\"s1e989b14b8g3yhkuco8dnb5qy\",\"root_id\":\"\",\"original_id\":\"\",\"message\":\"\",\"type\":\"slack_attachment\",\"props\":{\"attachments\":[{\"id\":0,\"fallback\":\"\",\"color\":\"good\",\"pretext\":\"\",\"author_name\":\"terraform/prod-temporal.flux-system\",\"author_link\":\"\",\"author_icon\":\"\",\"title\":\"\",\"title_link\":\"\",\"text\":\"Applied successfully\",\"fields\":[{\"title\":\"revision\",\"value\":\"main@sha1:a0f7095d8d855e988337b7cd18432c17d3d0a70f\",\"short\":false},{\"title\":\"summary\",\"value\":\"Terraform event detected\",\"short\":false}],\"image_url\":\"\",\"thumb_url\":\"\",\"footer\":\"\",\"footer_icon\":\"\",\"ts\":null}],\"from_bot\":\"true\",\"from_webhook\":\"true\",\"webhook_display_name\":\"IS Flux Notifications\"},\"hashtags\":\"\",\"pending_post_id\":\"\",\"reply_count\":0,\"last_reply_at\":0,\"participants\":null,\"metadata\":{\"embeds\":[{\"type\":\"message_attachment\"}]}}", "sender_name":"@is-flux-bot", "set_online":false, "team_id":"sqmc4sz45prypmkfctwynm5yjr"}, broadcast:(*model.WebsocketBroadcast)(0xc00022a3c0), sequence:3337, precomputedJSON:(*model.precomputedWebSocketEventJSON)(nil)}