Search by

spontena / pb-php

knlab

This package is abandoned and no longer maintained. No replacement package was suggested.

Pandorabots API client for PHP

Package info

github.com/spontena/pb-php

pkg:composer/spontena/pb-php

Statistics

Installs: 391

Dependents: 1

Suggesters: 0

Stars: 6

Open Issues: 0

v2.3.1 2026-11-20 17:44 UTC

README

Pandorabots API client for PHP.

Warning

Pandorabots has shut down its developer hosting platform, so this library no longer works. In 2026 Pandorabots wound down the hosted bot service and the API that pb-php calls (api.pandorabots.com); its website now carries a "Hosting Service Sunset" notice. pb-php is no longer maintained, and 2.3.1 is its final release.

To keep running AIML bots, Pandorabots points to open-source AIML interpreters: Program AB (Java, AIML 2.0 reference implementation), Program-Y (Python), aimlinterpreter (Node.js), and community projects such as Program O (PHP) listed under github.com/pandorabots. The AIML specification is at aiml.foundation. Customers who missed the migration window can contact support@pandorabots.com.

The rest of this README describes the library as it worked while the service was available.

The official Pandorabots API documentation used to be at https://www.pandorabots.com/docs/api-endpoints/; it is no longer online.

Requirements

  • PHP 8.3 or newer — keep it on the latest patch release of a supported branch
  • ext-json
  • Guzzle 7.16+ (7.x) or 8.x, with guzzlehttp/psr7 2.12.3+ (2.x) or 3.x

pb-php 2.2 and later require PHP 8.3 or newer. On PHP 8.1 or 8.2, Composer keeps projects on 2.1.5, the last release that supports them. PHP 8.1 no longer receives security fixes and PHP 8.2 reaches end of life on 31 December 2026, so upgrading PHP is recommended.

Windows: Brotli decompression (CVE-2026-111497)

PHP Windows builds older than 8.5.12-1, 8.4.27-1, 8.3.36-1, and 8.2.35-1 bundle a Brotli decoder with an out-of-bounds write vulnerability (CVE-2026-111497). Guzzle enables cURL's automatic response decompression by default, so pb-php requests can reach the vulnerable decoder if a server, or anyone able to tamper with the connection, returns a crafted Brotli-encoded response.

Update to one of the rebuilt Windows packages above or a later release. PHP 8.1 is end of life and has no rebuilt package. If you cannot update yet, pass a Guzzle client with response decompression disabled:

use GuzzleHttp\Client;
use GuzzleHttp\RequestOptions;
use Spontena\PbPhp\PBClient;

$pb = new PBClient(
    host:    'https://api.pandorabots.com',
    appId:   getenv('PB_APP_ID'),
    userKey: getenv('PB_USER_KEY'),
    http:    new Client([
        RequestOptions::CONNECT_TIMEOUT => 5,  // pb-php's default timeouts
        RequestOptions::TIMEOUT         => 30,
        RequestOptions::DECODE_CONTENT  => false,
    ]),
);

On Linux and macOS, PHP uses the system libcurl and Brotli libraries; keep them updated through your OS or package manager.

Installation

composer require spontena/pb-php

Quickstart

use Spontena\PbPhp\PBClient;
use Spontena\PbPhp\FileKind;
use Spontena\PbPhp\Exception\ApiException;

$pb = new PBClient(
    host:    'https://api.pandorabots.com',
    appId:   getenv('PB_APP_ID'),
    userKey: getenv('PB_USER_KEY'),
);

try {
    $pb->create('mybot');
    $pb->upload(__DIR__ . '/aiml/greetings.aiml', 'mybot');
    $pb->compile('mybot');

    $reply = $pb->talk('hello', 'mybot');
    foreach ($reply->responses as $line) {
        echo $line, "\n";
    }
} catch (ApiException $e) {
    fprintf(STDERR, "Pandorabots API error %d: %s\n", $e->getStatusCode(), $e->getResponseBody());
}

A working end-to-end script lives in examples/quickstart.php. Run it after setting PB_APP_ID and PB_USER_KEY:

PB_APP_ID=xxx PB_USER_KEY=yyy php examples/quickstart.php

API reference

Method HTTP Endpoint
getBotsList() GET /bot/{appId}
create($botname) PUT /bot/{appId}/{botname}
delete($botname) DELETE /bot/{appId}/{botname}
getBotFiles($botname) GET /bot/{appId}/{botname}
getBotFile(FileKind $kind, $botname, ?$name) GET /bot/{appId}/{botname}/{kind}[/{name}] (since v2.1.0)
upload($path, $botname) PUT /bot/{appId}/{botname}/{kind}[/{name}]
deleteBotFile($name, FileKind $kind, $botname) DELETE /bot/{appId}/{botname}/{kind}[/{name}]
compile($botname) GET /bot/{appId}/{botname}/verify
talk($input, $botname, ...) POST /talk/{appId}/{botname}
debug($input, $botname, ...) POST /talk/{appId}/{botname} (with trace etc.)
atalk($input, ...) POST /talk?botkey=... (botkey auth, bot identified by key)

