PHP code example of voyanara / avito-laravel-client

1. Go to this page and download the library: Download voyanara/avito-laravel-client 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/ */

    

voyanara / avito-laravel-client example snippets


public function action(AvitoClient $client)
{
    $client::messenger()->getChats();
    //or
    AvitoClient::user()->self();
}

use Voyanara\LaravelApiClient\Application\Facades\AvitoClientFacade as AvitoClient;

use Voyanara\LaravelApiClient\Application\Facades\Client;

public function action(Client $client)
{
    $client->messenger()->getChats();
    //or
    $client->user()->getBalance();
    $client->user()->getOperationsHistory();
}

use Voyanara\LaravelApiClient\Application\Facades\Client;

public function action(Client $client)
{
    $userId = $client->user()->self()->id;

    $chats = $client->messenger()->getChats($userId, unreadOnly: true);
    $chat = $chats->chats->first();

    $client->messenger()->sendMessage($userId, $chat->id, 'Hello! Thanks for reaching out.');
    $client->messenger()->readChat($userId, $chat->id);
}

$upload = $client->messenger()->uploadImage($userId, storage_path('app/photo.jpg'));
$client->messenger()->sendMessageWithImage($userId, $chatId, $upload->id);

$client->messenger()->subscribeWebhook('https://example.com/avito/webhook');

$subscriptions = $client->messenger()->getSubscriptions();
foreach ($subscriptions->subscriptions as $subscription) {
    echo $subscription->url.' (v'.$subscription->version.')'.PHP_EOL;
}

$client->messenger()->unsubscribeWebhook('https://example.com/avito/webhook');
bash
php artisan vendor:publish --provider="Voyanara\LaravelApiClient\Infrastructure\Providers\AvitoModuleServiceProvider --tag="config"
bash
php artisan vendor:publish --provider="Voyanara\LaravelApiClient\Infrastructure\Providers\AvitoModuleServiceProvider --tag="migrations"