dorzki / slack-notifications

Get WordPress notifications to your team's Slack channel.
https://wordpress.org/plugins/dorzki-notifications-to-slack/
GNU General Public License v3.0
41 stars 27 forks source link

Support actions when building notification for interactive messages #38

Open ocean90 opened 5 years ago

ocean90 commented 5 years ago

Slack also has support for interactive messages which includes link buttons. Link buttons are added via attachments and the actions field. See https://api.slack.com/docs/interactive-message-field-guide#action_fields for more.

Currently when passing an attachment array to send_message() it's not really treated as an attachment which Slack would expect. It's more of a "fields" array, so just one part of an attachment. I'd really like to see a way to pass a fully prepared attachment to send_message(). This would give you also the possibility to add many of the other supported properties.

But for now, actions is probably something which the plugin itself would benefit from too. Imagine "View Order" or "View Post" buttons below some of the default notifications.

What are your thoughts on this? Happy to provide a PR for this once we have fleshed out the details. Thanks!

As a workaround I'm currently passing the actions in the $args parameter of send_message() and extend the notification with the actions via slack_after_notification_generation.

ocean90 commented 5 years ago

Relevant code:

https://github.com/dorzki/Slack-Notifications/blob/ca36ac83e3e2df7a14b93cccb56493588488f08f/core/slack-bot.php#L91-L127

One ida would be to check first if a property like fallback, color or fields is set on $attachment. If set, do nothing and just merge into the new array. Otherwise use the current way as a fallback.

DorZuberi commented 5 years ago

Hi @ocean90, Soon i will release an updated version with more control of the notifications.

macbookandrew commented 4 years ago

I’m interested in actions as well, particularly approve/spam/trash for comments. I’m willing to submit a PR if you’ll consider it for use in the plugin.

DorZuberi commented 4 years ago

Hi @macbookandrew, I need to see how to embed the actions, It will be released in a future version.

Do you have a list of actions you would like to see?

macbookandrew commented 4 years ago

Some actions I’d like:

I looked at the code a bit and it appears you’re using the older attachments, and Slack has moved to a new blocks approach (upgrade notes: https://api.slack.com/messaging/attachments-to-blocks).

Do you anticipate switching to the blocks API or sticking with the attachments?

DorZuberi commented 4 years ago

I will look into it. I can't promise it will be in the coming days, but I will release a new version in the following weeks.