@@ -11,93 +11,93 @@ |
||
11 | 11 | |
12 | 12 | class EngagementHistory extends Collection |
13 | 13 | { |
14 | - private $instance; |
|
14 | + private $instance; |
|
15 | 15 | |
16 | - public function __construct(array $models = [], LiveEngageLaravel $instance = null) |
|
17 | - { |
|
18 | - $this->instance = $instance; |
|
16 | + public function __construct(array $models = [], LiveEngageLaravel $instance = null) |
|
17 | + { |
|
18 | + $this->instance = $instance; |
|
19 | 19 | |
20 | - return parent::__construct($models); |
|
21 | - } |
|
20 | + return parent::__construct($models); |
|
21 | + } |
|
22 | 22 | |
23 | - public function find($engagementID) |
|
24 | - { |
|
25 | - $result = $this->filter(function ($value, $key) use ($engagementID) { |
|
26 | - return $value->info->sessionId == $engagementID; |
|
27 | - }); |
|
23 | + public function find($engagementID) |
|
24 | + { |
|
25 | + $result = $this->filter(function ($value, $key) use ($engagementID) { |
|
26 | + return $value->info->sessionId == $engagementID; |
|
27 | + }); |
|
28 | 28 | |
29 | - return $result->first(); |
|
30 | - } |
|
29 | + return $result->first(); |
|
30 | + } |
|
31 | 31 | |
32 | - public function next() |
|
33 | - { |
|
34 | - if (! $this->instance) { |
|
35 | - return false; |
|
36 | - } |
|
32 | + public function next() |
|
33 | + { |
|
34 | + if (! $this->instance) { |
|
35 | + return false; |
|
36 | + } |
|
37 | 37 | |
38 | - $instance = $this->instance; |
|
38 | + $instance = $this->instance; |
|
39 | 39 | |
40 | - $next = $instance->retrieveHistory($instance->start, $instance->end, $instance->next); |
|
41 | - if (property_exists($next->_metadata, 'next')) { |
|
42 | - $instance->next = $next->_metadata->next->href; |
|
40 | + $next = $instance->retrieveHistory($instance->start, $instance->end, $instance->next); |
|
41 | + if (property_exists($next->_metadata, 'next')) { |
|
42 | + $instance->next = $next->_metadata->next->href; |
|
43 | 43 | |
44 | - $history = []; |
|
45 | - foreach ($next->interactionHistoryRecords as $item) { |
|
44 | + $history = []; |
|
45 | + foreach ($next->interactionHistoryRecords as $item) { |
|
46 | 46 | |
47 | - if (property_exists($item, 'info')) { |
|
48 | - $item->info = new Info((array) $item->info); |
|
49 | - } |
|
47 | + if (property_exists($item, 'info')) { |
|
48 | + $item->info = new Info((array) $item->info); |
|
49 | + } |
|
50 | 50 | |
51 | - if (property_exists($item, 'visitorInfo')) { |
|
52 | - $item->visitorInfo = new Visitor((array) $item->visitorInfo); |
|
53 | - } |
|
51 | + if (property_exists($item, 'visitorInfo')) { |
|
52 | + $item->visitorInfo = new Visitor((array) $item->visitorInfo); |
|
53 | + } |
|
54 | 54 | |
55 | - if (property_exists($item, 'campaign')) { |
|
56 | - $item->campaign = new Campaign((array) $item->campaign); |
|
57 | - } |
|
55 | + if (property_exists($item, 'campaign')) { |
|
56 | + $item->campaign = new Campaign((array) $item->campaign); |
|
57 | + } |
|
58 | 58 | |
59 | - $history[] = new Engagement((array) $item); |
|
60 | - } |
|
59 | + $history[] = new Engagement((array) $item); |
|
60 | + } |
|
61 | 61 | |
62 | - return $this->merge(new EngagementHistory($history)); |
|
63 | - } else { |
|
64 | - return false; |
|
65 | - } |
|
66 | - } |
|
62 | + return $this->merge(new EngagementHistory($history)); |
|
63 | + } else { |
|
64 | + return false; |
|
65 | + } |
|
66 | + } |
|
67 | 67 | |
68 | - public function prev() |
|
69 | - { |
|
70 | - if (! $this->instance) { |
|
71 | - return false; |
|
72 | - } |
|
68 | + public function prev() |
|
69 | + { |
|
70 | + if (! $this->instance) { |
|
71 | + return false; |
|
72 | + } |
|
73 | 73 | |
74 | - $instance = $this->instance; |
|
74 | + $instance = $this->instance; |
|
75 | 75 | |
76 | - $prev = $instance->retrieveHistory($instance->start, $instance->end, $instance->prev); |
|
77 | - if (property_exists($prev->_metadata, 'prev')) { |
|
78 | - $instance->prev = $prev->_metadata->prev->href; |
|
76 | + $prev = $instance->retrieveHistory($instance->start, $instance->end, $instance->prev); |
|
77 | + if (property_exists($prev->_metadata, 'prev')) { |
|
78 | + $instance->prev = $prev->_metadata->prev->href; |
|
79 | 79 | |
80 | - $history = []; |
|
81 | - foreach ($next->interactionHistoryRecords as $item) { |
|
80 | + $history = []; |
|
81 | + foreach ($next->interactionHistoryRecords as $item) { |
|
82 | 82 | |
83 | - if (property_exists($item, 'info')) { |
|
84 | - $item->info = new Info((array) $item->info); |
|
85 | - } |
|
83 | + if (property_exists($item, 'info')) { |
|
84 | + $item->info = new Info((array) $item->info); |
|
85 | + } |
|
86 | 86 | |
87 | - if (property_exists($item, 'visitorInfo')) { |
|
88 | - $item->visitorInfo = new Visitor((array) $item->visitorInfo); |
|
89 | - } |
|
87 | + if (property_exists($item, 'visitorInfo')) { |
|
88 | + $item->visitorInfo = new Visitor((array) $item->visitorInfo); |
|
89 | + } |
|
90 | 90 | |
91 | - if (property_exists($item, 'campaign')) { |
|
92 | - $item->campaign = new Campaign((array) $item->campaign); |
|
93 | - } |
|
91 | + if (property_exists($item, 'campaign')) { |
|
92 | + $item->campaign = new Campaign((array) $item->campaign); |
|
93 | + } |
|
94 | 94 | |
95 | - $history[] = new Engagement((array) $item); |
|
96 | - } |
|
95 | + $history[] = new Engagement((array) $item); |
|
96 | + } |
|
97 | 97 | |
98 | - return $this->merge(new self($history)); |
|
99 | - } else { |
|
100 | - return false; |
|
101 | - } |
|
102 | - } |
|
98 | + return $this->merge(new self($history)); |
|
99 | + } else { |
|
100 | + return false; |
|
101 | + } |
|
102 | + } |
|
103 | 103 | } |
@@ -11,89 +11,89 @@ |
||
11 | 11 | |
12 | 12 | class ConversationHistory extends Collection |
13 | 13 | { |
14 | - private $instance; |
|
14 | + private $instance; |
|
15 | 15 | |
16 | - public function __construct(array $models = [], LiveEngageLaravel $instance = null) |
|
17 | - { |
|
18 | - $this->instance = $instance; |
|
16 | + public function __construct(array $models = [], LiveEngageLaravel $instance = null) |
|
17 | + { |
|
18 | + $this->instance = $instance; |
|
19 | 19 | |
20 | - parent::__construct($models); |
|
21 | - } |
|
20 | + parent::__construct($models); |
|
21 | + } |
|
22 | 22 | |
23 | - public function find($engagementID) |
|
24 | - { |
|
25 | - $result = $this->filter(function ($value, $key) use ($engagementID) { |
|
26 | - return $value->info->conversationId == $engagementID; |
|
27 | - }); |
|
23 | + public function find($engagementID) |
|
24 | + { |
|
25 | + $result = $this->filter(function ($value, $key) use ($engagementID) { |
|
26 | + return $value->info->conversationId == $engagementID; |
|
27 | + }); |
|
28 | 28 | |
29 | - return $result->first(); |
|
30 | - } |
|
29 | + return $result->first(); |
|
30 | + } |
|
31 | 31 | |
32 | - public function next() |
|
33 | - { |
|
34 | - if (! $this->instance) { |
|
35 | - return false; |
|
36 | - } |
|
32 | + public function next() |
|
33 | + { |
|
34 | + if (! $this->instance) { |
|
35 | + return false; |
|
36 | + } |
|
37 | 37 | |
38 | - $instance = $this->instance; |
|
38 | + $instance = $this->instance; |
|
39 | 39 | |
40 | - $next = $instance->retrieveMsgHistory($instance->start, $instance->end, $instance->next); |
|
41 | - if (property_exists($next->_metadata, 'next')) { |
|
42 | - $instance->next = $next->_metadata->next->href; |
|
40 | + $next = $instance->retrieveMsgHistory($instance->start, $instance->end, $instance->next); |
|
41 | + if (property_exists($next->_metadata, 'next')) { |
|
42 | + $instance->next = $next->_metadata->next->href; |
|
43 | 43 | |
44 | - $history = []; |
|
45 | - foreach ($next->conversationHistoryRecords as $item) { |
|
46 | - if (property_exists($item, 'info')) { |
|
47 | - $item->info = new Info((array) $item->info); |
|
48 | - } |
|
44 | + $history = []; |
|
45 | + foreach ($next->conversationHistoryRecords as $item) { |
|
46 | + if (property_exists($item, 'info')) { |
|
47 | + $item->info = new Info((array) $item->info); |
|
48 | + } |
|
49 | 49 | |
50 | - if (property_exists($item, 'visitorInfo')) { |
|
51 | - $item->visitorInfo = new Visitor((array) $item->visitorInfo); |
|
52 | - } |
|
50 | + if (property_exists($item, 'visitorInfo')) { |
|
51 | + $item->visitorInfo = new Visitor((array) $item->visitorInfo); |
|
52 | + } |
|
53 | 53 | |
54 | - if (property_exists($item, 'campaign')) { |
|
55 | - $item->campaign = new Campaign((array) $item->campaign); |
|
56 | - } |
|
57 | - $history[] = new Conversation((array) $item); |
|
58 | - } |
|
54 | + if (property_exists($item, 'campaign')) { |
|
55 | + $item->campaign = new Campaign((array) $item->campaign); |
|
56 | + } |
|
57 | + $history[] = new Conversation((array) $item); |
|
58 | + } |
|
59 | 59 | |
60 | - return $this->merge(new self($history)); |
|
61 | - } else { |
|
62 | - return false; |
|
63 | - } |
|
64 | - } |
|
60 | + return $this->merge(new self($history)); |
|
61 | + } else { |
|
62 | + return false; |
|
63 | + } |
|
64 | + } |
|
65 | 65 | |
66 | - public function prev() |
|
67 | - { |
|
68 | - if (! $this->instance) { |
|
69 | - return false; |
|
70 | - } |
|
66 | + public function prev() |
|
67 | + { |
|
68 | + if (! $this->instance) { |
|
69 | + return false; |
|
70 | + } |
|
71 | 71 | |
72 | - $instance = $this->instance; |
|
72 | + $instance = $this->instance; |
|
73 | 73 | |
74 | - $prev = $instance->retrieveMsgHistory($instance->start, $instance->end, $instance->prev); |
|
75 | - if (property_exists($prev->_metadata, 'prev')) { |
|
76 | - $instance->prev = $prev->_metadata->prev->href; |
|
74 | + $prev = $instance->retrieveMsgHistory($instance->start, $instance->end, $instance->prev); |
|
75 | + if (property_exists($prev->_metadata, 'prev')) { |
|
76 | + $instance->prev = $prev->_metadata->prev->href; |
|
77 | 77 | |
78 | - $history = []; |
|
79 | - foreach ($next->conversationHistoryRecords as $item) { |
|
80 | - if (property_exists($item, 'info')) { |
|
81 | - $item->info = new Info((array) $item->info); |
|
82 | - } |
|
78 | + $history = []; |
|
79 | + foreach ($next->conversationHistoryRecords as $item) { |
|
80 | + if (property_exists($item, 'info')) { |
|
81 | + $item->info = new Info((array) $item->info); |
|
82 | + } |
|
83 | 83 | |
84 | - if (property_exists($item, 'visitorInfo')) { |
|
85 | - $item->visitorInfo = new Visitor((array) $item->visitorInfo); |
|
86 | - } |
|
84 | + if (property_exists($item, 'visitorInfo')) { |
|
85 | + $item->visitorInfo = new Visitor((array) $item->visitorInfo); |
|
86 | + } |
|
87 | 87 | |
88 | - if (property_exists($item, 'campaign')) { |
|
89 | - $item->campaign = new Campaign((array) $item->campaign); |
|
90 | - } |
|
91 | - $history[] = new Conversation((array) $item); |
|
92 | - } |
|
88 | + if (property_exists($item, 'campaign')) { |
|
89 | + $item->campaign = new Campaign((array) $item->campaign); |
|
90 | + } |
|
91 | + $history[] = new Conversation((array) $item); |
|
92 | + } |
|
93 | 93 | |
94 | - return $this->merge(new self($history)); |
|
95 | - } else { |
|
96 | - return false; |
|
97 | - } |
|
98 | - } |
|
94 | + return $this->merge(new self($history)); |
|
95 | + } else { |
|
96 | + return false; |
|
97 | + } |
|
98 | + } |
|
99 | 99 | } |
@@ -18,320 +18,320 @@ |
||
18 | 18 | |
19 | 19 | class LiveEngageLaravel |
20 | 20 | { |
21 | - private $account = false; |
|
22 | - private $results = []; |
|
23 | - private $skills = []; |
|
24 | - private $next = false; |
|
25 | - private $prev = false; |
|
26 | - private $start; |
|
27 | - private $end; |
|
28 | - private $config = 'services.liveperson.default'; |
|
29 | - private $version = '1.0'; |
|
30 | - private $history_limit = 50; |
|
31 | - private $history = false; |
|
32 | - private $context = 'interactionHistoryRecords'; |
|
33 | - private $interactive = true; |
|
34 | - private $ended = true; |
|
35 | - |
|
36 | - private $domain = false; |
|
37 | - |
|
38 | - private $retry_limit = 5; |
|
39 | - private $retry_counter = 0; |
|
40 | - |
|
41 | - public function __get($attribute) |
|
42 | - { |
|
43 | - return $this->$attribute; |
|
44 | - } |
|
45 | - |
|
46 | - public function __set($attribute, $value) |
|
47 | - { |
|
48 | - return $this->$attribute = $value; |
|
49 | - } |
|
50 | - |
|
51 | - public function __construct() |
|
52 | - { |
|
53 | - $this->account = config("{$this->config}.account"); |
|
54 | - $this->domain = config("{$this->config}.domain"); |
|
55 | - $this->version = config("{$this->config}.version") ?: $this->version; |
|
56 | - } |
|
57 | - |
|
58 | - public function key($key = 'default') |
|
59 | - { |
|
60 | - $this->config = "services.liveperson.$key"; |
|
61 | - |
|
62 | - return $this; |
|
63 | - } |
|
21 | + private $account = false; |
|
22 | + private $results = []; |
|
23 | + private $skills = []; |
|
24 | + private $next = false; |
|
25 | + private $prev = false; |
|
26 | + private $start; |
|
27 | + private $end; |
|
28 | + private $config = 'services.liveperson.default'; |
|
29 | + private $version = '1.0'; |
|
30 | + private $history_limit = 50; |
|
31 | + private $history = false; |
|
32 | + private $context = 'interactionHistoryRecords'; |
|
33 | + private $interactive = true; |
|
34 | + private $ended = true; |
|
35 | + |
|
36 | + private $domain = false; |
|
37 | + |
|
38 | + private $retry_limit = 5; |
|
39 | + private $retry_counter = 0; |
|
40 | + |
|
41 | + public function __get($attribute) |
|
42 | + { |
|
43 | + return $this->$attribute; |
|
44 | + } |
|
45 | + |
|
46 | + public function __set($attribute, $value) |
|
47 | + { |
|
48 | + return $this->$attribute = $value; |
|
49 | + } |
|
50 | + |
|
51 | + public function __construct() |
|
52 | + { |
|
53 | + $this->account = config("{$this->config}.account"); |
|
54 | + $this->domain = config("{$this->config}.domain"); |
|
55 | + $this->version = config("{$this->config}.version") ?: $this->version; |
|
56 | + } |
|
57 | + |
|
58 | + public function key($key = 'default') |
|
59 | + { |
|
60 | + $this->config = "services.liveperson.$key"; |
|
61 | + |
|
62 | + return $this; |
|
63 | + } |
|
64 | 64 | |
65 | - public function nonInteractive() |
|
66 | - { |
|
67 | - $this->interactive = false; |
|
68 | - return $this; |
|
69 | - } |
|
65 | + public function nonInteractive() |
|
66 | + { |
|
67 | + $this->interactive = false; |
|
68 | + return $this; |
|
69 | + } |
|
70 | 70 | |
71 | - public function active() |
|
72 | - { |
|
73 | - $this->ended = false; |
|
74 | - return $this; |
|
75 | - } |
|
76 | - |
|
77 | - public function limit($limit) |
|
78 | - { |
|
79 | - $this->history_limit = $limit; |
|
80 | - |
|
81 | - return $this; |
|
82 | - } |
|
83 | - |
|
84 | - public function skills($skills) |
|
85 | - { |
|
86 | - $this->skills = $skills; |
|
87 | - |
|
88 | - return $this; |
|
89 | - } |
|
90 | - |
|
91 | - public function retry($limit) |
|
92 | - { |
|
93 | - $this->retry_limit = $limit; |
|
94 | - |
|
95 | - return $this; |
|
96 | - } |
|
97 | - |
|
98 | - public function get() |
|
99 | - { |
|
100 | - return $this->results; |
|
101 | - } |
|
102 | - |
|
103 | - public function account($accountid) |
|
104 | - { |
|
105 | - $this->account = $accountid; |
|
106 | - |
|
107 | - return $this; |
|
108 | - } |
|
109 | - |
|
110 | - public function domain($service) |
|
111 | - { |
|
112 | - $response = $this->request("https://api.liveperson.net/api/account/{$this->account}/service/{$service}/baseURI.json?version={$this->version}", 'GET'); |
|
113 | - if (is_a($response, 'Exception')) { |
|
114 | - throw new \Exception('Unable to get LivePerson account domain', 101); |
|
115 | - } else { |
|
116 | - $this->domain = $response->baseURI; |
|
117 | - |
|
118 | - return $this; |
|
119 | - } |
|
120 | - } |
|
121 | - |
|
122 | - public function visitor($visitorID, $sessionID, $setData = false) |
|
123 | - { |
|
124 | - if (! $this->domain) { |
|
125 | - $this->domain('smt'); |
|
126 | - } |
|
127 | - |
|
128 | - if ($setData) { |
|
129 | - $url = "https://{$this->domain}/api/account/{$this->account}/monitoring/visitors/{$visitorID}/visits/current/events?v=1&sid={$sessionID}"; |
|
130 | - |
|
131 | - return $this->request($url, 'POST', $setData); |
|
132 | - } else { |
|
133 | - $url = "https://{$this->domain}/api/account/{$this->account}/monitoring/visitors/{$visitorID}/visits/current/state?v=1&sid={$sessionID}"; |
|
134 | - |
|
135 | - return $this->request($url, 'GET'); |
|
136 | - } |
|
137 | - } |
|
138 | - |
|
139 | - public function agentStatus() |
|
140 | - { |
|
141 | - if (! $this->domain) { |
|
142 | - $this->domain('msgHist'); |
|
143 | - } |
|
144 | - |
|
145 | - $url = "https://{$this->domain}/messaging_history/api/account/{$this->account}/agent-view/status"; |
|
146 | - |
|
147 | - return $this->request($url, 'POST', new Payload(['skillIds' => $this->skills])); |
|
148 | - } |
|
149 | - |
|
150 | - final public function retrieveHistory(Carbon $start, Carbon $end, $url = false) |
|
151 | - { |
|
152 | - if (! $this->domain) { |
|
153 | - $this->domain('engHistDomain'); |
|
154 | - } |
|
155 | - |
|
156 | - $url = $url ?: "https://{$this->domain}/interaction_history/api/account/{$this->account}/interactions/search?limit={$this->history_limit}&offset=0"; |
|
157 | - |
|
158 | - $start_str = $start->toW3cString(); |
|
159 | - $end_str = $end->toW3cString(); |
|
160 | - |
|
161 | - $data = [ |
|
162 | - 'interactive' => $this->interactive, |
|
163 | - 'ended' => $this->ended, |
|
164 | - 'start' => [ |
|
165 | - 'from' => strtotime($start_str).'000', |
|
166 | - 'to' => strtotime($end_str).'000', |
|
167 | - ], |
|
168 | - ]; |
|
169 | - if (count($this->skills)) { |
|
170 | - $data['skillIds'] = $this->skills; |
|
171 | - } |
|
172 | - |
|
173 | - $data = new Payload($data); |
|
174 | - |
|
175 | - return $this->request($url, 'POST', $data); |
|
176 | - } |
|
177 | - |
|
178 | - final public function retrieveMsgHistory(Carbon $start, Carbon $end, $url = false) |
|
179 | - { |
|
180 | - if (! $this->domain) { |
|
181 | - $this->domain('msgHist'); |
|
182 | - } |
|
183 | - |
|
184 | - $url = $url ?: "https://{$this->domain}/messaging_history/api/account/{$this->account}/conversations/search?limit={$this->history_limit}&offset=0"; |
|
185 | - |
|
186 | - $start_str = $start->toW3cString(); |
|
187 | - $end_str = $end->toW3cString(); |
|
188 | - |
|
189 | - $data = [ |
|
190 | - 'interactive' => $this->interactive, |
|
191 | - 'ended' => $this->ended, |
|
192 | - 'start' => [ |
|
193 | - 'from' => strtotime($start_str).'000', |
|
194 | - 'to' => strtotime($end_str).'000', |
|
195 | - ], |
|
196 | - ]; |
|
197 | - if (count($this->skills)) { |
|
198 | - $data['skillIds'] = $this->skills; |
|
199 | - } |
|
200 | - |
|
201 | - $data = new Payload($data); |
|
202 | - |
|
203 | - return $this->request($url, 'POST', $data); |
|
204 | - } |
|
205 | - |
|
206 | - public function messagingHistory(Carbon $start = null, Carbon $end = null) |
|
207 | - { |
|
208 | - $this->retry_counter = 0; |
|
209 | - |
|
210 | - $start = $start ?: (new Carbon())->today(); |
|
211 | - $end = $end ?: (new Carbon())->today()->addHours(23)->addMinutes(59); |
|
212 | - |
|
213 | - $this->start = $start; |
|
214 | - $this->end = $end; |
|
215 | - |
|
216 | - $results_object = $this->retrieveMsgHistory($start, $end); |
|
217 | - $results = $results_object->conversationHistoryRecords; |
|
218 | - if (property_exists($results_object->_metadata, 'next')) { |
|
219 | - $this->next = $results_object->_metadata->next->href; |
|
220 | - } |
|
221 | - if (property_exists($results_object->_metadata, 'prev')) { |
|
222 | - $this->prev = $results_object->_metadata->prev->href; |
|
223 | - } |
|
224 | - |
|
225 | - $history = []; |
|
226 | - foreach ($results as $item) { |
|
227 | - if (property_exists($item, 'info')) { |
|
228 | - $item->info = new Info((array) $item->info); |
|
229 | - } |
|
230 | - |
|
231 | - if (property_exists($item, 'visitorInfo')) { |
|
232 | - $item->visitorInfo = new Visitor((array) $item->visitorInfo); |
|
233 | - } |
|
234 | - |
|
235 | - if (property_exists($item, 'campaign')) { |
|
236 | - $item->campaign = new Campaign((array) $item->campaign); |
|
237 | - } |
|
238 | - |
|
239 | - $history[] = new Conversation((array) $item); |
|
240 | - } |
|
241 | - |
|
242 | - return new ConversationHistory($history, $this); |
|
243 | - } |
|
244 | - |
|
245 | - public function history(Carbon $start = null, Carbon $end = null) |
|
246 | - { |
|
247 | - $this->retry_counter = 0; |
|
248 | - |
|
249 | - $start = $start ?: (new Carbon())->today(); |
|
250 | - $end = $end ?: (new Carbon())->today()->addHours(23)->addMinutes(59); |
|
251 | - |
|
252 | - $this->start = $start; |
|
253 | - $this->end = $end; |
|
254 | - |
|
255 | - $results_object = $this->retrieveHistory($start, $end); |
|
256 | - $results = $results_object->interactionHistoryRecords; |
|
257 | - if (property_exists($results_object->_metadata, 'next')) { |
|
258 | - $this->next = $results_object->_metadata->next->href; |
|
259 | - } |
|
260 | - if (property_exists($results_object->_metadata, 'prev')) { |
|
261 | - $this->prev = $results_object->_metadata->prev->href; |
|
262 | - } |
|
263 | - |
|
264 | - $history = []; |
|
265 | - foreach ($results as $item) { |
|
266 | - if (property_exists($item, 'info')) { |
|
267 | - $item->info = new Info((array) $item->info); |
|
268 | - } |
|
269 | - |
|
270 | - if (property_exists($item, 'visitorInfo')) { |
|
271 | - $item->visitorInfo = new Visitor((array) $item->visitorInfo); |
|
272 | - } |
|
273 | - |
|
274 | - if (property_exists($item, 'campaign')) { |
|
275 | - $item->campaign = new Campaign((array) $item->campaign); |
|
276 | - } |
|
277 | - |
|
278 | - $history[] = new Engagement((array) $item); |
|
279 | - } |
|
71 | + public function active() |
|
72 | + { |
|
73 | + $this->ended = false; |
|
74 | + return $this; |
|
75 | + } |
|
76 | + |
|
77 | + public function limit($limit) |
|
78 | + { |
|
79 | + $this->history_limit = $limit; |
|
80 | + |
|
81 | + return $this; |
|
82 | + } |
|
83 | + |
|
84 | + public function skills($skills) |
|
85 | + { |
|
86 | + $this->skills = $skills; |
|
87 | + |
|
88 | + return $this; |
|
89 | + } |
|
90 | + |
|
91 | + public function retry($limit) |
|
92 | + { |
|
93 | + $this->retry_limit = $limit; |
|
94 | + |
|
95 | + return $this; |
|
96 | + } |
|
97 | + |
|
98 | + public function get() |
|
99 | + { |
|
100 | + return $this->results; |
|
101 | + } |
|
102 | + |
|
103 | + public function account($accountid) |
|
104 | + { |
|
105 | + $this->account = $accountid; |
|
106 | + |
|
107 | + return $this; |
|
108 | + } |
|
109 | + |
|
110 | + public function domain($service) |
|
111 | + { |
|
112 | + $response = $this->request("https://api.liveperson.net/api/account/{$this->account}/service/{$service}/baseURI.json?version={$this->version}", 'GET'); |
|
113 | + if (is_a($response, 'Exception')) { |
|
114 | + throw new \Exception('Unable to get LivePerson account domain', 101); |
|
115 | + } else { |
|
116 | + $this->domain = $response->baseURI; |
|
117 | + |
|
118 | + return $this; |
|
119 | + } |
|
120 | + } |
|
121 | + |
|
122 | + public function visitor($visitorID, $sessionID, $setData = false) |
|
123 | + { |
|
124 | + if (! $this->domain) { |
|
125 | + $this->domain('smt'); |
|
126 | + } |
|
127 | + |
|
128 | + if ($setData) { |
|
129 | + $url = "https://{$this->domain}/api/account/{$this->account}/monitoring/visitors/{$visitorID}/visits/current/events?v=1&sid={$sessionID}"; |
|
130 | + |
|
131 | + return $this->request($url, 'POST', $setData); |
|
132 | + } else { |
|
133 | + $url = "https://{$this->domain}/api/account/{$this->account}/monitoring/visitors/{$visitorID}/visits/current/state?v=1&sid={$sessionID}"; |
|
134 | + |
|
135 | + return $this->request($url, 'GET'); |
|
136 | + } |
|
137 | + } |
|
138 | + |
|
139 | + public function agentStatus() |
|
140 | + { |
|
141 | + if (! $this->domain) { |
|
142 | + $this->domain('msgHist'); |
|
143 | + } |
|
144 | + |
|
145 | + $url = "https://{$this->domain}/messaging_history/api/account/{$this->account}/agent-view/status"; |
|
146 | + |
|
147 | + return $this->request($url, 'POST', new Payload(['skillIds' => $this->skills])); |
|
148 | + } |
|
149 | + |
|
150 | + final public function retrieveHistory(Carbon $start, Carbon $end, $url = false) |
|
151 | + { |
|
152 | + if (! $this->domain) { |
|
153 | + $this->domain('engHistDomain'); |
|
154 | + } |
|
155 | + |
|
156 | + $url = $url ?: "https://{$this->domain}/interaction_history/api/account/{$this->account}/interactions/search?limit={$this->history_limit}&offset=0"; |
|
157 | + |
|
158 | + $start_str = $start->toW3cString(); |
|
159 | + $end_str = $end->toW3cString(); |
|
160 | + |
|
161 | + $data = [ |
|
162 | + 'interactive' => $this->interactive, |
|
163 | + 'ended' => $this->ended, |
|
164 | + 'start' => [ |
|
165 | + 'from' => strtotime($start_str).'000', |
|
166 | + 'to' => strtotime($end_str).'000', |
|
167 | + ], |
|
168 | + ]; |
|
169 | + if (count($this->skills)) { |
|
170 | + $data['skillIds'] = $this->skills; |
|
171 | + } |
|
172 | + |
|
173 | + $data = new Payload($data); |
|
174 | + |
|
175 | + return $this->request($url, 'POST', $data); |
|
176 | + } |
|
177 | + |
|
178 | + final public function retrieveMsgHistory(Carbon $start, Carbon $end, $url = false) |
|
179 | + { |
|
180 | + if (! $this->domain) { |
|
181 | + $this->domain('msgHist'); |
|
182 | + } |
|
183 | + |
|
184 | + $url = $url ?: "https://{$this->domain}/messaging_history/api/account/{$this->account}/conversations/search?limit={$this->history_limit}&offset=0"; |
|
185 | + |
|
186 | + $start_str = $start->toW3cString(); |
|
187 | + $end_str = $end->toW3cString(); |
|
188 | + |
|
189 | + $data = [ |
|
190 | + 'interactive' => $this->interactive, |
|
191 | + 'ended' => $this->ended, |
|
192 | + 'start' => [ |
|
193 | + 'from' => strtotime($start_str).'000', |
|
194 | + 'to' => strtotime($end_str).'000', |
|
195 | + ], |
|
196 | + ]; |
|
197 | + if (count($this->skills)) { |
|
198 | + $data['skillIds'] = $this->skills; |
|
199 | + } |
|
200 | + |
|
201 | + $data = new Payload($data); |
|
202 | + |
|
203 | + return $this->request($url, 'POST', $data); |
|
204 | + } |
|
205 | + |
|
206 | + public function messagingHistory(Carbon $start = null, Carbon $end = null) |
|
207 | + { |
|
208 | + $this->retry_counter = 0; |
|
209 | + |
|
210 | + $start = $start ?: (new Carbon())->today(); |
|
211 | + $end = $end ?: (new Carbon())->today()->addHours(23)->addMinutes(59); |
|
212 | + |
|
213 | + $this->start = $start; |
|
214 | + $this->end = $end; |
|
215 | + |
|
216 | + $results_object = $this->retrieveMsgHistory($start, $end); |
|
217 | + $results = $results_object->conversationHistoryRecords; |
|
218 | + if (property_exists($results_object->_metadata, 'next')) { |
|
219 | + $this->next = $results_object->_metadata->next->href; |
|
220 | + } |
|
221 | + if (property_exists($results_object->_metadata, 'prev')) { |
|
222 | + $this->prev = $results_object->_metadata->prev->href; |
|
223 | + } |
|
224 | + |
|
225 | + $history = []; |
|
226 | + foreach ($results as $item) { |
|
227 | + if (property_exists($item, 'info')) { |
|
228 | + $item->info = new Info((array) $item->info); |
|
229 | + } |
|
230 | + |
|
231 | + if (property_exists($item, 'visitorInfo')) { |
|
232 | + $item->visitorInfo = new Visitor((array) $item->visitorInfo); |
|
233 | + } |
|
234 | + |
|
235 | + if (property_exists($item, 'campaign')) { |
|
236 | + $item->campaign = new Campaign((array) $item->campaign); |
|
237 | + } |
|
238 | + |
|
239 | + $history[] = new Conversation((array) $item); |
|
240 | + } |
|
241 | + |
|
242 | + return new ConversationHistory($history, $this); |
|
243 | + } |
|
244 | + |
|
245 | + public function history(Carbon $start = null, Carbon $end = null) |
|
246 | + { |
|
247 | + $this->retry_counter = 0; |
|
248 | + |
|
249 | + $start = $start ?: (new Carbon())->today(); |
|
250 | + $end = $end ?: (new Carbon())->today()->addHours(23)->addMinutes(59); |
|
251 | + |
|
252 | + $this->start = $start; |
|
253 | + $this->end = $end; |
|
254 | + |
|
255 | + $results_object = $this->retrieveHistory($start, $end); |
|
256 | + $results = $results_object->interactionHistoryRecords; |
|
257 | + if (property_exists($results_object->_metadata, 'next')) { |
|
258 | + $this->next = $results_object->_metadata->next->href; |
|
259 | + } |
|
260 | + if (property_exists($results_object->_metadata, 'prev')) { |
|
261 | + $this->prev = $results_object->_metadata->prev->href; |
|
262 | + } |
|
263 | + |
|
264 | + $history = []; |
|
265 | + foreach ($results as $item) { |
|
266 | + if (property_exists($item, 'info')) { |
|
267 | + $item->info = new Info((array) $item->info); |
|
268 | + } |
|
269 | + |
|
270 | + if (property_exists($item, 'visitorInfo')) { |
|
271 | + $item->visitorInfo = new Visitor((array) $item->visitorInfo); |
|
272 | + } |
|
273 | + |
|
274 | + if (property_exists($item, 'campaign')) { |
|
275 | + $item->campaign = new Campaign((array) $item->campaign); |
|
276 | + } |
|
277 | + |
|
278 | + $history[] = new Engagement((array) $item); |
|
279 | + } |
|
280 | 280 | |
281 | - $collection = new EngagementHistory($history, $this); |
|
282 | - $collection->metaData = $results_object->_metadata; |
|
281 | + $collection = new EngagementHistory($history, $this); |
|
282 | + $collection->metaData = $results_object->_metadata; |
|
283 | 283 | |
284 | - return $collection; |
|
285 | - } |
|
286 | - |
|
287 | - private function request($url, $method, $payload = false) |
|
288 | - { |
|
289 | - $consumer_key = config("{$this->config}.key"); |
|
290 | - $consumer_secret = config("{$this->config}.secret"); |
|
291 | - $token = config("{$this->config}.token"); |
|
292 | - $secret = config("{$this->config}.token_secret"); |
|
293 | - |
|
294 | - $stack = HandlerStack::create(); |
|
295 | - $auth = new Oauth1([ |
|
296 | - 'consumer_key' => $consumer_key, |
|
297 | - 'consumer_secret' => $consumer_secret, |
|
298 | - 'token' => $token, |
|
299 | - 'token_secret' => $secret, |
|
300 | - 'signature_method'=> Oauth1::SIGNATURE_METHOD_HMAC, |
|
301 | - ]); |
|
302 | - $stack->push($auth); |
|
303 | - |
|
304 | - $client = new Client([ |
|
305 | - 'handler' => $stack, |
|
306 | - ]); |
|
307 | - |
|
308 | - $args = [ |
|
309 | - 'auth' => 'oauth', |
|
310 | - 'headers' => [ |
|
311 | - 'content-type' => 'application/json', |
|
312 | - ], |
|
313 | - ]; |
|
314 | - |
|
315 | - if ($payload !== false) { |
|
316 | - $args['body'] = json_encode($payload); |
|
317 | - } |
|
318 | - |
|
319 | - try { |
|
320 | - $res = $client->request($method, $url, $args); |
|
321 | - |
|
322 | - $response = json_decode($res->getBody()); |
|
323 | - } catch (\GuzzleHttp\Exception\ConnectException $connection) { |
|
324 | - return $connection; |
|
325 | - } catch (\Exception $e) { |
|
326 | - if ($this->retry_counter < $this->retry_limit || $this->retry_limit == -1) { |
|
327 | - usleep(1500); |
|
328 | - $this->retry_counter++; |
|
329 | - $response = $this->request($url, $payload); |
|
330 | - } else { |
|
331 | - throw $e; //new LiveEngageException("Retry limit has been exceeded ($this->retry_limit)", 100); |
|
332 | - } |
|
333 | - } |
|
334 | - |
|
335 | - return $response; |
|
336 | - } |
|
284 | + return $collection; |
|
285 | + } |
|
286 | + |
|
287 | + private function request($url, $method, $payload = false) |
|
288 | + { |
|
289 | + $consumer_key = config("{$this->config}.key"); |
|
290 | + $consumer_secret = config("{$this->config}.secret"); |
|
291 | + $token = config("{$this->config}.token"); |
|
292 | + $secret = config("{$this->config}.token_secret"); |
|
293 | + |
|
294 | + $stack = HandlerStack::create(); |
|
295 | + $auth = new Oauth1([ |
|
296 | + 'consumer_key' => $consumer_key, |
|
297 | + 'consumer_secret' => $consumer_secret, |
|
298 | + 'token' => $token, |
|
299 | + 'token_secret' => $secret, |
|
300 | + 'signature_method'=> Oauth1::SIGNATURE_METHOD_HMAC, |
|
301 | + ]); |
|
302 | + $stack->push($auth); |
|
303 | + |
|
304 | + $client = new Client([ |
|
305 | + 'handler' => $stack, |
|
306 | + ]); |
|
307 | + |
|
308 | + $args = [ |
|
309 | + 'auth' => 'oauth', |
|
310 | + 'headers' => [ |
|
311 | + 'content-type' => 'application/json', |
|
312 | + ], |
|
313 | + ]; |
|
314 | + |
|
315 | + if ($payload !== false) { |
|
316 | + $args['body'] = json_encode($payload); |
|
317 | + } |
|
318 | + |
|
319 | + try { |
|
320 | + $res = $client->request($method, $url, $args); |
|
321 | + |
|
322 | + $response = json_decode($res->getBody()); |
|
323 | + } catch (\GuzzleHttp\Exception\ConnectException $connection) { |
|
324 | + return $connection; |
|
325 | + } catch (\Exception $e) { |
|
326 | + if ($this->retry_counter < $this->retry_limit || $this->retry_limit == -1) { |
|
327 | + usleep(1500); |
|
328 | + $this->retry_counter++; |
|
329 | + $response = $this->request($url, $payload); |
|
330 | + } else { |
|
331 | + throw $e; //new LiveEngageException("Retry limit has been exceeded ($this->retry_limit)", 100); |
|
332 | + } |
|
333 | + } |
|
334 | + |
|
335 | + return $response; |
|
336 | + } |
|
337 | 337 | } |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | |
122 | 122 | public function visitor($visitorID, $sessionID, $setData = false) |
123 | 123 | { |
124 | - if (! $this->domain) { |
|
124 | + if (!$this->domain) { |
|
125 | 125 | $this->domain('smt'); |
126 | 126 | } |
127 | 127 | |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | |
139 | 139 | public function agentStatus() |
140 | 140 | { |
141 | - if (! $this->domain) { |
|
141 | + if (!$this->domain) { |
|
142 | 142 | $this->domain('msgHist'); |
143 | 143 | } |
144 | 144 | |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | |
150 | 150 | final public function retrieveHistory(Carbon $start, Carbon $end, $url = false) |
151 | 151 | { |
152 | - if (! $this->domain) { |
|
152 | + if (!$this->domain) { |
|
153 | 153 | $this->domain('engHistDomain'); |
154 | 154 | } |
155 | 155 | |
@@ -162,8 +162,8 @@ discard block |
||
162 | 162 | 'interactive' => $this->interactive, |
163 | 163 | 'ended' => $this->ended, |
164 | 164 | 'start' => [ |
165 | - 'from' => strtotime($start_str).'000', |
|
166 | - 'to' => strtotime($end_str).'000', |
|
165 | + 'from' => strtotime($start_str) . '000', |
|
166 | + 'to' => strtotime($end_str) . '000', |
|
167 | 167 | ], |
168 | 168 | ]; |
169 | 169 | if (count($this->skills)) { |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | |
178 | 178 | final public function retrieveMsgHistory(Carbon $start, Carbon $end, $url = false) |
179 | 179 | { |
180 | - if (! $this->domain) { |
|
180 | + if (!$this->domain) { |
|
181 | 181 | $this->domain('msgHist'); |
182 | 182 | } |
183 | 183 | |
@@ -190,8 +190,8 @@ discard block |
||
190 | 190 | 'interactive' => $this->interactive, |
191 | 191 | 'ended' => $this->ended, |
192 | 192 | 'start' => [ |
193 | - 'from' => strtotime($start_str).'000', |
|
194 | - 'to' => strtotime($end_str).'000', |
|
193 | + 'from' => strtotime($start_str) . '000', |
|
194 | + 'to' => strtotime($end_str) . '000', |
|
195 | 195 | ], |
196 | 196 | ]; |
197 | 197 | if (count($this->skills)) { |