PHP code example of x3group-dev / calltouch

1. Go to this page and download the library: Download x3group-dev/calltouch library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

x3group-dev / calltouch example snippets

injectablephp
use Throwable;

use X3Group\CallTouch\Result\ResultInterface;
use X3Group\CallTouch\Helpers\ExceptionHelper;
use X3Group\CallTouch\Reporters\ReportedInterface;

use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\RequestInterface;

class EmailReporter implements ReportedInterface
{    
    private ?ResponseInterface $response = null;
    private ?RequestInterface $request = null;
    private ?ResultInterface $result = null;
    
    public function report(): void
    {
        if (null === $this->response) {
            return;
        }
    
        $responseBody = $this->response->getBody();
        $responseBody->rewind();
        
        $message = $responseBody->getContents() ?: 'Unknown error';
    
        mail('[email protected]', 'Subject', $message);
    }
    
    public function setResponse(ResponseInterface $response): self
    {
        $this->response = $response;
        return $this;
    }
    
    public function setRequest(RequestInterface $request): self
    {
        $this->request = $request;
        return $this;
    }
    
    public function setResultValidate(ResultInterface $result): self
    {
        $this->result = $result;
        return $this; 
    }
}

injectablephp
use X3Group\CallTouch\Builder\CallbackBuilder;

$routeKey = "myKey";
$token = 'your access token...';

$formData = [
    'USER_PHONE' => '79099999999',
    'NAME' => "Игорь",
    'EMAIL' => "[email protected]",
    'NOW_PAGE' => 'http://test.ru',
];

$builder = new CallbackBuilder($token);
$builder->getFieldMap()
    ->setPhone(['USER_PHONE', 'PERSONAL_PHONE'])
    ->setCallUrl(['NOW_PAGE'])
    ->setFields([
        'NAME',
        'EMAIL',
        'NOW_PAGE'
    ]);

$builder->setRouteKey($routeKey)
    ->addReporter(new EmailReporter)
    ->make()
    ->send($formData);