Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- date_default_timezone_set('UTC');
- ini_set('max_execution_time', 0);
- set_time_limit(0);
- $data = file_get_contents('php://input');
- $data = json_decode($data);
- // make sure the "chat_started" event occured
- if ($data->event_type === 'chat_started') {
- // read additional information about your visitor
- // from your internal database
- $email = $data->visitor->email;
- //$visitorDetails = $MyDatabase->query($email);
- // send this information to LiveChat apps
- $fields = array();
- $fields[] = (object) array(
- 'name' => 'Age',
- 'value' => 100
- );
- $fields[] = (object) array(
- 'name' => 'Email',
- 'value' => $email
- );
- $curlFields = http_build_query(array(
- 'license_id' => $data->license_id,
- 'token' => $data->token,
- 'id' => 'my-integration',
- // Do not enter "http" prefix in the icon URL.
- // Your server must be able to serve the icon
- // using both https:// and http:// protocols.
- 'icon' => 'cdn0.iconfinder.com/data/icons/customicondesignoffice5/128/examples.png',
- 'fields' => $fields
- ));
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, 'https://api.livechatinc.com/visitors/' . $data->visitor->id . '/details');
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $curlFields);
- curl_setopt($ch, CURLOPT_HTTPHEADER, array(
- 'X-API-Version: 2'
- ));
- $result = curl_exec($ch);
- curl_close($ch);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement