Filter uncanny-automator

uap_slack_conversations_create

Filters the body content for creating Slack conversations.

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

Description

Filters the arguments passed to the Slack API when creating a new channel. Developers can modify channel name or add custom parameters to the request body before it's sent to Slack for conversation creation.


Usage

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

Parameters

$body (mixed)
This parameter is a mixed array containing data related to the creation of a Slack conversation, including an 'action' and a sanitized 'name' for the channel.

Return Value

The filtered value.


Examples

/**
 * Example of using the 'uap_slack_conversations_create' filter to modify
 * the payload sent to Slack when creating a conversation.
 *
 * This example adds a custom 'description' field to the conversation payload,
 * which might be useful for internal tracking or automation.
 */
add_filter( 'uap_slack_conversations_create', function( $body ) {
	// Check if $body is an array and has the expected structure before modifying.
	if ( is_array( $body ) && isset( $body['action'] ) && $body['action'] === 'create_conversation' ) {
		// Add a custom description to the conversation payload.
		// In a real-world scenario, you might fetch this description from post meta,
		// user settings, or another dynamic source.
		$body['description'] = 'Conversation created for a new user signup.';

		// You could also conditionally modify existing parameters.
		// For instance, to prepend a prefix to the channel name:
		// $body['name'] = 'uap_' . $body['name'];
	}

	// Always return the modified (or unmodified) $body.
	return $body;
}, 10, 1 ); // Priority 10, accepts 1 argument ($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:69

public function conversations_create( $channel_name, $action_data = null ) {
		$body = array(
			'action' => 'create_conversation',
			'name'   => substr( sanitize_title( $channel_name ), 0, 79 ),
		);

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

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


Scroll to Top