live-person-inc / live-engage-laravel
LiveEngage package for laravel
Requires
- php: >=7.0
- guzzlehttp/oauth-subscriber: ^0.3.0
- laravel/framework: >=5.5
Requires (Dev)
- orchestra/testbench: ~3.6.0
- phpunit/phpunit: ~7.2
This package is auto-updated.
Last update: 2024-11-08 02:32:40 UTC
README
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.
Installation
Install via composer
composer require live-person-inc/live-engage-laravel
Register Service Provider
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 Facade
Register package facade in config/app.php
in aliases
section
'LiveEngage' => LivePersonInc\LiveEngageLaravel\Facades\LiveEngageLaravel::class,
Usage
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');
Security
If you discover any security related issues, please email rlester@liveperson.com instead of using the issue tracker.
Credits
This package is bootstrapped with the help of melihovv/laravel-package-generator.