Successful responses are returned as stdClass (the decoded JSON body). getBotsList() returns a list<\stdClass> because the API responds with a top-level JSON array. getBotFile() returns the raw response body as a string (no JSON decoding) — useful for downloading AIML/set/map content. HTTP 4xx/5xx responses raise Spontena\PbPhp\Exception\ApiException; bad inputs raise InvalidArgumentException or InvalidFileException.

upload() infers the file kind from the extension:

Extension FileKind URL form
.aiml File /bot/.../file/{name}
.set Set /bot/.../set/{name}
.map Map /bot/.../map/{name}
.substitution Substitution /bot/.../substitution/{name}
.pdefaults Pdefaults /bot/.../pdefaults
.properties Properties /bot/.../properties

Migration from v1

v2 is a breaking-change release. Notable differences:

  • Namespace is now Spontena\PbPhp (was spontena\pbphp); autoloading switched from PSR-0 to PSR-4.
  • Constructor accepts named arguments and an optional botKey for atalk().
  • HTTP errors throw ApiException instead of returning { status: "error", ... }.
  • deleteBotFile() now takes a FileKind enum instead of a string.
  • botname and filenames are URL-encoded.
  • debug()'s broken client_name parameter (the long-standing $clientname typo) is fixed.
  • Requires PHP 8.1+ and Guzzle 7.x (see Requirements for the current minimum patched version).

Error handling and logging

HTTP errors throw ApiException. Its message contains the HTTP status and the request method/URL path, without the query or response body. Use getStatusCode(), getResponseBody(), or getDecodedBody() for application error handling instead of parsing the exception message.

Transport failures keep the class of the built-in Guzzle exception, with a fixed message (plus the numeric cURL error code when available) and no previous exception. On Guzzle 7 that is ConnectException, RequestException, or TooManyRedirectsException. Guzzle 8 classifies failures more precisely, for example ConnectTimeoutException, NetworkTimeoutException, NetworkException, ResponseTransferException, and ResponseTimeoutException, and those classes are kept as well. Code that supports both Guzzle versions can catch Psr\Http\Client\NetworkExceptionInterface for failures without a response. Custom subclasses raised by an injected HTTP client are rebuilt as the nearest built-in Guzzle class.

Request and response accessors, and on Guzzle 7 the handler context, remain available for retries and diagnostics, and can contain credentials or conversation data. Guzzle 8 removed getHandlerContext(); use its exception classes or the on_stats request option instead. Do not log raw accessor values or dump entire exception objects.

Use zend.exception_ignore_args=On when logging exception traces. This library also redacts its sensitive parameters using SensitiveParameter; callers remain responsible for sensitive arguments in their own stack frames. This library does not change global PHP settings.

Testing

Unit tests (no API access)

composer install
composer test          # PHPUnit unit suite (mocked HTTP, runs by default)
composer analyse       # PHPStan (level 6)

CI runs the unit suite, PHPStan, and dependency audit on PHP 8.3 / 8.4 / 8.5 / 8.6, each with Guzzle 7 and Guzzle 8 — see .github/workflows/ci.yml.

Integration tests (real Pandorabots API)

The tests/Integration/ suite hits the live API to validate that endpoint URLs, request formats, and response shapes still match. It is not run by default. Provide credentials via env vars and invoke the integration suite explicitly:

PB_APP_ID=xxx PB_USER_KEY=yyy vendor/bin/phpunit --testsuite integration

Test bots are created with names like pbphpci<hint><random> (lowercase alphanumeric only — Pandorabots rejects hyphens) and removed in tearDown() even if a test fails.

To exercise atalk(), additionally set PB_BOT_KEY for an existing, compiled bot whose bot key has been issued in the Pandorabots dashboard:

PB_BOT_KEY=zzz \
PB_APP_ID=xxx PB_USER_KEY=yyy \
vendor/bin/phpunit --testsuite integration

The bot is identified by the bot key alone — no botname is needed in the request path.

Env var Purpose
PB_APP_ID Pandorabots app id (required)
PB_USER_KEY Pandorabots user key (required)
PB_HOST API host, defaults to https://api.pandorabots.com
PB_BOT_KEY Bot key for atalk() integration test (optional)

License

MIT — see LICENSE.txt.