PHP code example of asyntai / cakephp-ai-chatbot

1. Go to this page and download the library: Download asyntai/cakephp-ai-chatbot 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/ */

    

asyntai / cakephp-ai-chatbot example snippets


'AiChatbot' => [
    'widgetId' => 'asyntai_1a2b3c4d5e6f',
],

'AiChatbot' => [
    // Your widget ID. It wins over ASYNTAI_WIDGET_ID.
    'widgetId' => 'asyntai_1a2b3c4d5e6f',

    // Show the widget only when this returns true. It gets the request.
    'visible' => fn ($request) => !str_starts_with($request->getUri()->getPath(), '/admin'),

    // Data about the visitor that the assistant can use in its answers.
    'userContext' => function ($request) {
        $identity = $request->getAttribute('identity');

        return $identity ? ['name' => $identity->name, 'plan' => $identity->plan] : null;
    },

    // Set to false to place the widget yourself with the view helper.
    'autoInject' => true,

    // Advanced. Load the widget from another URL.
    'scriptUrl' => 'https://widget.asyntai.com/static/js/chat-widget.js',
],

// src/View/AppView.php, in initialize()
$this->addHelper('Asyntai/AiChatbot.AiChatbot');

<?= $this->AiChatbot->widget()