diff --git a/modules/SMSNotifier/providers/RingCentral.php b/modules/SMSNotifier/providers/RingCentral.php new file mode 100644 index 000000000000..7b652e8e243d --- /dev/null +++ b/modules/SMSNotifier/providers/RingCentral.php @@ -0,0 +1,134 @@ +$key; + } + + /** + * Response. + * + * @param Requests_Response $request + * + * @return bool + */ + public function getResponse(Requests_Response $request) + { + $response = \App\Json::decode($request->body); + + return isset($response['error']) && !empty($response['error']) ? false : true; + } + + /** + * Fields to edit in settings. + * + * @return \Settings_Vtiger_Field_Model[] + */ + public function getSettingsEditFieldsModel() + { + $fields = []; + $moduleName = 'Settings:SMSNotifier'; + foreach ($this->getRequiredParams() as $name) { + $field = ['uitype' => 1, 'column' => $name, 'name' => $name, 'displaytype' => 1, 'typeofdata' => 'V~M', 'presence' => 0, 'isEditableReadOnly' => false]; + switch ($name){ + case ("CLIENT_ID" || "RINGUSER" || "RINGPASS" || "RINGPHONE" || "RINGEXT"): + $field['text'] = ['']; + $field['label'] = $name; + $fields[] = $field; + break; + } + } + foreach ($fields as &$field) { + $field = Settings_Vtiger_Field_Model::init($moduleName, $field); + } + return $fields; + } + + public function getPatch() + { + $keys = $this->getRequiredParams(); + $keys[] = $this->toName; + $keys[] = $this->messageName; + $params = []; + foreach ($keys as $key) { + $params[$key] = $this->get($key); + } + + return $params; + + } + + public function send() { + + $url = $this->getUrl(); + $cliend_secret = $this->getAuthorization(); + $patch = $this->getPatch(); +// + $login = new RingCentral\SDK\SDK($patch['CLIENT_ID'], $cliend_secret, $url); + $platform = $login->platform(); + $RINGCENTRAL_USERNAME = $patch['RINGUSER']; + $RINGCENTRAL_NUMBER = $patch['RINGPHONE']; + $RINGCENTRAL_PASSWORD = $patch['RINGPASS']; + $RINGCENTRAL_EXTENSION = $patch['RINGEXT']; + try { + $platform->login($RINGCENTRAL_USERNAME, + $RINGCENTRAL_EXTENSION, + $RINGCENTRAL_PASSWORD); + $params = array( + 'from' => array('phoneNumber' => $RINGCENTRAL_NUMBER), + 'to' => array( + array('phoneNumber' => $patch['to']), + ), + 'text' => $patch['message'], + ); + $r = $platform->post('/account/~/extension/~/sms', $params); + } catch (\RingCentral\SDK\Http\ApiException $e) { + print 'Expected HTTP Error: ' . $e->getMessage() . PHP_EOL; + } + + return true; + } +}