Filter uncanny-automator

uap_slack_conversations_invite

Filters the Slack conversation invite payload, allowing modifications before inviting users.

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

Description

Filters the arguments before sending an invite to a Slack conversation. Developers can modify the request body, such as adding or changing user IDs or channel IDs, to customize the invite process. This hook fires just before the Slack API request is made.


Usage

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

Parameters

$body (mixed)
This parameter contains an array of data representing the Slack API call to invite a user to a conversation, including the action, channel ID, and user ID.

Return Value

The filtered value.


Examples

/**
 * Example function to modify the Slack conversation invite body.
 *
 * This function demonstrates how to use the 'uap_slack_conversations_invite'
 * filter hook to add extra data to the Slack API request body, for example,
 * to include a custom message or tag users in a specific way.
 *
 * @param array $body The original request body for inviting a user to a Slack conversation.
 * @return array The modified request body.
 */
add_filter( 'uap_slack_conversations_invite', 'my_custom_slack_invite_body', 10, 1 );

function my_custom_slack_invite_body( $body ) {
	// Check if the channel ID and user ID are present before proceeding.
	if ( isset( $body['channel'] ) && isset( $body['users'] ) ) {
		// Add a custom message to the invite body.
		// This is a hypothetical field; check Slack API documentation for valid options.
		$body['custom_message'] = 'Welcome to the channel! We're excited to have you.';

		// You could also potentially add other parameters here based on your needs.
		// For example, if your plugin has a way to determine a reason for the invite:
		// if ( ! empty( $reason_for_invite ) ) {
		//     $body['invite_reason'] = $reason_for_invite;
		// }
	}

	return $body;
}

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:151

public function conversations_invite( $channel_id, $user_id, $action_data = null ) {
		$body = array(
			'action' => 'invite_conversation',
			'channel' => $channel_id,
			'users' => $user_id,
		);

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

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


Scroll to Top