PHP code example of blockshiftnetwork / composio-laravel

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

    

blockshiftnetwork / composio-laravel example snippets


use BlockshiftNetwork\ComposioLaravel\Facades\Composio;

$session = Composio::create('user_123', [
    'toolkits' => ['github', 'slack'],
    'tools' => [
        'github' => ['GITHUB_CREATE_ISSUE', 'GITHUB_LIST_REPOS'],
        'slack' => ['SLACK_SEND_MESSAGE'],
    ],
    'manageConnections' => [
        'enable' => true,
        'callbackUrl' => route('composio.callback'),
        'inferScopesFromTools' => true,
    ],
]);

$session->sessionId;
$session->mcp;

$session = Composio::use('session_123');

$tools = $session->tools();

$result = $session->execute('GITHUB_CREATE_ISSUE', [
    'owner' => 'acme',
    'repo' => 'api',
    'title' => 'Bug from agent',
]);

$session = Composio::use('session_123');

$tools = $session->laravelAiTools();

$link = $session->authorize('github', route('composio.callback'));

$link->getRedirectUrl();
$link->getConnectedAccountId();

$tools = Composio::tools('user_123')
    ->withConnectedAccount('ca_123')
    ->get('github', ['GITHUB_CREATE_ISSUE'], ['issues']);

$result = Composio::tools('user_123')
    ->withConnectedAccount('ca_123')
    ->execute('GITHUB_CREATE_ISSUE', [
        'owner' => 'acme',
        'repo' => 'api',
        'title' => 'Bug from Laravel',
    ]);

$tools = Composio::tools('user_123')
    ->withConnectedAccount('ca_123')
    ->getLaravelAiTools('github');

$session = Composio::create('user_123', [
    'sessionPreset' => 'direct_tools',
    'toolkits' => ['github'],
]);

Composio::customTools()->register(
    slug: 'LOCAL_PING',
    description: 'Return pong',
    inputSchema: [],
    handler: fn (array $args) => json_encode(['pong' => true]),
);

$tools = Composio::tools()->get();

$tools = Composio::tools('user_123');

$tools->hooks()->beforeExecute('*', function (string $tool, array $arguments): array {
    $arguments['source'] = 'laravel';

    return $arguments;
});

Composio::connectedAccounts();
Composio::authConfigs();
Composio::toolkits();
Composio::triggers();
Composio::mcp();
Composio::files();