django-asyntai-ai-chatbot
Adds the Asyntai AI chat assistant to a Django 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.
- Requires Django 4.2 or newer and Python 3.10 or newer
- Documentation: https://asyntai.com/documentation/integrations/django/
Install
pip install django-asyntai-ai-chatbot
Add the app to INSTALLED_APPS:
INSTALLED_APPS = [
# ...
"django_asyntai",
]
Add the middleware at the end of MIDDLEWARE:
MIDDLEWARE = [
# ...
"django_asyntai.middleware.AsyntaiWidgetMiddleware",
]
Put your widget ID in your settings file:
ASYNTAI_WIDGET_ID = "asyntai_ab12cd34"
You get the ID from the Install page of your Asyntai dashboard. 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. No template edit and no migration.
Settings
ASYNTAI_WIDGET_ID = "asyntai_ab12cd34" # required; empty switches the chat off
ASYNTAI_SHOW_TO_ANONYMOUS_ONLY = False # optional; hide the chat from signed-in users
ASYNTAI_SKIP_PREFIXES = ["/admin/"] # optional; paths the widget never touches
ASYNTAI_SCRIPT_URL = "https://widget.asyntai.com/static/js/chat-widget.js" # optional
The values are read on every request, so you can keep the ID in an environment variable:
import os
ASYNTAI_WIDGET_ID = os.environ.get("ASYNTAI_WIDGET_ID", "")
Set ASYNTAI_SKIP_PREFIXES when your admin lives somewhere other than
/admin/. Change ASYNTAI_SCRIPT_URL only if Asyntai support asks you to.
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 needs the request in the template context, which Django's default
django.template.context_processors.request provides. The tag and the
middleware never both fire, so it is safe to keep both.
GZipMiddleware
If you use GZipMiddleware, list AsyntaiWidgetMiddleware below it, so the
widget goes into the page before the page is compressed. manage.py check
warns you when the order is wrong.
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. Only an https script address is
accepted.
The middleware leaves alone: the 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.
Checks
manage.py check reports three mistakes:
| ID | Meaning |
|---|---|
django_asyntai.W001 |
ASYNTAI_WIDGET_ID is not a valid widget ID. |
django_asyntai.W002 |
ASYNTAI_SCRIPT_URL is not an https address. |
django_asyntai.W003 |
The middleware is listed above GZipMiddleware. |
Tests
pip install django
PYTHONPATH=src:. python -m django test --settings=tests.settings
Support
Licence
MIT. See LICENSE.
Metadata
Release files for django-asyntai-ai-chatbot 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| django_asyntai_ai_chatbot-1.0.0.tar.gz | 13.7 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_asyntai_ai_chatbot-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 24.2 kB
Release files / django_asyntai_ai_chatbot-1.0.0.tar.gz
| Download URL | django_asyntai_ai_chatbot-1.0.0.tar.gz |
|---|---|
| Size | 13.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ff28be11edd1d8860b954ffaf65bcfea2339bd15a4c2f87e6ba77217444c4c27
|
|
BLAKE2b-256 checksum How to use checksums |
ca0ea6dd1d10e2993a0d1a83e6bb3a6c2ba4410d5817aeca8560f4a85c282c1f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.10
|
Release files / django_asyntai_ai_chatbot-1.0.0-py3-none-any.whl
| Download URL | django_asyntai_ai_chatbot-1.0.0-py3-none-any.whl |
|---|---|
| Size | 10.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
97664fa0cfef60643b962de5ebc995d10ab8ebc5fdf0e577ad85a6d04e85294f
|
|
BLAKE2b-256 checksum How to use checksums |
f914b1da17b97cfc9b5612234ca5a9fe5b7e68dba0265b4c9413a43a73f38241
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.10
|
Security for django-asyntai-ai-chatbot 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.