PHP code example of webgrafia / cheshire-cat-sdk-laravel

1. Go to this page and download the library: Download webgrafia/cheshire-cat-sdk-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/ */

    

webgrafia / cheshire-cat-sdk-laravel example snippets


return [
    'base_uri' => env('CHESHIRE_CAT_BASE_URI', 'http://localhost:1865/'),
    'ws_base_uri' => env('CHESHIRE_CAT_WS_BASE_URI', 'ws://localhost:1865/ws'),
    'api_key' => env('CHESHIRE_CAT_API_KEY'),
];

use CheshireCatSdk\Facades\CheshireCatFacade as CheshireCat;

$response = CheshireCat::status();

if ($response->getStatusCode() === 200) {
    echo "API is up and running!";
}

$response = CheshireCat::message('Hello, Cheshire Cat!');
$data = json_decode($response->getBody(), true);

echo $data['text'];

$response = CheshireCat::getAvailablePermissions();
$permissions = json_decode($response->getBody(), true);

print_r($permissions);

  $response = CheshireCat::createUser([
      'username' => 'testuser',
      'password' => 'securepassword',
  ]);
  $user = json_decode($response->getBody(), true);

  echo $user['id'];
  

  $response = CheshireCat::getUsers(0, 10);
  $users = json_decode($response->getBody(), true);

  print_r($users);
  

  $response = CheshireCat::updateUser('user_id', [
      'username' => 'updateduser',
  ]);
  echo $response->getStatusCode();
  

  $response = CheshireCat::deleteUser('user_id');
  echo $response->getStatusCode();
  

  $response = CheshireCat::getSettings();
  $settings = json_decode($response->getBody(), true);

  print_r($settings);
  

  $response = CheshireCat::createSetting([
      'name' => 'new_setting',
      'value' => 'some_value',
  ]);
  echo $response->getStatusCode();
  

  $response = CheshireCat::updateSetting('setting_id', [
      'value' => 'updated_value',
  ]);
  echo $response->getStatusCode();
  

  $response = CheshireCat::deleteSetting('setting_id');
  echo $response->getStatusCode();
  

  $response = CheshireCat::getMemoryPoints('collection_id');
  $points = json_decode($response->getBody(), true);

  print_r($points);
  

  $response = CheshireCat::createMemoryPoint('collection_id', [
      'content' => 'This is a memory point.',
  ]);
  echo $response->getStatusCode();
  

  $response = CheshireCat::deleteMemoryPoint('collection_id', 'point_id');
  echo $response->getStatusCode();
  

  $response = CheshireCat::getAvailablePlugins();
  $plugins = json_decode($response->getBody(), true);

  print_r($plugins);
  

  $file = fopen('/path/to/plugin.zip', 'r');

  $response = CheshireCat::installPlugin([
      [
          'name' => 'file',
          'contents' => $file,
      ],
  ]);
  echo $response->getStatusCode();
  

  $response = CheshireCat::togglePlugin('plugin_id');
  echo $response->getStatusCode();
  

use CheshireCatSdk\Facades\CheshireCatFacade as CheshireCat;
$payload = ['text' => 'Hello, who are you?'];
        CheshireCat::sendMessageViaWebSocket($payload);

        // Ciclo per ricevere più messaggi
        while (true) {
            // Ricevi la risposta
            $response = CheshireCat::wsClient()->receive();
            $response = json_decode($response, true);

            if($response["type"] == "chat"){
                echo $response["text"];
                break;
            }
        }

        // Chiudi la connessione WebSocket
        CheshireCat::closeWebSocketConnection();

use CheshireCatSdk\Facades\CheshireCatFacade as CheshireCat;

$filePath = 'tests/mocks/sample.pdf';
$fileName = 'sample.pdf';
$contentType = 'application/pdf';

$metadata = [
    "source" => "sample.pdf",
    "title" => "Test title",
    "author" => "Test author",
    "year" => 2020,
];

$response = CheshireCat::uploadFile($filePath, $fileName, $contentType, $metadata);

if ($response->getStatusCode() === 200) {
    echo "File uploaded successfully!";
}

use Illuminate\Support\Facades\Route;
use CheshireCatSdk\Facades\CheshireCatFacade as CheshireCat;

Route::get('/meow_connection', function () {
    try {
        // Try to get the status of the Cheshire Cat API
        $statusResponse = CheshireCat::getStatus();

        // Check if the status response is successful
        if ($statusResponse->getStatusCode() === 200) {
            echo "Cheshire Cat API connection successful!<br>";
            echo "Status Response: " . $statusResponse->getBody()->getContents();
        } else {
            echo "Cheshire Cat API connection failed!<br>";
            echo "Status Response: " . $statusResponse->getBody()->getContents();
        }
    } catch (\Exception $e) {
        echo "Cheshire Cat API connection failed!<br>";
        echo "Error: " . $e->getMessage();
    }
});
bash
   php artisan vendor:publish --tag=config --provider="CheshireCatSdk\CheshireCatServiceProvider"