Skip to main content

wagtail-ai-chatbot

Adds the Asyntai AI chat assistant to a Wagtail site. The assistant answers visitor questions from your own content, day and night, in more than 80 languages.

Free and open source. Works on every Asyntai plan, including the free plan.

Install

pip install wagtail-ai-chatbot

Add the app and the settings module to INSTALLED_APPS:

INSTALLED_APPS = [
    "wagtail_asyntai",
    "wagtail.contrib.settings",
    # ...
]

Add the middleware, first in the list:

MIDDLEWARE = [
    "wagtail_asyntai.middleware.AsyntaiWidgetMiddleware",
    # ...
]

Run the migration:

python manage.py migrate wagtail_asyntai

Then open the Wagtail admin, go to Settings → Asyntai chat assistant, and paste your widget ID. You get the ID from your Asyntai dashboard, under Setup & Integration. You can paste the whole snippet; the package keeps only the ID.

That is all. The chat button appears on every page of the site.

Settings in the Wagtail admin

Field What it does
Widget ID The chat runs while this holds a valid ID. Clear it to switch the chat off.
Show the chat to signed out visitors only Signed in users never see the chat.
Widget script address Leave this alone unless Asyntai support asks you to change it.

The settings are per site, so a multi-site project can give each site its own assistant.

Settings in your settings file

A project that keeps configuration in environment variables can skip the admin. The admin wins when both are filled in.

ASYNTAI_WIDGET_ID = "asyntai_ab12cd34"
ASYNTAI_SHOW_TO_ANONYMOUS_ONLY = False       # optional
ASYNTAI_SCRIPT_URL = "https://widget.asyntai.com/static/js/chat-widget.js"  # optional
ASYNTAI_SKIP_PREFIXES = ["/admin/", "/django-admin/", "/cms/"]             # optional

ASYNTAI_SKIP_PREFIXES names the paths the widget never touches. Set it when your admin lives somewhere other than /admin/.

Placing the widget by hand

Leave the middleware out and put the tag where you want it instead:

{% load asyntai %}
...
{% asyntai_widget %}
</body>

The tag and the middleware never both fire, so it is safe to keep both.

How it works

The middleware inserts a small script just before the closing body tag of every HTML page. That script waits for the page to finish loading, then fetches the chat widget from Asyntai, so your site draws first and page speed is unchanged.

The widget ID and the script address travel to the browser on a data attribute, never inside the script, so a pasted value cannot break out and run. Only an https address is accepted.

The middleware leaves alone: the Wagtail admin, anything that is not text/html, any status other than 200, a streaming response, a body another middleware has compressed, a page with no closing body tag, and a page that already carries the widget.

Tests

pip install wagtail
PYTHONPATH=src:. python -m django test --settings=tests.settings

50 tests. They cover reading a stored value, the settings screen in the Wagtail admin, the middleware on ten kinds of response, the template tag, and a node --check of the script on the rendered page.

Support

hello@asyntai.com

Licence

MIT. See LICENSE.

Metadata

Release files for wagtail-ai-chatbot 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for wagtail-ai-chatbot 1.0.1
File Size Uploaded
wagtail_ai_chatbot-1.0.1.tar.gz 12.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for wagtail-ai-chatbot 1.0.1
File Interpreter ABI Platform
wagtail_ai_chatbot-1.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 24.8 kB

Release files / wagtail_ai_chatbot-1.0.1.tar.gz

Download URL wagtail_ai_chatbot-1.0.1.tar.gz
Size 12.9 kB
Tags Source
SHA-256 checksum
How to use checksums
4c5066d11b2cf413c8048807946b76bc77518de7d3a2ad80cdccec3fa90df6a6
BLAKE2b-256 checksum
How to use checksums
d377421f04fe4e759041dcfc8fa6aa5064128c0e872535991054a503ffce4fa0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.6

Release files / wagtail_ai_chatbot-1.0.1-py3-none-any.whl

Download URL wagtail_ai_chatbot-1.0.1-py3-none-any.whl
Size 11.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6c8f5b51160ef596ebb25bfbd8640a7736557da1d73ca880ef8c1e547155dccd
BLAKE2b-256 checksum
How to use checksums
358f5ac45b8b2812ddaa0ef9431e5693d4ed6b237c29402adaf735c3e6ba01d3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.6

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page