Filter uncanny-automator

uap_slack_conversations_join

Filters the body of the request when joining a Slack conversation, allowing modification before it's sent to Slack.

add_filter( 'uap_slack_conversations_join', $callback, 10, 1 );

Description

Filters the request body used when joining a Slack conversation. Developers can modify parameters like the channel ID before the API call is made. This hook fires just before the `slack_request` method is invoked.


Usage

add_filter( 'uap_slack_conversations_join', 'your_function_name', 10, 1 );

Parameters

$body (mixed)
This parameter contains an associative array representing the payload for the Slack API call to join a conversation.

Return Value

The filtered value.


Examples

/**
 * Example of how to use the 'uap_slack_conversations_join' filter to modify the Slack API request body.
 *
 * This example demonstrates adding a custom parameter to the 'join_conversation' action.
 * In a real-world scenario, you might use this to pass additional context or data
 * related to the user joining the channel, which could be used by the Slack API
 * or processed further within your WordPress plugin.
 *
 * @param array $body The original array of parameters for the Slack API 'join_conversation' action.
 * @return array The modified array of parameters for the Slack API request.
 */
add_filter( 'uap_slack_conversations_join', function( $body ) {
    // Check if the channel ID is set in the original body.
    if ( isset( $body['channel'] ) ) {
        // Add a custom parameter. For demonstration, we'll add a timestamp
        // to indicate when this join action was modified by our filter.
        $body['custom_join_context'] = 'joined_via_plugin_' . time();
    }
    return $body;
}, 10, 1 );

Placement

This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.


Source Code

src/integrations/slack/helpers/slack-api-caller.php:130

public function conversations_join( $channel_id, $action_data = null ) {
		$body = array(
			'action' => 'join_conversation',
			'channel' => $channel_id,
		);

		$body = apply_filters( 'uap_slack_conversations_join', $body );

		return $this->slack_request( $body, $action_data );
	}


Scroll to Top