1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Root class file for all api wrappers. |
4
|
|
|
* |
5
|
|
|
* @package LivePersonInc\LiveEngageLaravel |
6
|
|
|
* |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace LivePersonInc\LiveEngageLaravel; |
10
|
|
|
|
11
|
|
|
use Carbon\Carbon; |
12
|
|
|
use GuzzleHttp\Client; |
13
|
|
|
use GuzzleHttp\HandlerStack; |
14
|
|
|
use GuzzleHttp\Subscriber\Oauth\Oauth1; |
15
|
|
|
use LivePersonInc\LiveEngageLaravel\Models\Info; |
16
|
|
|
use LivePersonInc\LiveEngageLaravel\Models\MetaData; |
17
|
|
|
use LivePersonInc\LiveEngageLaravel\Models\AccountStatus; |
18
|
|
|
use LivePersonInc\LiveEngageLaravel\Models\MessagingInfo; |
19
|
|
|
use LivePersonInc\LiveEngageLaravel\Models\Payload; |
20
|
|
|
use LivePersonInc\LiveEngageLaravel\Models\Visitor; |
21
|
|
|
use LivePersonInc\LiveEngageLaravel\Models\Agent; |
22
|
|
|
use LivePersonInc\LiveEngageLaravel\Models\Skill; |
23
|
|
|
use LivePersonInc\LiveEngageLaravel\Models\Campaign; |
24
|
|
|
use LivePersonInc\LiveEngageLaravel\Models\Engagement; |
25
|
|
|
use LivePersonInc\LiveEngageLaravel\Models\Conversation; |
26
|
|
|
use LivePersonInc\LiveEngageLaravel\Models\Message; |
27
|
|
|
use LivePersonInc\LiveEngageLaravel\Collections\EngagementHistory; |
28
|
|
|
use LivePersonInc\LiveEngageLaravel\Collections\Skills; |
29
|
|
|
use LivePersonInc\LiveEngageLaravel\Collections\AgentParticipants; |
30
|
|
|
use LivePersonInc\LiveEngageLaravel\Exceptions\LiveEngageException; |
31
|
|
|
use LivePersonInc\LiveEngageLaravel\Collections\ConversationHistory; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* LiveEngageLaravel class holds all of the root package functions. |
35
|
|
|
* |
36
|
|
|
* All "setting" functions will return `$this` so method can be chained. Most methods will return a class object or Laravel collection. |
37
|
|
|
*/ |
38
|
|
|
class LiveEngageLaravel |
39
|
|
|
{ |
40
|
|
|
/** |
41
|
|
|
* account - LiveEngage account number, usually set by configuration |
42
|
|
|
* |
43
|
|
|
* (default value: false) |
44
|
|
|
* |
45
|
|
|
* @var long |
|
|
|
|
46
|
|
|
* @access private |
47
|
|
|
*/ |
48
|
|
|
private $account = false; |
49
|
|
|
/** |
50
|
|
|
* skills - holds the skills for history retrieval |
51
|
|
|
* |
52
|
|
|
* (default value: []) |
53
|
|
|
* |
54
|
|
|
* @var array |
55
|
|
|
* @access private |
56
|
|
|
*/ |
57
|
|
|
private $skills = []; |
58
|
|
|
/** |
59
|
|
|
* config - holds the configuration key where keyset is stored in config/services.php |
60
|
|
|
* |
61
|
|
|
* (default value: 'services.liveperson.default') |
62
|
|
|
* |
63
|
|
|
* @var string |
64
|
|
|
* @access private |
65
|
|
|
*/ |
66
|
|
|
private $config = 'services.liveperson.default'; |
67
|
|
|
/** |
68
|
|
|
* version - api version |
69
|
|
|
* |
70
|
|
|
* (default value: '1.0') |
71
|
|
|
* |
72
|
|
|
* @var string |
73
|
|
|
* @access private |
74
|
|
|
*/ |
75
|
|
|
private $version = '1.0'; |
76
|
|
|
/** |
77
|
|
|
* history_limit - stores the history page limit |
78
|
|
|
* |
79
|
|
|
* (default value: 50) |
80
|
|
|
* |
81
|
|
|
* @var int |
82
|
|
|
* @access private |
83
|
|
|
*/ |
84
|
|
|
private $history_limit = 50; |
85
|
|
|
private $interactive = true; |
86
|
|
|
private $ended = true; |
87
|
|
|
/** |
88
|
|
|
* bearer - bearer token for V2 authentication |
89
|
|
|
* |
90
|
|
|
* (default value: false) |
91
|
|
|
* |
92
|
|
|
* @var string |
93
|
|
|
* @access private |
94
|
|
|
*/ |
95
|
|
|
private $bearer = false; |
96
|
|
|
/** |
97
|
|
|
* revision |
98
|
|
|
* |
99
|
|
|
* (default value: 0) |
100
|
|
|
* |
101
|
|
|
* @var int |
102
|
|
|
* @access private |
103
|
|
|
*/ |
104
|
|
|
private $revision = 0; |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* domain - api domain storage |
108
|
|
|
* |
109
|
|
|
* (default value: false) |
110
|
|
|
* |
111
|
|
|
* @var bool |
112
|
|
|
* @access private |
113
|
|
|
*/ |
114
|
|
|
private $domain = false; |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* retry_limit - number of times the request will attempt before it throws the exception. |
118
|
|
|
* |
119
|
|
|
* (default value: 5) |
120
|
|
|
* |
121
|
|
|
* @var int |
122
|
|
|
* @access private |
123
|
|
|
*/ |
124
|
|
|
private $retry_limit = 5; |
125
|
|
|
/** |
126
|
|
|
* retry_counter - stores current count of retries. |
127
|
|
|
* |
128
|
|
|
* (default value: 0) |
129
|
|
|
* |
130
|
|
|
* @var int |
131
|
|
|
* @access private |
132
|
|
|
*/ |
133
|
|
|
private $retry_counter = 0; |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* __get magic function to retrieve private properties of the class. |
137
|
|
|
* |
138
|
|
|
* @access public |
139
|
|
|
* @param mixed $attribute |
140
|
|
|
* @return mixed |
141
|
|
|
*/ |
142
|
5 |
|
public function __get($attribute) |
143
|
|
|
{ |
144
|
5 |
|
return $this->$attribute; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* __construct function. |
149
|
|
|
* |
150
|
|
|
* @access public |
151
|
|
|
* @return void |
152
|
|
|
*/ |
153
|
8 |
|
public function __construct() |
154
|
|
|
{ |
155
|
8 |
|
$this->account = config("{$this->config}.account"); |
156
|
|
|
//$this->domain = config("{$this->config}.domain"); |
157
|
8 |
|
$this->version = config("{$this->config}.version") ?: $this->version; |
158
|
8 |
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* key function sets the keyset the class should use. Setting this once will be stored for script execution, but not for the session. |
162
|
|
|
* |
163
|
|
|
* @access public |
164
|
|
|
* @param string $key (default: 'default') |
165
|
|
|
* @return this |
166
|
|
|
*/ |
167
|
1 |
|
public function key($key = 'default') |
168
|
|
|
{ |
169
|
1 |
|
$this->config = "services.liveperson.$key"; |
170
|
1 |
|
$this->__construct(); |
171
|
|
|
|
172
|
1 |
|
return $this; |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* nonInteractive function. |
177
|
|
|
* |
178
|
|
|
* @access public |
179
|
|
|
* @return void |
180
|
|
|
*/ |
181
|
1 |
|
public function nonInteractive() |
182
|
|
|
{ |
183
|
1 |
|
$this->interactive = false; |
184
|
1 |
|
return $this; |
|
|
|
|
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* active function. |
189
|
|
|
* |
190
|
|
|
* @access public |
191
|
|
|
* @return void |
192
|
|
|
*/ |
193
|
1 |
|
public function active() |
194
|
|
|
{ |
195
|
1 |
|
$this->ended = false; |
196
|
1 |
|
return $this; |
|
|
|
|
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* limit function. |
201
|
|
|
* |
202
|
|
|
* @access public |
203
|
|
|
* @param mixed $limit |
204
|
|
|
* @return void |
205
|
|
|
*/ |
206
|
1 |
|
public function limit($limit) |
207
|
|
|
{ |
208
|
1 |
|
$this->history_limit = $limit; |
209
|
|
|
|
210
|
1 |
|
return $this; |
|
|
|
|
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
/** |
214
|
|
|
* retry function. |
215
|
|
|
* |
216
|
|
|
* @access public |
217
|
|
|
* @param mixed $limit |
218
|
|
|
* @return void |
219
|
|
|
*/ |
220
|
1 |
|
public function retry($limit) |
221
|
|
|
{ |
222
|
1 |
|
$this->retry_limit = $limit; |
223
|
|
|
|
224
|
1 |
|
return $this; |
|
|
|
|
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
/** |
228
|
|
|
* account function. |
229
|
|
|
* |
230
|
|
|
* @access public |
231
|
|
|
* @param mixed $accountid |
232
|
|
|
* @return void |
233
|
|
|
*/ |
234
|
1 |
|
public function account($accountid) |
235
|
|
|
{ |
236
|
1 |
|
$this->account = $accountid; |
237
|
|
|
|
238
|
1 |
|
return $this; |
|
|
|
|
239
|
|
|
} |
240
|
|
|
|
241
|
|
|
/** |
242
|
|
|
* domain function sets the LivePerson domain for the secified service. Like `key` it is set for the execution script, but not session. It must be run each time. |
243
|
|
|
* |
244
|
|
|
* @access public |
245
|
|
|
* @param mixed $service |
246
|
|
|
* @return this |
247
|
|
|
*/ |
248
|
1 |
|
public function domain($service) |
249
|
|
|
{ |
250
|
1 |
|
$response = $this->requestV1("https://api.liveperson.net/api/account/{$this->account}/service/{$service}/baseURI.json?version={$this->version}", 'GET'); |
251
|
|
|
|
252
|
1 |
|
$this->domain = $response->baseURI; |
253
|
|
|
|
254
|
1 |
|
return $this; |
255
|
|
|
} |
256
|
|
|
|
257
|
|
|
/** |
258
|
|
|
* visitor function gets or sets visitor attribute information - this only works for CHAT, not messaging. |
259
|
|
|
* |
260
|
|
|
* @access public |
261
|
|
|
* @param string $visitorID |
262
|
|
|
* @param string $sessionID |
263
|
|
|
* @param mixed $setData (default: false) |
264
|
|
|
* @return mixed |
265
|
|
|
* @codeCoverageIgnore |
266
|
|
|
*/ |
267
|
|
|
public function visitor($visitorID, $sessionID, $setData = false) |
268
|
|
|
{ |
269
|
|
|
$this->domain('smt'); |
270
|
|
|
|
271
|
|
|
if ($setData) { |
272
|
|
|
$url = "https://{$this->domain}/api/account/{$this->account}/monitoring/visitors/{$visitorID}/visits/current/events?v=1&sid={$sessionID}"; |
273
|
|
|
|
274
|
|
|
return $this->requestV1($url, 'POST', $setData); |
275
|
|
|
} else { |
276
|
|
|
$url = "https://{$this->domain}/api/account/{$this->account}/monitoring/visitors/{$visitorID}/visits/current/state?v=1&sid={$sessionID}"; |
277
|
|
|
|
278
|
|
|
return $this->requestV1($url, 'GET'); |
279
|
|
|
} |
280
|
|
|
} |
281
|
|
|
|
282
|
|
|
/** |
283
|
|
|
* chat function |
284
|
|
|
* |
285
|
|
|
* @codeCoverageIgnore |
286
|
|
|
* |
287
|
|
|
* @todo connect this to the server chat api - this function currently does nothing. |
288
|
|
|
*/ |
289
|
|
|
public function chat() |
290
|
|
|
{ |
291
|
|
|
$this->domain('conversationVep'); |
292
|
|
|
|
293
|
|
|
$url = "https://{$this->domain}/api/account/{$this->account}/chat/request?v=1&NC=true"; |
294
|
|
|
|
295
|
|
|
$args = [ |
296
|
|
|
|
297
|
|
|
]; |
298
|
|
|
$payload = new Payload($args); |
299
|
|
|
|
300
|
|
|
$response = $this->requestV1($url, 'POST', $payload); |
|
|
|
|
301
|
|
|
|
302
|
|
|
return $response; |
303
|
|
|
} |
304
|
|
|
|
305
|
|
|
/** |
306
|
|
|
* retrieveHistory function. |
307
|
|
|
* |
308
|
|
|
* @access public |
309
|
|
|
* @final |
310
|
|
|
* @param Carbon $start |
311
|
|
|
* @param Carbon $end |
312
|
|
|
* @param string $url (default: false) |
313
|
|
|
* @return mixed |
314
|
|
|
*/ |
315
|
1 |
|
final public function retrieveHistory(Carbon $start, Carbon $end, $url = false) |
316
|
|
|
{ |
317
|
1 |
|
$this->domain('engHistDomain'); |
318
|
|
|
|
319
|
1 |
|
$url = $url ?: "https://{$this->domain}/interaction_history/api/account/{$this->account}/interactions/search?limit={$this->history_limit}&offset=0"; |
320
|
|
|
|
321
|
1 |
|
$start_str = $start->toW3cString(); |
322
|
1 |
|
$end_str = $end->toW3cString(); |
323
|
|
|
|
324
|
1 |
|
$data = new Payload([ |
325
|
1 |
|
'interactive' => $this->interactive, |
326
|
1 |
|
'ended' => $this->ended, |
327
|
|
|
'start' => [ |
328
|
1 |
|
'from' => strtotime($start_str) . '000', |
329
|
1 |
|
'to' => strtotime($end_str) . '000', |
330
|
|
|
], |
331
|
1 |
|
'skillIds' => $this->skills |
332
|
|
|
]); |
333
|
|
|
|
334
|
1 |
|
$result = $this->requestV1($url, 'POST', $data); |
|
|
|
|
335
|
1 |
|
$result->records = $result->interactionHistoryRecords; |
336
|
1 |
|
$result->interactionHistoryRecords = null; |
337
|
|
|
|
338
|
1 |
|
return $result; |
339
|
|
|
} |
340
|
|
|
|
341
|
|
|
/** |
342
|
|
|
* retrieveMsgHistory function. |
343
|
|
|
* |
344
|
|
|
* @access public |
345
|
|
|
* @final |
346
|
|
|
* @param Carbon $start |
347
|
|
|
* @param Carbon $end |
348
|
|
|
* @param string $url (default: false) |
349
|
|
|
* @return mixed |
350
|
|
|
*/ |
351
|
1 |
|
final public function retrieveMsgHistory(Carbon $start, Carbon $end, $url = false) |
352
|
|
|
{ |
353
|
1 |
|
$this->domain('msgHist'); |
354
|
|
|
|
355
|
1 |
|
$url = $url ?: "https://{$this->domain}/messaging_history/api/account/{$this->account}/conversations/search?limit={$this->history_limit}&offset=0&sort=start:desc"; |
356
|
|
|
|
357
|
1 |
|
$start_str = $start->toW3cString(); |
358
|
1 |
|
$end_str = $end->toW3cString(); |
359
|
|
|
|
360
|
1 |
|
$data = new Payload([ |
361
|
1 |
|
'status' => $this->ended ? ['CLOSE'] : ['OPEN', 'CLOSE'], |
362
|
|
|
'start' => [ |
363
|
1 |
|
'from' => strtotime($start_str) . '000', |
364
|
1 |
|
'to' => strtotime($end_str) . '000', |
365
|
|
|
], |
366
|
1 |
|
'skillIds' => $this->skills |
367
|
|
|
]); |
368
|
|
|
|
369
|
1 |
|
$result = $this->requestV1($url, 'POST', $data); |
|
|
|
|
370
|
1 |
|
$result->records = $result->conversationHistoryRecords; |
371
|
1 |
|
$result->conversationHistoryRecords = null; |
372
|
|
|
|
373
|
1 |
|
return $result; |
374
|
|
|
} |
375
|
|
|
|
376
|
|
|
/** |
377
|
|
|
* skills function gets collection of skills associated with the account. |
378
|
|
|
* |
379
|
|
|
* @access public |
380
|
|
|
* @return Collections\Skills |
381
|
|
|
*/ |
382
|
1 |
|
public function skills() |
383
|
|
|
{ |
384
|
1 |
|
$this->domain('accountConfigReadOnly'); |
385
|
|
|
|
386
|
1 |
|
$url = "https://{$this->domain}/api/account/{$this->account}/configuration/le-users/skills?v=4.0"; |
387
|
|
|
|
388
|
1 |
|
return new Skills($this->requestV2($url, 'GET')); |
|
|
|
|
389
|
|
|
} |
390
|
|
|
|
391
|
|
|
/** |
392
|
|
|
* getSkill function gets skill object based on ID. |
393
|
|
|
* |
394
|
|
|
* @access public |
395
|
|
|
* @param int $skillId |
396
|
|
|
* @return Models\Skill |
397
|
|
|
*/ |
398
|
1 |
|
public function getSkill($skillId) |
399
|
|
|
{ |
400
|
1 |
|
$this->domain('accountConfigReadOnly'); |
401
|
|
|
|
402
|
1 |
|
$url = "https://{$this->domain}/api/account/{$this->account}/configuration/le-users/skills/{$skillId}?v=4.0"; |
403
|
|
|
|
404
|
1 |
|
return new Skill((array) $this->requestV2($url, 'GET')); |
|
|
|
|
405
|
|
|
} |
406
|
|
|
|
407
|
|
|
/** |
408
|
|
|
* getAgent function gets agent object based on ID. |
409
|
|
|
* |
410
|
|
|
* @access public |
411
|
|
|
* @param int $userId |
412
|
|
|
* @return Models\Agent |
413
|
|
|
*/ |
414
|
1 |
|
public function getAgent($userId) |
415
|
|
|
{ |
416
|
1 |
|
$this->domain('accountConfigReadOnly'); |
417
|
|
|
|
418
|
1 |
|
$url = "https://{$this->domain}/api/account/{$this->account}/configuration/le-users/users/{$userId}?v=4.0"; |
419
|
|
|
|
420
|
1 |
|
return new Agent((array) $this->requestV2($url, 'GET')); |
|
|
|
|
421
|
|
|
} |
422
|
|
|
|
423
|
|
|
/** |
424
|
|
|
* updateAgent function. |
425
|
|
|
* |
426
|
|
|
* @access public |
427
|
|
|
* @param mixed $userId |
428
|
|
|
* @param mixed $properties |
429
|
|
|
* @return void |
430
|
|
|
* @codeCoverageIgnore |
431
|
|
|
*/ |
432
|
|
|
public function updateAgent($userId, $properties) |
433
|
|
|
{ |
434
|
|
|
$agent = $this->getAgent($userId); |
|
|
|
|
435
|
|
|
|
436
|
|
|
$this->domain('accountConfigReadWrite'); |
437
|
|
|
|
438
|
|
|
$url = "https://{$this->domain}/api/account/{$this->account}/configuration/le-users/users/{$userId}?v=4.0"; |
439
|
|
|
$headers = [ |
440
|
|
|
'X-HTTP-Method-Override' => 'PUT', |
441
|
|
|
'if-Match' => '*' |
442
|
|
|
]; |
443
|
|
|
|
444
|
|
|
return new Agent((array) $this->requestV2($url, 'PUT', $properties, $headers)); |
|
|
|
|
445
|
|
|
} |
446
|
|
|
|
447
|
|
|
/** |
448
|
|
|
* agents function gets collection of agents from account. |
449
|
|
|
* |
450
|
|
|
* @access public |
451
|
|
|
* @return Collections\AgentParticipants |
452
|
|
|
*/ |
453
|
1 |
|
public function agents() |
454
|
|
|
{ |
455
|
1 |
|
$this->domain('accountConfigReadOnly'); |
456
|
|
|
|
457
|
1 |
|
$select = implode(',', [ |
458
|
1 |
|
'id', |
459
|
|
|
'pid', |
460
|
|
|
'deleted', |
461
|
|
|
'loginName', |
462
|
|
|
'skills', |
463
|
|
|
'nickname', |
464
|
|
|
'dateCreated', |
465
|
|
|
'userTypeId', |
466
|
|
|
'isApiUser', |
467
|
|
|
'profileIds', |
468
|
|
|
'permissionGroups', |
469
|
|
|
'allowedAppKeys', |
470
|
|
|
'changePwdNextLogin', |
471
|
|
|
'maxChats', |
472
|
|
|
'skillIds', |
473
|
|
|
'lpaCreatedUser', |
474
|
|
|
'email', |
475
|
|
|
'lobs', |
476
|
|
|
'profiles', |
477
|
|
|
'fullName', |
478
|
|
|
'employeeId', |
479
|
|
|
'managedAgentGroups', |
480
|
|
|
'dateUpdated', |
481
|
|
|
'isEnabled', |
482
|
|
|
'lastPwdChangeDate', |
483
|
|
|
'pictureUrl' |
484
|
|
|
]); |
485
|
|
|
|
486
|
1 |
|
$url = "https://{$this->domain}/api/account/{$this->account}/configuration/le-users/users?v=4.0&select=$select"; |
487
|
|
|
|
488
|
1 |
|
return new AgentParticipants($this->requestV2($url, 'GET')); |
|
|
|
|
489
|
|
|
} |
490
|
|
|
|
491
|
|
|
/** |
492
|
|
|
* getAgentStatus function gets status of agents based on provided Skill IDs. |
493
|
|
|
* |
494
|
|
|
* @access public |
495
|
|
|
* @param int/array $skills |
|
|
|
|
496
|
|
|
* @return Collections\AgentParticipants |
497
|
|
|
*/ |
498
|
1 |
|
public function getAgentStatus($skills) |
499
|
|
|
{ |
500
|
1 |
|
$skills = is_array($skills) ? $skills : [$skills]; |
501
|
|
|
|
502
|
1 |
|
$this->domain('msgHist'); |
503
|
|
|
|
504
|
1 |
|
$url = "https://{$this->domain}/messaging_history/api/account/{$this->account}/agent-view/status"; |
505
|
|
|
|
506
|
1 |
|
$data = ['skillIds' => $skills]; |
507
|
|
|
|
508
|
1 |
|
$response = $this->requestV1($url, 'POST', $data); |
509
|
1 |
|
$collection = new AgentParticipants($response->agentStatusRecords); |
510
|
1 |
|
$collection->metaData = new MetaData((array) $response->_metadata); |
511
|
|
|
|
512
|
1 |
|
return $collection; |
513
|
|
|
|
514
|
|
|
} |
515
|
|
|
|
516
|
|
|
/** |
517
|
|
|
* conversationHistory function. |
518
|
|
|
* |
519
|
|
|
* @access public |
520
|
|
|
* @param Carbon $start (default: null) |
521
|
|
|
* @param Carbon $end (default: null) |
522
|
|
|
* @param int/array $skills (default: []) |
|
|
|
|
523
|
|
|
* @return Collections\ConversationHistory |
524
|
|
|
*/ |
525
|
1 |
|
public function conversationHistory(Carbon $start = null, Carbon $end = null, $skills = []) |
526
|
|
|
{ |
527
|
1 |
|
$this->retry_counter = 0; |
528
|
1 |
|
$this->skills = $skills; |
529
|
|
|
|
530
|
1 |
|
$start = $start ?: (new Carbon())->today(); |
531
|
1 |
|
$end = $end ?: (new Carbon())->today()->addHours(23)->addMinutes(59); |
532
|
|
|
|
533
|
1 |
|
$results_object = $this->retrieveMsgHistory($start, $end); |
534
|
|
|
|
535
|
1 |
|
$results_object->_metadata->start = $start; |
536
|
1 |
|
$results_object->_metadata->end = $end; |
537
|
|
|
|
538
|
1 |
|
$meta = new MetaData((array) $results_object->_metadata); |
539
|
|
|
|
540
|
1 |
|
$collection = new ConversationHistory($results_object->records); |
541
|
1 |
|
$collection->metaData = $meta; |
542
|
|
|
|
543
|
1 |
|
return $collection; |
544
|
|
|
|
545
|
|
|
} |
546
|
|
|
|
547
|
|
|
/** |
548
|
|
|
* getConversation function. |
549
|
|
|
* |
550
|
|
|
* @access public |
551
|
|
|
* @param mixed $conversationId |
552
|
|
|
* @return Models\Conversation |
553
|
|
|
*/ |
554
|
1 |
|
public function getConversation($conversationId) |
555
|
|
|
{ |
556
|
1 |
|
$this->domain('msgHist'); |
557
|
|
|
|
558
|
1 |
|
$url = "https://{$this->domain}/messaging_history/api/account/{$this->account}/conversations/conversation/search"; |
559
|
|
|
|
560
|
1 |
|
$data = new Payload([ |
561
|
1 |
|
'conversationId' => $conversationId |
562
|
|
|
]); |
563
|
|
|
|
564
|
1 |
|
$result = $this->requestV1($url, 'POST', $data); |
|
|
|
|
565
|
1 |
|
if (!count($result->conversationHistoryRecords)) { |
566
|
|
|
return null; // @codeCoverageIgnore |
567
|
|
|
} |
568
|
|
|
|
569
|
1 |
|
return new Conversation((array) $result->conversationHistoryRecords[0]); |
570
|
|
|
} |
571
|
|
|
|
572
|
|
|
/** |
573
|
|
|
* engagementHistory function. |
574
|
|
|
* |
575
|
|
|
* @access public |
576
|
|
|
* @param Carbon $start (default: null) |
577
|
|
|
* @param Carbon $end (default: null) |
578
|
|
|
* @param int/array $skills (default: []) |
|
|
|
|
579
|
|
|
* @return Collections\EngagementHistory |
580
|
|
|
*/ |
581
|
1 |
|
public function engagementHistory(Carbon $start = null, Carbon $end = null, $skills = []) |
582
|
|
|
{ |
583
|
1 |
|
$this->retry_counter = 0; |
584
|
1 |
|
$this->skills = $skills; |
585
|
|
|
|
586
|
1 |
|
$start = $start ?: (new Carbon())->today(); |
587
|
1 |
|
$end = $end ?: (new Carbon())->today()->addHours(23)->addMinutes(59); |
588
|
|
|
|
589
|
1 |
|
$results_object = $this->retrieveHistory($start, $end); |
590
|
|
|
|
591
|
1 |
|
$results_object->_metadata->start = $start; |
592
|
1 |
|
$results_object->_metadata->end = $end; |
593
|
|
|
|
594
|
1 |
|
$meta = new MetaData((array) $results_object->_metadata); |
595
|
|
|
|
596
|
1 |
|
$collection = new EngagementHistory($results_object->records); |
597
|
1 |
|
$collection->metaData = $meta; |
598
|
|
|
|
599
|
1 |
|
return $collection; |
600
|
|
|
|
601
|
|
|
} |
602
|
|
|
|
603
|
|
|
/** |
604
|
|
|
* status function gets status of the account. |
605
|
|
|
* |
606
|
|
|
* @access public |
607
|
|
|
* @return Models\AccountStatus |
608
|
|
|
*/ |
609
|
1 |
|
public function status() |
610
|
|
|
{ |
611
|
1 |
|
$url = "https://status.liveperson.com/json?site={$this->account}"; |
612
|
|
|
|
613
|
1 |
|
$response = $this->requestV1($url, 'GET'); |
614
|
|
|
|
615
|
1 |
|
return new AccountStatus((array) $response); |
616
|
|
|
} |
617
|
|
|
|
618
|
|
|
/** |
619
|
|
|
* login function. |
620
|
|
|
* |
621
|
|
|
* @access public |
622
|
|
|
* @return this |
623
|
|
|
*/ |
624
|
1 |
|
public function login() |
625
|
|
|
{ |
626
|
1 |
|
$this->domain('agentVep'); |
627
|
|
|
|
628
|
1 |
|
$consumer_key = config("{$this->config}.key"); |
629
|
1 |
|
$consumer_secret = config("{$this->config}.secret"); |
630
|
1 |
|
$token = config("{$this->config}.token"); |
631
|
1 |
|
$secret = config("{$this->config}.token_secret"); |
632
|
1 |
|
$username = config("{$this->config}.user_name"); |
633
|
|
|
|
634
|
|
|
$auth = [ |
635
|
1 |
|
'username' => $username, |
636
|
1 |
|
'appKey' => $consumer_key, |
637
|
1 |
|
'secret' => $consumer_secret, |
638
|
1 |
|
'accessToken' => $token, |
639
|
1 |
|
'accessTokenSecret' => $secret, |
640
|
|
|
]; |
641
|
|
|
|
642
|
1 |
|
$url = "https://{$this->domain}/api/account/{$this->account}/login?v=1.3"; |
643
|
|
|
|
644
|
1 |
|
$response = $this->requestV1($url, 'POST', $auth); |
645
|
|
|
|
646
|
1 |
|
$this->bearer = $response->bearer; |
647
|
|
|
|
648
|
1 |
|
return $this; |
649
|
|
|
} |
650
|
|
|
|
651
|
|
|
/** |
652
|
|
|
* requestV2 function. |
653
|
|
|
* |
654
|
|
|
* @access private |
655
|
|
|
* @param mixed $url |
656
|
|
|
* @param mixed $method |
657
|
|
|
* @param mixed $payload (default: []) |
658
|
|
|
* @param mixed $headers (default: []) |
659
|
|
|
* @return void |
660
|
|
|
*/ |
661
|
1 |
|
private function requestV2($url, $method, $payload = [], $headers = []) |
662
|
|
|
{ |
663
|
1 |
|
$this->login(); |
664
|
|
|
|
665
|
1 |
|
$client = new Client(); |
666
|
|
|
$args = [ |
667
|
1 |
|
'headers' => array_merge([ |
668
|
1 |
|
'content-type' => 'application/json', |
669
|
1 |
|
'Authorization' => 'Bearer ' . $this->bearer |
670
|
1 |
|
], $headers), |
671
|
1 |
|
'body' => json_encode($payload) |
672
|
|
|
]; |
673
|
|
|
|
674
|
|
|
// @codeCoverageIgnoreStart |
675
|
|
|
try { |
676
|
|
|
$res = $client->request($method, $url, $args); |
677
|
|
|
} catch (\Exception $e) { |
678
|
|
|
throw $e; |
679
|
|
|
} |
680
|
|
|
// @codeCoverageIgnoreEnd |
681
|
|
|
|
682
|
1 |
|
return json_decode($res->getBody()); |
683
|
|
|
} |
684
|
|
|
|
685
|
|
|
/** |
686
|
|
|
* requestClient function. |
687
|
|
|
* |
688
|
|
|
* @access private |
689
|
|
|
* @return \GuzzleHttp\Client |
690
|
|
|
*/ |
691
|
2 |
|
private function requestClient() |
692
|
|
|
{ |
693
|
2 |
|
$consumer_key = config("{$this->config}.key"); |
694
|
2 |
|
$consumer_secret = config("{$this->config}.secret"); |
695
|
2 |
|
$token = config("{$this->config}.token"); |
696
|
2 |
|
$secret = config("{$this->config}.token_secret"); |
697
|
|
|
|
698
|
2 |
|
$stack = HandlerStack::create(); |
699
|
2 |
|
$auth = new Oauth1([ |
700
|
2 |
|
'consumer_key' => $consumer_key, |
701
|
2 |
|
'consumer_secret' => $consumer_secret, |
702
|
2 |
|
'token' => $token, |
703
|
2 |
|
'token_secret' => $secret, |
704
|
2 |
|
'signature_method'=> Oauth1::SIGNATURE_METHOD_HMAC, |
705
|
|
|
]); |
706
|
2 |
|
$stack->push($auth); |
707
|
|
|
|
708
|
2 |
|
$client = new Client([ |
709
|
2 |
|
'handler' => $stack, |
710
|
|
|
]); |
711
|
|
|
|
712
|
2 |
|
return $client; |
713
|
|
|
} |
714
|
|
|
|
715
|
|
|
/** |
716
|
|
|
* requestV1 - request bootstrap for older oauth supported APIs. |
717
|
|
|
* |
718
|
|
|
* @access private |
719
|
|
|
* @param string $url |
720
|
|
|
* @param string $method |
721
|
|
|
* @param array $payload (default: []) |
722
|
|
|
* @return mixed |
723
|
|
|
*/ |
724
|
1 |
|
private function requestV1($url, $method, $payload = []) |
725
|
|
|
{ |
726
|
1 |
|
$client = $this->requestClient(); |
727
|
|
|
|
728
|
|
|
$args = [ |
729
|
1 |
|
'auth' => 'oauth', |
730
|
|
|
'headers' => [ |
731
|
|
|
'content-type' => 'application/json', |
732
|
|
|
], |
733
|
1 |
|
'body' => json_encode($payload) |
734
|
|
|
]; |
735
|
|
|
|
736
|
|
|
try { |
737
|
1 |
|
$res = $client->request($method, $url, $args); |
738
|
1 |
|
$response = json_decode($res->getBody()); |
739
|
|
|
} catch (\Exception $e) { |
740
|
|
|
// @codeCoverageIgnoreStart |
741
|
|
|
if ($this->retry_counter < $this->retry_limit || $this->retry_limit == -1) { |
742
|
|
|
usleep(1500); |
743
|
|
|
$this->retry_counter++; |
744
|
|
|
$response = $this->requestV1($url, $payload); |
|
|
|
|
745
|
|
|
} else { |
746
|
|
|
throw $e; |
747
|
|
|
} |
748
|
|
|
// @codeCoverageIgnoreEnd |
749
|
|
|
} |
750
|
|
|
|
751
|
1 |
|
return $response; |
752
|
|
|
} |
753
|
|
|
} |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths