How to Add Asyntai AI Chatbot to Moodle
Step-by-step guide for Moodle LMS websites
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: Using Additional HTML (Recommended)
Moodle has a built-in feature to add custom HTML/JavaScript to all pages:
- Log in to your Moodle site as an administrator
- Go to Site administration
- Navigate to Appearance → Additional HTML
- Scroll down to the "Before BODY is closed" section
- Paste your Asyntai embed code in the text area
- Click "Save changes"
Tip: Adding the code to "Before BODY is closed" places it just before the closing </body> tag, which is the recommended placement for chat widgets and ensures it loads after the main page content.
Alternative: Using Theme Settings
Many Moodle themes (including Boost and its variants) have their own settings for adding custom JavaScript:
- Go to Site administration → Appearance → Themes
- Click on Theme settings for your active theme (e.g., Boost)
- Look for "Raw SCSS", "Additional HTML", or "Custom JavaScript" section
- If there's a JavaScript field, paste your Asyntai embed code there
- Click "Save changes"
- Purge the caches: Site administration → Development → Purge caches
Note: Theme-specific settings vary between themes. If your theme doesn't have a JavaScript field, use the Additional HTML method above.
Alternative: Creating a Local Plugin
For more control, you can create a simple local plugin:
- Create the folder structure:
local/asyntaichatbot/in your Moodle installation - Create version.php:
<?php
defined('MOODLE_INTERNAL') || die();
$plugin->component = 'local_asyntaichatbot';
$plugin->version = 2024010100;
$plugin->requires = 2022041900; - Create lib.php:
<?php
defined('MOODLE_INTERNAL') || die();
function local_asyntaichatbot_before_footer() {
global $PAGE;
$PAGE->requires->js_call_amd('local_asyntaichatbot/loader', 'init');
} - Create folder amd/src/ and file loader.js:
define([], function() {
return {
init: function() {
var script = document.createElement('script');
script.async = true;
script.src = 'https://asyntai.com/static/js/chat-widget.js';
script.setAttribute('data-asyntai-id', 'YOUR_WIDGET_ID');
document.body.appendChild(script);
}
};
}); - Replace
YOUR_WIDGET_IDwith your actual widget ID - Go to Site administration → Notifications to install the plugin
- Purge caches after installation
Important: The local plugin method requires command-line access to create files. For most users, the Additional HTML method is simpler and sufficient.
Alternative: Edit Theme Footer Template
You can also edit your theme's footer template directly:
- Navigate to your theme folder:
theme/YOUR_THEME/ - Find the layout files (e.g.,
layout/columns2.phportemplates/columns2.mustache) - Find the closing
</body>tag or the footer section - Add your Asyntai embed code just before
</body> - Save the file
- Purge Moodle caches
Important: Editing theme files directly means changes may be lost when updating your theme. Use a child theme or the Additional HTML method for a more permanent solution.
Step 3: Verify Installation
After saving your changes and purging the caches, visit your Moodle 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 to purge all Moodle caches: go to Site administration → Development → Purge all caches. Also try clearing your browser cache or viewing in an incognito window. If you're using a caching plugin or reverse proxy, clear those caches as well.