Advertisement
livechatinc

Example Webhook call

Nov 24th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.54 KB | None | 0 0
  1. <?php
  2.  
  3. date_default_timezone_set('UTC');
  4. ini_set('max_execution_time', 0);
  5. set_time_limit(0);
  6.  
  7.  
  8. $data = file_get_contents('php://input');
  9. $data = json_decode($data);
  10.  
  11. // make sure the "chat_started" event occured
  12. if ($data->event_type === 'chat_started') {
  13.     // read additional information about your visitor
  14.     // from your internal database
  15.     $email = $data->visitor->email;
  16.     //$visitorDetails = $MyDatabase->query($email);
  17.    
  18.     // send this information to LiveChat apps
  19.     $fields   = array();
  20.     $fields[] = (object) array(
  21.         'name' => 'Age',
  22.         'value' => 100
  23.     );
  24.     $fields[] = (object) array(
  25.         'name' => 'Email',
  26.         'value' => $email
  27.     );
  28.    
  29.     $curlFields = http_build_query(array(
  30.         'license_id' => $data->license_id,
  31.         'token' => $data->token,
  32.         'id' => 'my-integration',
  33.        
  34.         // Do not enter "http" prefix in the icon URL.
  35.         // Your server must be able to serve the icon
  36.         // using both https:// and http:// protocols.
  37.         'icon' => 'cdn0.iconfinder.com/data/icons/customicondesignoffice5/128/examples.png',
  38.        
  39.         'fields' => $fields
  40.     ));
  41.    
  42.     $ch = curl_init();
  43.     curl_setopt($ch, CURLOPT_URL, 'https://api.livechatinc.com/visitors/' . $data->visitor->id . '/details');
  44.     curl_setopt($ch, CURLOPT_POST, 1);
  45.     curl_setopt($ch, CURLOPT_POSTFIELDS, $curlFields);
  46.     curl_setopt($ch, CURLOPT_HTTPHEADER, array(
  47.         'X-API-Version: 2'
  48.     ));
  49.     $result = curl_exec($ch);
  50.     curl_close($ch);
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement