This repository has been archived by the owner on Sep 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 745
RING Central SMS Integration #12504
Open
z0lo13
wants to merge
3
commits into
YetiForceCompany:developer
Choose a base branch
from
z0lo13:developer
base: developer
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
RING Central SMS Integration #12504
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
<?php | ||
|
||
/** | ||
* RINGCENTRAL - sms provider. | ||
*/ | ||
class SMSNotifier_RingCentral_Provider extends SMSNotifier_Basic_Provider | ||
{ | ||
/** | ||
* Provider name. | ||
* | ||
* @var string | ||
*/ | ||
protected $name = 'RingCentral'; | ||
|
||
/** | ||
* Address URL. | ||
* | ||
* @var string | ||
*/ | ||
protected $url = 'https://platform.ringcentral.com'; | ||
|
||
/** | ||
* Encoding. | ||
* | ||
* @var string | ||
*/ | ||
public $encoding = 'utf-8'; | ||
|
||
/** | ||
* Format. | ||
* | ||
* @var string | ||
*/ | ||
public $format = 'json'; | ||
|
||
/** | ||
* Required fields. | ||
* | ||
* @return string[] | ||
*/ | ||
public function getRequiredParams() | ||
{ | ||
return ['CLIENT_ID','RINGUSER','RINGPASS','RINGPHONE','RINGEXT']; | ||
} | ||
|
||
public function get($key) | ||
{ | ||
return $this->$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; | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What class is this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/ringcentral/ringcentral-php
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't merge your commits because an additional library in the system is required, which in most cases won't be used. If you rewrite the communication code to "Guzzle, PHP HTTP client" (here is an example https://github.com/YetiForceCompany/YetiForceCRM/search?q=GuzzleHttp) we will merge your commits.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mariuszkrzaczkowski
I won't be doing it, as it works just fine in the environment. What is the problem with Ringcentral SDK? It is an official well-maintained library. https://github.com/ringcentral/ringcentral-php
you can close the request if you don't see potential in this.
P.S
Letting you know that Ringcentral one of the largest VoIP providers in North America, so potentially including this integration will bring you more clients.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mariuszkrzaczkowski
I am not too sure about guzzle but I do have sms, call logs, and call recordings working in production. Full pbx and mms integration is feasible and I would be willing to create a pull request for complete RingCentral / Telus Business Connect support; though I am not sure what your thoughts are on using curl as its not used in the code base, please let me know.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
guzzle would be better, it includes default proxy configuration and is simple to use, see
YetiForceCRM/app/RecordCollectors/UaYouControl.php
Lines 134 to 147 in f1904a6