macsidigital / laravel-liveagent

LiveAgent Laravel package

Stars
0

Laravel LiveAgent integration for API V3

Latest Version on Packagist
Build Status
StyleCI
Total Downloads

A little Laravel package to communicate with LiveAgent.

Installation

You can install the package via composer:

composer require macsidigital/laravel-liveagent

The service provider should automatically register for For Laravel > 5.4.

For Laravel < 5.5, open config/app.php and, within the providers array, append:

MacsiDigital\LiveAgent\Providers\LiveAgentServiceProvider::class

Configuration file

Publish the configuration file

php artisan vendor:publish --provider="MacsiDigital\LiveAgent\Providers\LiveAgentServiceProvider"

This will create a liveagent/config.php within your config directory. Check the LiveAgent documentation for the relevant values in the config.php file.
Ensure that the location of the RSA keys matches.

Usage

Everything has been setup to be similar to Laravel syntax.

Within the models we have $attributes, $queryAttributes, $createAttributes, $updateAttributes & a $methods array which control what attributes can be set on the model. SO if query isnt working then first check these arrays.

Also the LiveAgent API is very inconsistant, for example it assigns a different system_name depending on how the you create a contact. If you create a contact the system_name is the email, if you create a ticket it creates a user that has a system_name of the user name. And if it requires a useridentifier, this is generally not the id but the email address.

Best to check the documentation at

LiveAgent Docs

There is a playground there to test the API, sometimes its just a case of playing until you find what is required as the docuemnts dont tell you!!

We also use a little bit of magic to work with LiveAgent's model names.

If the response is anything other than a '200' then we will throw an exception, so use try catch blocks.

So to use the conversation model we would use the following syntax.

	$liveagent = new \MacsiDigital\LiveAgent\LiveAgent;
	$liveagent->contact->functionName();

Find all

The find all function returns a Laravel Collection so you can use all the Laravel Collection magic

	$liveagent = new \MacsiDigital\LiveAgent\LiveAgent;
	$contacts = $liveagent->contact->all();

Filtered

The filtered find function returns a Laravel Collection so you can use all the Laravel Collection magic

	$liveagent = new \MacsiDigital\LiveAgent\LiveAgent;
	$contacts = $liveagent->contact->where('system_name', 'Test Name')->get();

To only get a single item use the 'first' method

	$liveagent = new \MacsiDigital\LiveAgent\LiveAgent;
	$contact = $liveagent->contact->where('system_name', 'Test Name')->first();

Find by ID

Just like Laravel we can use the 'find' method to return a single matched result on the ID

	$liveagent = new \MacsiDigital\LiveAgent\LiveAgent;
	$contact = $liveagent->contact->find('ID_String');

Creating Items

We can create and update records using the save function.

	$contact = $liveagent->contact->make([
        'firstname' => 'First Name',
        'lastname' => 'Last Name',
        'registration_email' => '[email protected]',
    ])->save();

or we can use the create shortcut

	$contact = $liveagent->contact->create([
        'firstname' => 'First Name',
        'lastname' => 'Last Name',
        'registration_email' => '[email protected]',
    ]);

Resources

At present we have the following resources

  • Agent
  • Contact
  • Department
  • Message
  • MessageGroup // Returned when you query a tickets messages
  • Ticket
  • TicketListGroup // Used to create a ticket

We plan to add more resources in the future but setting up additional models is straight forward, below is the department model setup. If you create any models, then create a pull request and we will add into main repo.

	namespace MacsiDigital\LiveAgent;

	use MacsiDigital\LiveAgent\Support\Model;

	class Department extends Model
	{
	    const ENDPOINT = 'departments';
	    const NODE_NAME = 'Departments';
	    const KEY_FIELD = 'department_id';

	    protected $methods = ['get'];

	    protected $queryAttributes = [
	        
	    ];

	    protected $attributes = [
	        'department_id' => '',
	        'agent_count' => '',
	        'name' => '',
	        'online_status' => '',
	        'agent_ids' => '',
	        'mailaccount_id' => ''
	    ];

	}

Testing

At present there is no PHP Unit Testing, but we plan to add it in the future.

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.