How to Add Asyntai AI Chatbot to ProcessWire

Step-by-step guide for ProcessWire CMS websites

Get Embed Code

Step 1: Get Your Embed Code

First, go to your Asyntai Dashboard and scroll down to the "Embed Code" section. Copy your unique embed code which will look like this:

<script async src="https://asyntai.com/static/js/chat-widget.js" data-asyntai-id="YOUR_WIDGET_ID"></script>

Note: The code above is just an example. You must copy your own unique embed code from your Dashboard as it contains your personal widget ID.

Step 2: Add to Template File (Recommended)

ProcessWire uses PHP template files located in the site/templates/ directory. The easiest approach is to add the embed code directly to your main template file:

  1. Access your ProcessWire installation files via FTP, SSH, or your file manager
  2. Navigate to site/templates/
  3. Open your main template file — this is often _main.php or basic-page.php depending on your site profile
  4. If you are using the delayed output strategy (the default for most site profiles), open _main.php
  5. Find the closing </body> tag
  6. Paste your Asyntai embed code just before it:
<script async src="https://asyntai.com/static/js/chat-widget.js" data-asyntai-id="YOUR_WIDGET_ID"></script>
</body>

Tip: Placing the script just before the closing </body> tag ensures the chatbot loads after the page content, which is recommended for optimal performance and won't slow down your page rendering.

Alternative Method 1: Using _foot.inc or _main.php Append File

If your ProcessWire site uses the append file approach (common in many site profiles), you can add the embed code to the shared footer include:

  1. Navigate to site/templates/
  2. Open _foot.inc (or your equivalent footer include file)
  3. Paste your Asyntai embed code just before the closing </body> tag
  4. Save the file

ProcessWire's delayed output strategy typically works with three key files:

  • _init.php — runs before every template, initializes variables
  • Your template file (e.g., basic-page.php) — populates content variables
  • _main.php — outputs the final HTML markup using those variables

If your site uses this approach, adding the script to _main.php before </body> ensures it appears on every page.

Note: The file names _init.php and _main.php are configured in your site/config.php via the $config->prependTemplateFile and $config->appendTemplateFile settings. Check your config if your files are named differently.

Alternative Method 2: Using $config->scripts Array

ProcessWire provides a $config->scripts FilenameArray that you can use to manage JavaScript files. In your _init.php or individual template file, add:

<?php
$config->scripts->add('https://asyntai.com/static/js/chat-widget.js');
?>

Then in your _main.php (or footer include), loop through the scripts array to output them:

<?php foreach($config->scripts as $file): ?>
<script src="<?php echo $file; ?>"></script>
<?php endforeach; ?>

Important: The $config->scripts approach handles the script src attribute, but the data-asyntai-id attribute needs to be handled separately. You will need to either add the data attribute manually in the loop output, or use the direct script tag method from Step 2 instead for the simplest setup.

Alternative Method 3: Using a Hook (ready.php)

For a more advanced approach, you can use ProcessWire's hook system to automatically inject the chatbot script into every page. Add the following to your site/ready.php file:

<?php
$wire->addHookAfter('Page::render', function(HookEvent $event) {
    $html = $event->return;
    $script = '<script async src="https://asyntai.com/static/js/chat-widget.js" data-asyntai-id="YOUR_WIDGET_ID"></script>';
    $html = str_replace('</body>', $script . '</body>', $html);
    $event->return = $html;
});
?>

This hook intercepts the rendered HTML output of every page and injects the Asyntai script just before the closing </body> tag automatically.

Tip: The ready.php hook approach is ideal if you want the chatbot on every page without modifying any template files. It also survives template changes and theme updates since it lives outside the template files.

Step 3: Verify Installation

After saving your changes, visit your ProcessWire site in a new browser tab or incognito window. You should see the chat widget button in the bottom right corner. Click it to make sure it opens and works correctly.

Not seeing the widget? Make sure you saved all modified files. Try clearing your browser cache or viewing in an incognito window. If ProcessWire's template cache is enabled, you may need to clear it by going to Modules → Core → Template Engine Cache or by adding ?nocache=1 to your URL. Also verify that your template file is actually being used by the pages you are viewing.