Laravel package to easily tap the LiveEngage developer APIs for such content as Engagement History, Engagement Attributes, and more...
Use at your own risk. This package carries no SLA or support and is still currently under development.
Install via composer
composer require live-person-inc/live-engage-laravel
Note! This and next step are optional if you use laravel>=5.5 with package auto discovery feature.
Add service provider to config/app.php
in providers
section
LivePersonInc\LiveEngageLaravel\ServiceProvider::class,
Register package facade in config/app.php
in aliases
section
'LiveEngage' => LivePersonInc\LiveEngageLaravel\Facades\LiveEngageLaravel::class,
Create/Obtain an API key from LiveEngage with appropriate permissions for the APIs you intend to access. The default
key is required.
Configure your keys/account in config/services.php
'liveperson' => [
'default' => [
'key' => 'xxxxxxx',
'secret' => 'xxxxxxx',
'token' => 'xxxxxxx',
'token_secret' => 'xxxxxxx',
'account' => '123456',
]
],
If you want to have multiple API keys, you can add more arrays for them. The keys for each array are arbitrary, but you will need to specify them later to access specific key sets.
'liveperson' => [
'default' => [
'key' => 'xxxxxxx',
'secret' => 'xxxxxxx',
'token' => 'xxxxxxx',
'token_secret' => 'xxxxxxx',
'account' => '123456',
],
'history' => [
'key' => 'xxxxxxx',
'secret' => 'xxxxxxx',
'token' => 'xxxxxxx',
'token_secret' => 'xxxxxxx',
'account' => '123456',
],
'attributes' => [
'key' => 'xxxxxxx',
'secret' => 'xxxxxxx',
'token' => 'xxxxxxx',
'token_secret' => 'xxxxxxx',
'account' => '123456',
]
],
To make an api call on a specific key set...
$history = LiveEngage::key('history')->engagementHistory(); //conversationHistory() for messaging
To use the default keyset, you need not use the key
method at all.
$history = LiveEngage::engagementHistory(); //conversationHistory() for messaging
Example: Capturing engagement history between 2 date/times using global account configured above.
use LiveEngage;
use Carbon\Carbon;
$start = new Carbon('2018-06-01 08:00:00');
$end = new Carbon('2018-06-03 17:00:00');
/**
* engagementHistory function.
*
* @access public
* @param Carbon $start (default: null)
* @param Carbon $end (default: null)
* @param mixed $skills (default: [])
*/
$history = LiveEngage::engagementHistory($start, $end);
Example: Getting engagement history between 2 date/times for specific skill IDs.
use LiveEngage;
use Carbon\Carbon;
$start = new Carbon('2018-06-01 08:00:00');
$end = new Carbon('2018-06-03 17:00:00');
$skills = [432,676];
$history = LiveEngage::engagementHistory($start, $end, $skills);
engagementHistory()
and conversationHistory()
returns a Laravel collection of Engagement objects.
Example: Pulling the next "page" of data in to the collection.
$history->next(); // one page
Or
while ($next = $history->next()) { $history = history->merge($next) } // get all remaining data
Example: Iterate through all messages of the transcript
$engagement = $history->find('3498290084'); // This is a collection, so random(), first(), last() all work as well
foreach ($engagement->transcript as $message) { // For messaging conversations, use messageRecords instead of transcript
echo $message . "\n"; // calling the message object as a string returns its text value
}
Transcript is a collection of message objects, so you can access properties of the message as well.
echo $message->time->format('Y-m-d'); //The all time properties are Carbon date objects.
$conversation = LiveEngage::conversationHistory()->first();
foreach ($conversation->transfers as $transfer) {
echo $transfer->targetSkillName . "\n";
}
Example: Get messaging agents availability by skill
$availableAgents = LiveEngage::getAgentStatus(17); //Skill ID 17
$online = $availableAgents->state('online');
$away = $availableAgents->state('away');
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
This package is bootstrapped with the help of melihovv/laravel-package-generator.