This repository was archived by the owner on Aug 26, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 773
Expand file tree
/
Copy pathRingCentral.php
More file actions
157 lines (142 loc) · 4.08 KB
/
Copy pathRingCentral.php
File metadata and controls
157 lines (142 loc) · 4.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<?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];
if ($name === 'CLIENT_ID') {
$field['text'] = [''];
$field['label'] = 'CLIENT_ID';
$fields[] = $field;
continue;
}
if ($name === 'RINGUSER') {
$field['text'] = [''];
$field['label'] = 'RINGUSER';
$fields[] = $field;
continue;
}
if ($name === 'RINGPASS') {
$field['text'] = [''];
$field['label'] = 'RINGPASS';
$fields[] = $field;
continue;
}
if ($name === 'RINGPHONE') {
$field['text'] = [''];
$field['label'] = 'RINGPHONE';
$fields[] = $field;
continue;
}
if ($name === 'RINGEXT') {
$field['text'] = [''];
$field['label'] = 'RINGEXT';
$fields[] = $field;
continue;
}
}
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;
}
}