Twilio_Helpers::send_sms( string $to,  $body, string $user_id,  $action = null )


Parameters Parameters

$to

(Required)

$message

(Required)

$user_id

(Required)


Top ↑

Return Return

(array)


Source Source

File: src/integrations/twilio/helpers/twilio-helpers.php

	public function send_sms( $to, $body, $user_id, $action = null ) {

		$from = trim( get_option( 'uap_automator_twilio_api_phone_number', '' ) );

		if ( empty( $from ) ) {
			return array(
				'result'  => false,
				'message' => __( 'Twilio number is missing.', 'uncanny-automator' ),
			);
		}

		$to = self::validate_phone_number( $to );

		if ( ! $to ) {
			return array(
				'result'  => false,
				'message' => __( 'To number is not valid.', 'uncanny-automator' ),
			);
		}

		$request['action'] = 'send_sms';
		$request['from'] = $from;
		$request['to'] = $to;
		$request['body'] = $body;

		try {
			$response = $this->api_call( $request, $action );
		} catch ( \Exception $e ) {
			return array(
				'result'  => false,
				'message' => $e->getMessage(),
			);
		}

		update_user_meta( $user_id, '_twilio_sms_', $response );

		return array(
			'result'  => true,
			'message' => '',
		);

	}