Rock The Slackbot helps you stay on top of changes by sending notifications straight to you and your team inside your Slack account.
Slack is a team collaboration tool that offers chat rooms organized by topic, as well as private groups and direct messaging. It’s a great way to be productive with your team without clogging up your inbox.
Slackbot is Slack’s built-in robot, which helps us send messages to you and your team inside your Slack account.
Because it can help you manage your websites, and stay on top of changes, by sending notifications (following numerous WordPress events) to your Slackbot who will pass them along to a channel or direct message in your Slack account.
Rock the Slackbot is multisite-friendly.
Rock the Slackbot sends customizable notifications for the following events:
I’m working to add the following events:
Each event can be customized to allow you to send different event notifications to different Slack channels, e.g. you can send core, theme and plugin updates to your “wp-development” channel while all of your post changes go to your “wp-content” channel.
Please use the Issues section of this plugin’s GitHub repo to suggest features, like other notification events.
A Slack account is required to use this plugin and is free to use for as long as you want and with an unlimited number of people. Visit the Slack website to learn more and sign up.
You can use the following send_webhook_message() function to send a simple message to your Slack account.
The function accepts the following parameters:
$channel – OPTIONAL – the channel you want to send message to. Prefix with # for a specific channel or @ for a specific user. Will use default channel if nothing is passed.
// Use this function to send a simple message to Slack
rock_the_slackbot()->send_webhook_message( ‘564d3c1cdf52d’, ‘this is a test’, ‘#testchannel’ );
Rock The Slackbot has filters setup to allow you to tweak each WordPress notification before it’s sent. You can setup a filter for all notifications or drill down by event or specific webhook.
Each notification filter passes three arguments:
See Notification Events below to learn which information is passed to the filters for each notification event.
add_filter( 'rock_the_slackbot_notification', 'filter_rock_the_slackbot_notification', 10, 3 ); function filter_rock_the_slackbot_notification( $notification, $notification_event, $event_args ) { // Change the pieces // Return the notification return $notification; }
// You can find the ID for each of your webhooks on their edit screen in the admin add_filter( 'rock_the_slackbot_notification_(webhook_id)', 'filter_rock_the_slackbot_notification_webhook', 10, 3 ); function filter_rock_the_slackbot_notification_webhook( $notification, $notification_event, $event_args ) { // Change the pieces // Return the notification return $notification; }
// The event slugs are listed below add_filter( 'rock_the_slackbot_notification_(notification_event)', 'filter_rock_the_slackbot_notification_event', 10, 3 ); function filter_rock_the_slackbot_notification_event( $notification, $notification_event, $event_args ) { // Change the pieces // Return the notification return $notification; }
Whether it’s a WordPress notification or a simple Slack message, all messages to Slack are sent as a payload in an outgoing webhook. This filter allows you to change any payload sent to Slack in an outgoing webhook.
add_filter( 'rock_the_slackbot_outgoing_webhook_payload', 'filter_rock_the_slackbot_outgoing_webhook_payload', 10, 2 ); function filter_rock_the_slackbot_outgoing_webhook_payload( $payload, $webhook_url ) { // Change the payload // Return the payload return $notification; }<h3>Notification Events</h3>
Including event specific information passed to filters for each notification event.
You can use a filter to change the Slack notification to go to a different Slack channel according to post information, like the post category:
add_filter( 'rock_the_slackbot_notification', 'filter_rock_the_slackbot_notification', 10, 3 ); function filter_rock_the_slackbot_notification( $notification, $notification_event, $event_args ) { // Only run filter for specific events switch ( $notification_event ) { // This way you can set which events you want to use case 'post_published': case 'post_unpublished': case 'post_updated': case 'post_deleted': case 'post_trashed': // Get category names $categories = wp_get_post_categories( $event_args[ 'post_id' ], array( 'fields' => 'names' ) ); // Replace 'CategoryName' with the category you're looking for if ( in_array( 'CategoryName', $categories ) ) { // Change the channel in the payload // Make sure you prefix the channel name with # $notification[ 'payload' ][ 'channel' ] = '#newchannel'; } break; } // Return the notification return $notification; }
Plugin launch