metadrop / gocontact-php
PHP client for the GoContact CCaaS REST API: contacts, databases, extrafields and the report designer.
Requires
- php: >=8.2
- psr/http-client: ^1.0
- psr/http-factory: ^1.0
- psr/http-message: ^1.1 || ^2.0
- psr/log: ^2.0 || ^3.0
- psr/simple-cache: ^2.0 || ^3.0
Requires (Dev)
- nyholm/psr7: ^1.8
- phpmd/phpmd: ^2.15
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^11.5
- squizlabs/php_codesniffer: ^4.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
PHP client for the GoContact CCaaS REST API. It covers contacts, databases, extrafields templates and the report designer, and works with any PSR-18 HTTP client, PSR-16 cache and PSR-3 logger.
Documentation
- GoContact CCaaS API (Swagger): token, contacts, databases, extrafields and the report designer job endpoints.
- Report Designer (PHP):
the legacy
report_builder.phpendpoint that lists owners and report templates.
Installation
composer require metadrop/gocontact-php
The client needs a PSR-18 HTTP client, PSR-17 factories and a PSR-16 cache. The example below uses Symfony HttpClient, nyholm/psr7 and Symfony Cache:
composer require symfony/http-client nyholm/psr7 symfony/cache
Usage
use Metadrop\GoContact\Clock\SystemSleeper; use Metadrop\GoContact\Credentials; use Metadrop\GoContact\GoContact; use Metadrop\GoContact\Http\HttpFactories; use Metadrop\GoContact\Report\OwnerType; use Metadrop\GoContact\Report\ReportDownloader; use Metadrop\GoContact\Report\ReportRequest; use Nyholm\Psr7\Factory\Psr17Factory; use Psr\Log\NullLogger; use Symfony\Component\Cache\Adapter\FilesystemAdapter; use Symfony\Component\Cache\Psr16Cache; use Symfony\Component\HttpClient\Psr18Client; $psr17Factory = new Psr17Factory(); $psr18Client = new Psr18Client(NULL, $psr17Factory, $psr17Factory); $psr16Cache = new Psr16Cache(new FilesystemAdapter('gocontact')); $logger = new NullLogger(); $goContact = new GoContact( new Credentials('https://example.gocontact.es', 'example.gocontact.es', 'api_user', $password), new HttpFactories($psr18Client, $psr17Factory, $psr17Factory), $psr16Cache, $logger, ); // Contacts: the batch creation ignores extrafields, so they go afterwards. $contact = $goContact->client()->createContact($databaseId, ['contact' => 'Jane', 'first_phone' => '600000000']); $goContact->client()->updateExtrafields($databaseId, $contact->id, ['field1' => 'Jane']); // Reports: every campaign, one day, saved to a CSV file. $catalog = $goContact->reportCatalog()->catalog(OwnerType::Campaign); $request = ReportRequest::forDay(OwnerType::Campaign, $catalog->ownerIds(), 5, $templateId, new DateTimeImmutable('yesterday')); $bytes = (new ReportDownloader($goContact->reports(), new SystemSleeper(), $logger)) ->download($request, '/tmp/report.csv', maxWait: 900);
dataType selects which records enter the date range and depends on the owner
type. For campaigns and queues:
| dataType | Records |
|---|---|
| 0 | All calls |
| 1 | Calls with script |
| 2 | Answered calls |
| 3 | Not answered calls |
| 4 | Contact state by last call date |
| 5 | Contact state by last load date |
| 6 | Contact state by last update date |
The values of every other owner type are in the DataType Reference of
POST /api/reportdesigner/generateReport in the
Swagger documentation.
A report covers at most 3 months and 1 day.
API notes
- Tokens last 24h; they are cached and renewed once on a 401.
- The batch contact creation is all-or-nothing, needs at least one
*_phoneand ignores extrafields. - Extrafields are validated against the template of the campaign that owns the database, not the database's own template.
- Every request is logged before and after with its method and path. Query strings are never logged: the report builder takes the credentials there.
Quality
composer qa
License
LGPL-3.0-or-later. See LICENSE.