# ChatbotEvent events

> 2 FeatherPanel plugin events on ChatbotEvent (2 emitted by the core): the event names, the arguments each listener gets, where they fire and a PHP listener for each.

Source: https://featherpanel.com/docs/plugins/events/chatbot/

Part of the [plugin events reference](https://featherpanel.com/docs/plugins/events/). Listeners get the payload values as positional arguments in the order shown, cannot cancel the action, and must catch their own exceptions.

## Setup

Import `ChatbotEvent` in your entry class and register listeners in `processEvents()`:

```php
<?php

namespace App\Addons\myplugin;

use App\App;
use App\Plugins\AppPlugin;
use App\Plugins\PluginEvents;
use App\Plugins\Events\Events\ChatbotEvent;

class MyPlugin implements AppPlugin
{
    public static function processEvents(PluginEvents $event): void
    {
        $event->on(ChatbotEvent::onConversationDeleted(), function ($userUuid, $conversationId): void {
            App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:chatbot:conversation:delete ' . json_encode(['user_uuid' => $userUuid, 'conversation_id' => $conversationId]));
        });
    }

    public static function pluginInstall(): void
    {
    }

    public static function pluginUninstall(): void
    {
    }
}
```

## `ChatbotEvent::onConversationDeleted()`

- Name: `featherpanel:chatbot:conversation:delete`
- emitted at 2 sites
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/ChatbotEvent.php#L27)

Docblock: string user uuid, int conversation id.

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `user_uuid` | `$userUuid` | `string`from docblock |
| 2 | `conversation_id` | `$conversationId` | `int` |

When it fires (2 sites)

-   [`ChatbotController::deleteConversation`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/User/ChatbotController.php#L281) via `emitEvent()`[`DELETE /api/user/chatbot/conversations/{id}`](https://featherpanel.com/docs/api/reference/user/chatbot/#delete-user-chatbot-conversations-id)
-   [`VdsChatbotController::deleteConversation`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/User/VdsChatbotController.php#L281) via `emitEvent()`[`DELETE /api/user/vds-chatbot/conversations/{id}`](https://featherpanel.com/docs/api/reference/user/vds/chatbot/#delete-user-vds-chatbot-conversations-id)

```php
$event->on(ChatbotEvent::onConversationDeleted(), function ($userUuid, $conversationId): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:chatbot:conversation:delete ' . json_encode(['user_uuid' => $userUuid, 'conversation_id' => $conversationId]));
});
```

## `ChatbotEvent::onConversationMemoryUpdated()`

- Name: `featherpanel:chatbot:conversation:memory:update`
- emitted at 2 sites
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/ChatbotEvent.php#L35)

Docblock: string user uuid, int conversation id, string memory.

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `user_uuid` | `$userUuid` | `string`from docblock |
| 2 | `conversation_id` | `$conversationId` | `int` |
| 3 | `memory` | `$memory` | `string`from docblock |

When it fires (2 sites)

-   [`ChatbotController::updateMemory`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/User/ChatbotController.php#L357) via `emitEvent()`[`PATCH /api/user/chatbot/conversations/{id}/memory`](https://featherpanel.com/docs/api/reference/user/chatbot/#patch-user-chatbot-conversations-id-memory)
-   [`VdsChatbotController::updateMemory`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/User/VdsChatbotController.php#L357) via `emitEvent()`[`PATCH /api/user/vds-chatbot/conversations/{id}/memory`](https://featherpanel.com/docs/api/reference/user/vds/chatbot/#patch-user-vds-chatbot-conversations-id-memory)

```php
$event->on(ChatbotEvent::onConversationMemoryUpdated(), function ($userUuid, $conversationId, $memory): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:chatbot:conversation:memory:update ' . json_encode(['user_uuid' => $userUuid, 'conversation_id' => $conversationId, 'memory' => $memory]));
});
```
