PHPackages                             danlopez00/chatbase-api - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. danlopez00/chatbase-api

ActiveLibrary[API Development](/categories/api)

danlopez00/chatbase-api
=======================

PHP SDK Wrapper for the Chatbase API (unofficial)

1.0.0-beta1(8y ago)00MITPHPPHP ^7.1

Since Feb 10Pushed 7y ago1 watchersCompare

[ Source](https://github.com/danlopez00/chatbase-api)[ Packagist](https://packagist.org/packages/danlopez00/chatbase-api)[ RSS](/packages/danlopez00-chatbase-api/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (7)Versions (2)Used By (0)

Chatbase API for PHP and Laravel
================================

[](#chatbase-api-for-php-and-laravel)

Chatbase is a Chatbot analytics service by Google.

This is the unofficial Chatbase API for PHP. It focuses heavily on the Laravel Framework however it will work in any standalone project with usage of Composer.

Installation
------------

[](#installation)

This package can be installed through Composer.

```
composer require richdynamix/chatbase-api
```

### Framework Agnostic Usage

[](#framework-agnostic-usage)

```
// API KEY and default platform must be set
$apiKey = '12345-12345-12345';
$platform = 'messenger';
```

```
// Instantiate a new Chatbase client with the dependency of Guzzle
$client = new \Richdynamix\Chatbase\Service\ChatbaseClient(new \GuzzleHttp\Client());
```

```
// Instantiate a new FieldManager with the dependency of the API KEY and default platform
$fieldsManager = new \Richdynamix\Chatbase\Entities\FieldsManager($apiKey, $platform);
```

```
// Instantiate a new GenericMessage with the dependency of the Chatbase client and the FieldsManager
$chatbase = new \Richdynamix\Chatbase\Service\GenericMessage($client, $fieldsManager);
```

```
// send a user message to chatbase
$send = $chatbase->userMessage()->with(['user_id => '12345', 'message' => 'hello'])->send();
```

### Laravel Usage

[](#laravel-usage)

In Laravel &gt;5.5 the package will auto register the service provider. In Laravel 5.4 you must install this service provider.

```
// config/app.php
'providers' => [
    ...
    Richdynamix\Chatbase\ChatbaseServiceProvider::class,
    ...
];
```

In Laravel &gt;5.5 the package will auto register the facades. In Laravel 5.4 you must install the facade manually.

```
// config/app.php
'aliases' => [
    ...
    'Chatbase' => Richdynamix\Chatbase\Facades\Chatbase::class,
    ...
];
```

You can publish the config file of this package with this command:

```
php artisan vendor:publish --provider="Richdynamix\Chatbase\ChatbaseServiceProvider"
```

The following config file will be published in `config/chatbase.php`

```
return [
    /*
     * The Chatbase API key
     */
    'api_key' => env('CHATBASE_API_KEY'),
    'platform' => env('CHATBASE_DEFAULT_PLATFORM', 'messenger'),
];
```

**Only the Generic Messaging API is setup at present**

IoC container
-------------

[](#ioc-container)

The IoC container will automatically resolve the `GenericMessage` dependencies for you. You can grab an instance of `GenericMessage` from the IoC container in a number of ways.

```
// Directly from the IoC
$chatbase = app(Richdynamix\Chatbase\Contracts\GenericMessage::class);

// From a constructor
class FooClass {
    public function __construct(Richdynamix\Chatbase\Contracts\GenericMessage $chatbase) {
       // . . .
    }
}

// From a method
class BarClass {
    public function barMethod(Richdynamix\Chatbase\Contracts\GenericMessage $chatbase) {
       // . . .
    }
}
```

Alternatively you may use the `Chatbase` facade directly

```
    Chatbase::userMessage()->with($data)->send();
```

```
    Chatbase::notHandledUserMessage()->with($data)->send();
```

```
    Chatbase::botMessage()->with($data)->send();
```

#### Fields (keys) that can be set using the `with()` method. (Passed as an array)

[](#fields-keys-that-can-be-set-using-the-with-method-passed-as-an-array)

fieldtyperequireddescriptionuser\_idstringYthe ID of the end-usermessagestringNthe raw message body regardless of type for example a typed-in or a tapped button or tapped imageintentstringNset for user messages only; if not set usage metrics will not be shown per intent; do not set if it is a generic catch all intent, like default fallback, so that clusters of similar messages can be reportedversionstringNset for user and bot messages; used to track versions of your code or to track A/B testscustom\_session\_idstringNset for user and bot messages; used to define your own custom sessions for Session Flow report and daily session metricsUsage
-----

[](#usage)

All methods take the same parameters in the following order -

```
$userId, $message, $intent, $version, $customSessionID
```

#### Send a user message to Chatbase

[](#send-a-user-message-to-chatbase)

```
    $send = $chatbase->userMessage()->with(['user_id => '12345', 'message' => 'hello'])->send();

    // With Facade
    $send = Chatbase::userMessage()->with(['user_id => '12345', 'message' => 'hello'])->send();

    // With helper setters
    $send = Chatbase::userMessage()->withUserId('12345')->withMessage('hello')->send();

    dd($send);
```

Example Response -

```
    {#618 ▼
      +"message_id": "2981752682"
      +"status": 200
    }
```

#### Send a user message to Chatbase for a different platform

[](#send-a-user-message-to-chatbase-for-a-different-platform)

```
    $send = $chatbase->userMessage()->with([
        'user_id => '12345',
        'message' => 'hello',
        'platform' => 'slack'
    ])->send();

    // With Facade
    $send = Chatbase::userMessage()->with([
        'user_id => '12345',
        'message' => 'hello',
        'platform' => 'slack'
    ])->send();

    // With helper setters
    $send = Chatbase::userMessage()
        ->setPlatform('slack')
        ->withUserId('12345')
        ->withMessage('hello')
        ->send();

    dd($send);
```

Example Response -

```
    {#618 ▼
      +"message_id": "2981752682"
      +"status": 200
    }
```

#### Send a user message to Chatbase while logging a version

[](#send-a-user-message-to-chatbase-while-logging-a-version)

```
    $send = $chatbase->userMessage()->with([
            'user_id => '12345',
            'message' => 'hello',
            'version' => '1.2.1'
        ])->send();

    // With Facade
    $send = Chatbase::userMessage()->with([
        'user_id => '12345',
        'message' => 'hello',
        'version' => '1.2.1'
    ])->send();

    // With helper setters
    $send = Chatbase::userMessage()
        ->withUserId('12345')
        ->withMessage('hello')
        ->withVersion('1.2.1')
        ->send();

    dd($send);
```

Example Response -

```
    {#618 ▼
      +"message_id": "2981752682"
      +"status": 200
    }
```

#### Send a user message to Chatbase with intent

[](#send-a-user-message-to-chatbase-with-intent)

```
    $send = $chatbase->userMessage()->with([
        'user_id => '12345',
        'message' => 'hello',
        'intent' => 'hotel-booking'
    ])->send();

    // With Facade
    $send = Chatbase::userMessage()->with([
        'user_id => '12345',
        'message' => 'hello',
        'intent' => 'hotel-booking'
    ])->send();

    // With helper setters
    $send = Chatbase::userMessage()
        ->withUserId('12345')
        ->withMessage('hello')
        ->withIntent('hotel-booking')
        ->send();

    dd($send);
```

Example Response -

```
    {#618 ▼
      +"message_id": "2981752682"
      +"status": 200
    }
```

#### Send failed user message not handled by the bot

[](#send-failed-user-message-not-handled-by-the-bot)

```
    $send = $chatbase->notHandledUserMessage()
        ->with([
            'user_id => '12345',
            'message' => 'hello',
        ])
        ->send();

    // With Facade
    $send = Chatbase::notHandledUserMessage()
        ->with([
          'user_id => '12345',
          'message' => 'hello',
        ])
        ->send();

    // With helper setters
    $send = Chatbase::userMessage()
        ->withUserId('12345')
        ->withMessage('hello')
        ->withIntent('hotel-booking')
        ->send();

    dd($send);
```

Example Response -

```
    {#618 ▼
      +"message_id": "29817235682"
      +"status": 200
    }
```

#### Send a bot message sent back to the user

[](#send-a-bot-message-sent-back-to-the-user)

```
    $send = $chatbase->botMessage()->with(['user_id => '12345','message' => 'hello'])->send();

    // With facade
    $send = Chatbase::botMessage()->with(['user_id => '12345','message' => 'hello'])->send();

    // With helper setters
    $send = Chatbase::botMessage()->withUserId('12345')->withMessage('hello')->send();

    dd($send);
```

Response -

```
    {#618 ▼
      +"message_id": "29347235682"
      +"status": 200
    }
```

### Working with multiple bots

[](#working-with-multiple-bots)

Sometime you may wish to push your bot activity to different chatbase accounts. Perhaps you have multiple bots running in the one application. You can easily set the `API KEY` for each bot on each method call.

```
    $send = $chatbase->userMessage()->with([
        'api_key' => 'my-chatbase-api-key',
        'user_id => '12345',
        'message' => 'hello'
    ])->send();

    // With facade
    $send = Chatbase::userMessage()->with([
        'api_key' => 'my-chatbase-api-key',
        'user_id => '12345',
        'message' => 'hello'
    ])->send();

    // With helper setters
    $send = Chatbase::botMessage()->setApiKey('my-chatbase-api-key')->withUserId('12345')->withMessage('hello')->send();

    dd($send);
```

Example Response -

```
    {#618 ▼
      +"message_id": "2981752682"
      +"status": 200
    }
```

\***Please Note: Invalid fields sent to Chatbase may result in a successful entry however, you will receive a 400 error and a `WrongDataSet` exception will be thrown. This is common when you set fields like `intent` for bot messages.**

### Changelog

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Steven Richardson](https://github.com/richdynamix)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

19

—

LowBetter than 10% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity0

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

3015d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1d503b7b58c52ca995b7469787b6afd489659fd44df49852526db42c1b94182e?d=identicon)[danlopez00](/maintainers/danlopez00)

---

Top Contributors

[![danlopez00](https://avatars.githubusercontent.com/u/727396?v=4)](https://github.com/danlopez00 "danlopez00 (3 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/danlopez00-chatbase-api/health.svg)

```
[![Health](https://phpackages.com/badges/danlopez00-chatbase-api/health.svg)](https://phpackages.com/packages/danlopez00-chatbase-api)
```

###  Alternatives

[laravel/cashier-paddle

Cashier Paddle provides an expressive, fluent interface to Paddle's subscription billing services.

264778.4k3](/packages/laravel-cashier-paddle)[vluzrmos/slack-api

Wrapper for Slack.com WEB API.

102589.1k3](/packages/vluzrmos-slack-api)[ashallendesign/laravel-exchange-rates

A wrapper package for interacting with the exchangeratesapi.io API.

485677.8k](/packages/ashallendesign-laravel-exchange-rates)[smodav/mpesa

M-Pesa API implementation

16363.7k1](/packages/smodav-mpesa)[flarum/core

Delightfully simple forum software.

211.3M1.9k](/packages/flarum-core)[simplestats-io/laravel-client

Client for SimpleStats!

4515.5k](/packages/simplestats-io-laravel-client)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
