CakePHP Plugin
Add the Asyntai AI chat assistant to your CakePHP app
Overview
CakePHP is a popular PHP framework for websites, shops, portals and business apps. The Asyntai plugin adds the chat assistant to every page of your CakePHP app. Install it with Composer, add your widget ID, and the chat bubble is there for every visitor.
The assistant answers from your own content, such as your website, help center, docs and FAQs, in more than 80 languages, day and night. It can also know who is signed in, so its answers fit each user.
Requirements
- CakePHP 4.4 or later, or CakePHP 5
- PHP 8.1 or later
- An Asyntai account. The Free plan is enough to try the widget
Installation
Follow these steps to add Asyntai to your CakePHP app:
Get Your Widget ID
Sign in to Asyntai and open the Install page. The widget ID is the value of data-asyntai-id in the snippet shown there. It starts with asyntai_.
Install the Plugin
Run these commands in your CakePHP project:
composer require asyntai/cakephp-ai-chatbot
bin/cake plugin load Asyntai/AiChatbot
Add Your Widget ID
Add this to config/app_local.php:
'AiChatbot' => [
'widgetId' => 'asyntai_1a2b3c4d5e6f',
],
Or set the ASYNTAI_WIDGET_ID environment variable. Open your site and the chat bubble is in the corner of every page.
Options
All options go under the AiChatbot key in your config.
| Option | What it does |
|---|---|
widgetId | Your widget ID. It wins over ASYNTAI_WIDGET_ID |
visible | A function that gets the request. Show the widget only when it returns true, for example to keep it out of your admin pages |
userContext | A function that gets the request and returns data about the visitor that the assistant can use in its answers |
autoInject | Set to false to place the widget yourself with the view helper |
scriptUrl | Advanced. Load the widget from another URL |
'AiChatbot' => [
'widgetId' => 'asyntai_1a2b3c4d5e6f',
'visible' => fn ($request) => !str_starts_with($request->getUri()->getPath(), '/admin'),
],
Personal Answers With User Context
In a customer portal or a shop account area, the assistant can know who is asking. Pass the details you want it to use, for example from the CakePHP Authentication plugin:
'userContext' => function ($request) {
$identity = $request->getAttribute('identity');
return $identity ? ['name' => $identity->name, 'plan' => $identity->plan] : null;
},
The assistant can then greet users by name and answer questions about their own account. Guests get the widget without any user data. User context is part of the Standard and Pro plans.
Placing the Widget Yourself
Set 'autoInject' => false, load the helper in src/View/AppView.php, and print the widget in your layout before </body>:
// src/View/AppView.php, in initialize()
$this->addHelper('Asyntai/AiChatbot.AiChatbot');
// templates/layout/default.php
<?= $this->AiChatbot->widget() ?>
The helper also takes widgetId, scriptUrl and userContext options, so one section of your site can have its own assistant.
How It Works
The plugin adds one small script before </body> on every full HTML page. The script loads the widget after your page has finished loading, so your pages always render first. JSON responses, files, redirects, error pages and AJAX responses stay as they are.
Answering From Your Content
Asyntai reads your published pages. Add your website URL in the dashboard, and the assistant answers from those pages. You can also add documents, and question and answer pairs.
Tip: Use the visible option to show the assistant only to customers, or only on your public pages.
Removing It
Run bin/cake plugin unload Asyntai/AiChatbot and composer remove asyntai/cakephp-ai-chatbot. The chat bubble is gone.
Plans & Pricing
The plugin is free. View pricing.
Need Help?
If you have any questions or run into issues, contact us at [email protected].