SLACK_SENDMESSAGE::send_message( $user_id,  $action_data,  $recipe_id,  $args )


Parameters Parameters

$user_id

(Required)

$action_data

(Required)

$recipe_id

(Required)

$args

(Required)


Source Source

File: src/integrations/slack/actions/slack-sendmessage.php

	public function send_message( $user_id, $action_data, $recipe_id, $args ) {
		global $uncanny_automator;

		$message            = array();
		$message['channel'] = $action_data['meta']['SLACKCHANNEL'];
		$message['text']    = $uncanny_automator->parse->text( $action_data['meta']['SLACKMESSAGE'], $recipe_id, $user_id, $args );

		try {
			$response = $uncanny_automator->helpers->recipe->slack->chat_post_message( $message );

			if ( is_array( $response ) && ! is_wp_error( $response ) ) {
				$body = json_decode( wp_remote_retrieve_body( $response ) );

				if ( isset( $body->data ) ) {
					$data = $body->data;
					$uncanny_automator->complete_action( $user_id, $action_data, $recipe_id );

					return;
				} else if ( isset( $body->error ) ) {
					$error_msg                           = $body->error->description;
					$action_data['do-nothing']           = true;
					$action_data['complete_with_errors'] = true;
					$uncanny_automator->complete_action( $user_id, $action_data, $recipe_id, $error_msg );

					return;
				}
			} else {
				throw new \Exception( __( 'WordPress was unable to communicate with Slack.', 'uncanny-automator' ) );
			}
		} catch ( \Exception $e ) {
			$error_msg                           = $e->getMessage();
			$action_data['do-nothing']           = true;
			$action_data['complete_with_errors'] = true;
			$uncanny_automator->complete_action( $user_id, $action_data, $recipe_id, $error_msg );

			return;
		}

	}