TWILIO_SENDSMS::twilio_send_sms( $user_id,  $action_data,  $recipe_id,  $args )

Validation function when the action is hit


Parameters Parameters

$user_id

(Required)

$action_data

(Required)

$recipe_id

(Required)

$args

(Required)


Source Source

File: src/integrations/twilio/actions/twilio-sendsms.php

	public function twilio_send_sms( $user_id, $action_data, $recipe_id, $args ) {

		$to         = Automator()->parse->text( $action_data['meta'][ $this->action_meta ], $recipe_id, $user_id, $args );
		$body_text  = $action_data['meta']['SMSBODY'];
		$reset_pass = ! is_null( $this->key ) ? $this->key : Automator()->parse->generate_reset_token( $user_id );
		$body       = str_replace( '{{reset_pass_link}}', $reset_pass, $body_text );
		$body       = Automator()->parse->text( $body, $recipe_id, $user_id, $args );
		$body       = do_shortcode( $body );

		$to_numbers = explode( ',', $to );
		if ( ! empty( $to_numbers ) ) {
			$is_error  = false;
			$error_msg = '';
			foreach ( $to_numbers as $to_num ) {
				$result = Automator()->helpers->recipe->twilio->send_sms( $to_num, wp_strip_all_tags( $body ), $user_id, $action_data );

				if ( ! $result['result'] ) {
					$error_msg = $result['message'];
					$is_error  = true;
				}
			}
			if ( $is_error ) {
				$action_data['do-nothing']           = true;
				$action_data['complete_with_errors'] = true;
				Automator()->complete_action( $user_id, $action_data, $recipe_id, $error_msg );

				return;
			}
		}

		Automator()->complete_action( $user_id, $action_data, $recipe_id );
	}