MP_Addon_SMS_LiveChat::create_token( string $identity )

Create token.


Parameters Parameters

$identity

(string) (Required) identity


Top ↑

Return Return

(array)


Top ↑

Source Source

File: calculator-sms-add-on/inc/MP_Addon_SMS_LiveChat.php

	public function create_token( $identity ) {

		$twilio_account_sid = $this->twilio_account_sid;

		if ( empty( $this->twilio_api_key ) && empty( $this->twilio_api_secret ) ) {
			$this->get_api( MortgagePlatform::$domain );
		}

		$twilio_api_key    = $this->twilio_api_key;
		$twilio_api_secret = $this->twilio_api_secret;

		$service_sid = $this->get_service( MortgagePlatform::$plugin_name );

		$device_id = 'browser';
		$identity  = ! empty( $identity ) ? $identity : 'user' . time();

		$token = new AccessToken(
			$twilio_account_sid,
			$twilio_api_key,
			$twilio_api_secret,
			3600,
			$identity
		);

		$endpoint_id = MortgagePlatform::$domain . ':' . $identity . ':' . $device_id;

		$chat_grant = new ChatGrant();
		$chat_grant->setServiceSid( $service_sid );
		$chat_grant->setEndpointId( $endpoint_id );

		$token->addGrant( $chat_grant );

		$response = array(
			'identity' => $identity,
			'token'    => $token->toJWT(),
		);

		return $response;

	}

Top ↑

Changelog Changelog

Changelog
Version Description
1.0.0 Introduced.