How to Add Asyntai AI Chatbot to Bagisto
Step-by-step guide for Bagisto e-commerce platform
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 Blade Layout Template (Recommended)
Bagisto uses Laravel Blade templates. The recommended approach is to add the embed code directly to the shop layout file:
- Open the shop layout file:
- Package source:
packages/Webkul/Shop/src/Resources/views/layouts/master.blade.php - Published version:
resources/views/vendor/shop/layouts/master.blade.php(if you have published the views)
- Package source:
- Find the closing
</body>tag - Add the embed code just before
</body>, after@stack('scripts'):
@stack('scripts')
<script async src="https://asyntai.com/static/js/chat-widget.js" data-asyntai-id="YOUR_WIDGET_ID"></script>
</body>
Tip: If you have published the vendor views, edit the published version in resources/views/vendor/shop/. Otherwise, publish them first with php artisan vendor:publish --tag=shop-views to avoid losing changes during package updates.
Alternative Method 1: Using @push('scripts') in a View
In any Blade view or component, you can use the scripts stack to inject the chatbot script:
@push('scripts')
<script async src="https://asyntai.com/static/js/chat-widget.js" data-asyntai-id="YOUR_WIDGET_ID"></script>
@endpush
Note: This method requires that @stack('scripts') is present in the master layout file. It is included by default in Bagisto's layout.
Alternative Method 2: Using a Service Provider
You can use a service provider to make the script available across all views programmatically. Create a custom service provider or use AppServiceProvider:
public function boot()
{
view()->composer('shop::layouts.master', function ($view) {
// The script will be available in the layout
});
}
Or create a Blade component that renders the script tag and include it in your layout.
Tip: The service provider approach is useful if you want to conditionally load the chatbot based on configuration values or environment settings.
Alternative Method 3: Using Bagisto Event System
Bagisto fires view events at various points in the layout. You can listen to bagisto.shop.layout.body.after to inject the chatbot script:
Event::listen('bagisto.shop.layout.body.after', function($viewRenderEventManager) {
$viewRenderEventManager->addTemplate('shop::partials.asyntai-widget');
});
Then create the partial template at packages/Webkul/Shop/src/Resources/views/partials/asyntai-widget.blade.php (or the published equivalent) with your embed code:
<script async src="https://asyntai.com/static/js/chat-widget.js" data-asyntai-id="YOUR_WIDGET_ID"></script>
Note: The event system approach keeps your changes modular and separate from the core layout files, making it easier to manage during Bagisto upgrades.
Step 3: Clear Cache and Verify
After adding the embed code, clear the application cache to ensure your changes take effect:
php artisan cache:clear && php artisan view:clear
Visit your Bagisto store 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 ran both php artisan cache:clear and php artisan view:clear. Also try clearing your browser cache or viewing in an incognito window. If you edited the package source directly, verify that no published views are overriding your changes. Check that your embed code is placed correctly before the closing </body> tag.
Weebly