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