ZAPIER_SENDWEBHOOK::define_action()

Define and register the action by pushing it into the Automator object


Source Source

File: src/integrations/zapier/actions/zapier-sendwebhook.php

	public function define_action() {



		$action = array(
			'author'             => Automator()->get_author_name( $this->action_code ),
			'support_link'       => Automator()->get_author_support_link( $this->action_code, 'knowledge-base/working-with-zapier-actions' ),
			'integration'        => self::$integration,
			'code'               => $this->action_code,
			/* translators: Action - Zapier */
			'sentence'           => sprintf( esc_attr__( 'Send data to Zapier {{webhook:%1$s}}', 'uncanny-automator' ), $this->action_meta ),
			/* translators: Action - Zapier */
			'select_option_name' => esc_attr__( 'Send data to Zapier {{webhook}}', 'uncanny-automator' ),
			'priority'           => 10,
			'accepted_args'      => 1,
			'execution_function' => array( $this, 'send_webhook' ),
			'options_group'      => [
				$this->action_meta => [
					// Webhook URL
					[
						'input_type' => 'url',

						'option_code' => 'WEBHOOK_URL',
						'label'       => esc_attr__( 'URL', 'uncanny-automator' ),

						'supports_tokens' => true,
						'required'        => true,
					],
					// Action event
					[
						'input_type' => 'select',

						'option_code' => 'ACTION_EVENT',
						/* translators: HTTP request method */
						'label'       => esc_attr__( 'Request method', 'uncanny-automator' ),
						'description' => esc_attr__( 'Select the HTTP request method supported by the webhook destination. If you are unsure, leave this value unchanged unless you are experiencing issues.', 'uncanny-automator' ),

						'required' => true,

						'default_value' => 'POST',
						'options'       => [
							'GET'  => 'GET',
							'PUT'  => 'PUT',
							'POST' => 'POST',
						],
					],
					// Header
					[
						'input_type' => 'repeater',

						'option_code' => 'WEBHOOK_HEADERS',

						'label'       => esc_attr__( 'Headers', 'uncanny-automator' ),
						'description' => esc_attr__( 'Add any HTTP request headers required by the webhook destination.', 'uncanny-automator' ),

						'required'          => false,
						'fields'            => [
							[
								'input_type' => 'text',

								'option_code' => 'NAME',
								'label'       => esc_attr__( 'Name', 'uncanny-automator' ),

								'supports_tokens' => true,
								'required'        => true,
							],
							[
								'input_type' => 'text',

								'option_code' => 'VALUE',
								'label'       => esc_attr__( 'Value', 'uncanny-automator' ),

								'supports_tokens' => true,
								'required'        => true,
							],
						],

						/* translators: Non-personal infinitive verb */
						'add_row_button'    => esc_attr__( 'Add header', 'uncanny-automator' ),
						/* translators: Non-personal infinitive verb */
						'remove_row_button' => esc_attr__( 'Remove header', 'uncanny-automator' ),
					],
					// Fields
					[
						'input_type' => 'repeater',

						'option_code' => 'WEBHOOK_FIELDS',

						'label' => esc_attr__( 'Fields', 'uncanny-automator' ),

						'required'          => true,
						'fields'            => [
							[
								'input_type' => 'text',

								'option_code' => 'KEY',
								'label'       => esc_attr__( 'Key', 'uncanny-automator' ),

								'supports_tokens' => true,
								'required'        => true,
							],
							[
								'input_type' => 'text',

								'option_code' => 'VALUE',
								'label'       => esc_attr__( 'Value', 'uncanny-automator' ),

								'supports_tokens' => true,
								'required'        => true,
							],
						],

						/* translators: Non-personal infinitive verb */
						'add_row_button'    => esc_attr__( 'Add pair', 'uncanny-automator' ),
						/* translators: Non-personal infinitive verb */
						'remove_row_button' => esc_attr__( 'Remove pair', 'uncanny-automator' ),
					],
				],
			],
			'buttons'            => [
				[
					'show_in'     => $this->action_meta,
					'text'        => esc_attr__( 'Documentation', 'uncanny-automator' ),
					'css_classes' => 'uap-btn uap-btn--transparent',
					'on_click'    => 'function(){ window.open( "https://automatorplugin.com", "_blank" ); }',
				],
				[
					'show_in'     => $this->action_meta,
					/* translators: Non-personal infinitive verb */
					'text'        => esc_attr__( 'Send test', 'uncanny-automator' ),
					'css_classes' => 'uap-btn uap-btn--red',
					'on_click'    => $this->send_test_js(),
					'modules'     => [ 'markdown' ],
				],
			],
		);

		Automator()->register->action( $action );
	}