PHP code example of yannelli / pocket-laravel

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

    

yannelli / pocket-laravel example snippets


return [
    'api_key' => env('POCKET_API_KEY'),
    'base_url' => env('POCKET_BASE_URL', 'https://public.heypocketai.com'),
    'api_version' => env('POCKET_API_VERSION', 'v1'),
    'timeout' => env('POCKET_TIMEOUT', 30),
    'retry' => [
        'times' => env('POCKET_RETRY_TIMES', 3),
        'sleep' => env('POCKET_RETRY_SLEEP', 1000),
    ],
];

use Yannelli\Pocket\Facades\Pocket;

// List recordings
$recordings = Pocket::recordings()->list();

// Get a specific recording
$recording = Pocket::recordings()->get('rec_123');

// Search transcripts, summaries, and action items
$results = Pocket::search()->query('ship v2 by Friday');

// List folders
$folders = Pocket::folders()->list();

// List tags
$tags = Pocket::tags()->list();

use Yannelli\Pocket\Pocket;

class RecordingController extends Controller
{
    public function __construct(
        private Pocket $pocket
    ) {}

    public function index()
    {
        return $this->pocket->recordings()->list();
    }
}

use Yannelli\Pocket\Facades\Pocket;

// Create a tenant-specific instance
$tenantPocket = Pocket::withApiKey($tenant->pocket_api_key);

// Use the tenant-specific instance
$recordings = $tenantPocket->recordings()->list();

use Yannelli\Pocket\Pocket;

class TenantRecordingService
{
    public function __construct(
        private Pocket $pocket
    ) {}

    public function getRecordingsForTenant(Tenant $tenant)
    {
        return $this->pocket
            ->withApiKey($tenant->pocket_api_key)
            ->recordings()
            ->list();
    }
}

use Yannelli\Pocket\Facades\Pocket;

$recordings = Pocket::recordings()->list();

foreach ($recordings as $recording) {
    echo $recording->title;
    echo $recording->formattedDuration(); // "1:30:45"
}

if ($recordings->hasMore()) {
    $nextPage = Pocket::recordings()->list(page: $recordings->nextPage());
}

$recording = Pocket::recordings()->get('rec_123');

$recordings = Pocket::recordings()->inFolder('folder_123');

$recordings = Pocket::recordings()->withTags(['tag_1', 'tag_2']);

$recordings = Pocket::recordings()->betweenDates('2025-01-01', '2025-01-31');

$recordings = Pocket::recordings()->list(
    folderId: 'folder_123',
    startDate: '2025-01-01',
    endDate: '2025-01-31',
    tagIds: ['tag_1', 'tag_2'],
    page: 1,
    limit: 50
);

foreach (Pocket::recordings()->all() as $recording) {
    echo $recording->title;
}

foreach (Pocket::recordings()->all(folderId: 'folder_123') as $recording) {
    // Process recording...
}

$recording = Pocket::recordings()->get(
    id: 'rec_123',
    mmarizationId: 'sum_123'
);

echo $recording->recordedBy?->displayName;
echo $recording->recordingAt?->format('Y-m-d');
echo $recording->translation?->toLanguage;

$upload = Pocket::recordings()->createUploadUrl(
    contentType: 'audio/mpeg',
    fileName: 'standup.mp3',
    duration: 1800,
    title: 'Team Standup'
);

// Or create the URL and upload a local file in one call:
$upload = Pocket::recordings()->upload(
    path: storage_path('app/standup.mp3'),
    title: 'Team Standup'
);

$recording = Pocket::recordings()->get($upload->recordingId);

$recording = Pocket::recordings()->get('rec_123');

if ($recording->hasTranscript()) {
    // Access the full transcript text
    echo $recording->transcript->text;

    // Get a list of speakers
    $speakers = $recording->transcript->speakers();

    // Retrieve segments for a specific speaker
    $segments = $recording->transcript->segmentsForSpeaker('Speaker 1');
}

if ($recording->hasSummary()) {
    echo $recording->summary->title;

    foreach ($recording->summary->sections as $section) {
        echo $section->heading;
        echo $section->content;
    }
}

if ($recording->hasActionItems()) {
    // Filter by status
    $pendingItems = $recording->pendingActionItems();
    $completedItems = $recording->completedActionItems();

    foreach ($recording->actionItems as $item) {
        echo $item->title;
        echo $item->priority->label(); // "High", "Medium", "Low"

        if ($item->isOverdue()) {
            // Handle overdue item...
        }
    }
}

$recording = Pocket::recordings()->get('rec_123');

if ($recording->isProcessing()) {
    echo "Recording is being processed...";
}

