Metadata-Version: 2.4
Name: wagtail-ai-chatbot
Version: 1.0.1
Summary: Adds the Asyntai AI chat assistant to a Wagtail site. It answers visitor questions from your own content, in more than 80 languages.
Author-email: Asyntai <hello@asyntai.com>
License: MIT
Project-URL: Homepage, https://asyntai.com
Project-URL: Documentation, https://asyntai.com/documentation/integrations/wagtail/
Project-URL: Source, https://github.com/asyntai/wagtail-ai-chatbot
Project-URL: Issues, https://github.com/asyntai/wagtail-ai-chatbot/issues
Keywords: wagtail,django,chatbot,ai,live-chat,support,assistant
Classifier: Development Status :: 5 - Production/Stable
Classifier: Environment :: Web Environment
Classifier: Framework :: Django
Classifier: Framework :: Django :: 4.2
Classifier: Framework :: Django :: 5.0
Classifier: Framework :: Django :: 5.1
Classifier: Framework :: Django :: 5.2
Classifier: Framework :: Wagtail
Classifier: Framework :: Wagtail :: 5
Classifier: Framework :: Wagtail :: 6
Classifier: Framework :: Wagtail :: 7
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: Django>=4.2
Requires-Dist: wagtail>=5.2
Dynamic: license-file

# wagtail-ai-chatbot

Adds the [Asyntai](https://asyntai.com) 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.

- Requires Wagtail 5.2 or newer, Django 4.2 or newer, Python 3.9 or newer
- Documentation: https://asyntai.com/documentation/integrations/wagtail/

## Install

```
pip install wagtail-ai-chatbot
```

Add the app and the settings module to `INSTALLED_APPS`:

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

Add the middleware, first in the list:

```python
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.

```python
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:

```html
{% 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](LICENSE).
