live-person-inc / live-engage-laravel
适用于Laravel的LiveEngage包
1.0.1
2018-10-29 16:39 UTC
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-09-08 02:05:35 UTC
README
Laravel包,可以轻松调用LiveEngage开发者API,例如参与历史、参与属性等...
自行承担风险。此包没有SLA或支持,仍在开发中。
安装
通过Composer安装
composer require live-person-inc/live-engage-laravel
注册服务提供者
注意!如果你使用laravel>=5.5并启用了包自动发现功能,以下步骤是可选的。
将服务提供者添加到config/app.php
中的providers
部分
LivePersonInc\LiveEngageLaravel\ServiceProvider::class,
注册外观
在config/app.php
中的aliases
部分注册包外观
'LiveEngage' => LivePersonInc\LiveEngageLaravel\Facades\LiveEngageLaravel::class,
用法
从LiveEngage获取适当的API权限的API密钥。需要default
密钥。
在config/services.php
中配置你的密钥/账户
'liveperson' => [ 'default' => [ 'key' => 'xxxxxxx', 'secret' => 'xxxxxxx', 'token' => 'xxxxxxx', 'token_secret' => 'xxxxxxx', 'account' => '123456', ] ],
如果你想要多个API密钥,可以为它们添加更多数组。每个数组的键是任意的,但你需要稍后指定它们以访问特定的密钥集。
'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', ] ],
要在特定的密钥集上执行API调用...
$history = LiveEngage::key('history')->engagementHistory(); //conversationHistory() for messaging
要使用默认密钥集,你根本不需要使用key
方法。
$history = LiveEngage::engagementHistory(); //conversationHistory() for messaging
示例:使用上面配置的全局账户捕获两个日期/时间之间的参与历史。
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);
示例:获取特定技能ID之间的参与历史。
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()
和conversationHistory()
返回Laravel参与对象集合。
示例:将下一页数据拉入集合中。
$history->next(); // one page
或
while ($next = $history->next()) { $history = history->merge($next) } // get all remaining data
示例:遍历转录本中的所有消息
$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 }
转录本是消息对象集合,因此你可以访问消息的属性。
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"; }
示例:按技能获取消息代理的可用性
$availableAgents = LiveEngage::getAgentStatus(17); //Skill ID 17 $online = $availableAgents->state('online'); $away = $availableAgents->state('away');
安全
如果你发现任何安全相关的问题,请通过rlester@liveperson.com而不是使用问题跟踪器。
致谢
此包是在melihovv/laravel-package-generator的帮助下启动的。