if ($recording->isCompleted()) {
    echo "Recording is ready!";
}

if ($recording->isFailed()) {
    echo "Processing failed: " . $recording->state->description();
}

use Yannelli\Pocket\Facades\Pocket;

$results = Pocket::search()->query(
    query: 'ship v2 by Friday',
    limit: 8,
    dateFrom: '2026-01-01T00:00:00Z',
    dateTo: '2026-01-31T23:59:59Z',
    folderIds: ['folder_123'],
    recordingIds: ['rec_123']
);

foreach ($results as $hit) {
    echo $hit->title;
    echo $hit->snippet;
}

use Yannelli\Pocket\Facades\Pocket;

// List all folders
$folders = Pocket::folders()->list();

foreach ($folders as $folder) {
    echo $folder->name;
    echo $folder->recordingCount;
}

// Find a folder by ID, including nested children
$folder = Pocket::folders()->find('folder_123');

// Find a folder by name
$folder = Pocket::folders()->findByName('Work Meetings');

// Get the default folder when the API marks one with is_default
$defaultFolder = Pocket::folders()->default();

use Yannelli\Pocket\Facades\Pocket;

// List all tags (ordered by usage)
$tags = Pocket::tags()->list();

// Get most used tags
$topTags = Pocket::tags()->mostUsed(5);

// Find a tag by ID
$tag = Pocket::tags()->find('tag_123');

// Find a tag by name
$tag = Pocket::tags()->findByName('Important');

use Yannelli\Pocket\Facades\Pocket;

$audioUrl = Pocket::audio()->getUrl('rec_123');

echo $audioUrl->signedUrl;
echo $audioUrl->expiresIn; // Seconds until expiry

if ($audioUrl->isExpired()) {
    $audioUrl = Pocket::audio()->getUrl('rec_123');
}

// Get the audio file contents as a string
$contents = Pocket::audio()->getContents('rec_123');

// Stream the audio file (memory efficient for large files)
$stream = Pocket::audio()->stream('rec_123');

// Download to a temporary file (auto-cleaned up on script end)
$tempPath = Pocket::audio()->download('rec_123');

// Save to a Laravel storage disk
Pocket::audio()->saveTo('recordings/audio.mp3', 's3', [], 'rec_123');

// Save using streaming (memory efficient)
Pocket::audio()->saveStreamTo('recordings/audio.mp3', 'local', [], 'rec_123');

// Save directly to a local path
Pocket::audio()->saveToPath('/path/to/audio.mp3', 'rec_123');

use Yannelli\Pocket\Resources\AudioResource;

AudioResource::cleanup();

$audio = Pocket::audio('rec_123');

// All methods now work without passing the recording ID
$url = $audio->getUrl();
$contents = $audio->getContents();
$tempPath = $audio->download();

use Yannelli\Pocket\Facades\Pocket;

$users = Pocket::users()->list(q: 'alice');

$bundle = Pocket::users()->settings('usr_001',  ],
]);

use Yannelli\Pocket\Facades\Pocket;
use Illuminate\Http\Request;

public function handle(Request $request)
{
    $event = Pocket::webhooks()->parseAndVerify(
        secret: config('services.pocket.webhook_secret'),
        payload: $request->getContent(),
        signature: $request->header('X-HeyPocket-Signature'),
        timestamp: $request->header('X-HeyPocket-Timestamp'),
    );

    // $event->event, $event->recordingId(), $event->user, ...
}

use Yannelli\Pocket\Facades\Pocket;
use Yannelli\Pocket\Exceptions\AuthenticationException;
use Yannelli\Pocket\Exceptions\ForbiddenException;
use Yannelli\Pocket\Exceptions\NotFoundException;
use Yannelli\Pocket\Exceptions\RateLimitException;
use Yannelli\Pocket\Exceptions\ValidationException;
use Yannelli\Pocket\Exceptions\ServerException;
use Yannelli\Pocket\Exceptions\PocketException;

try {
    $recording = Pocket::recordings()->get('rec_123');
} catch (AuthenticationException $e) {
    // Invalid API key (401)
} catch (ForbiddenException $e) {
    // Missing scope or organization key mismatch (403)
} catch (NotFoundException $e) {
    // Recording not found (404)
} catch (RateLimitException $e) {
    // Too many requests (429)
    $retryAfter = $e->getRetryAfter();
} catch (ValidationException $e) {
    // Invalid parameters (400)
    $details = $e->getDetails();
} catch (ServerException $e) {
    // Server error (5xx)
} catch (PocketException $e) {
    // Any other API error
}
bash
php artisan vendor:publish --tag="pocket-config"