Metadata-Version: 2.4
Name: dash-ai-chatbot
Version: 1.0.0
Summary: Adds the Asyntai AI chat assistant to a Plotly Dash app. It answers visitor questions from your own content, in more than 80 languages.
Author-email: Asyntai <hello@asyntai.com>
License-Expression: MIT
Project-URL: Homepage, https://asyntai.com
Project-URL: Documentation, https://asyntai.com/documentation/integrations/plotly-dash/
Project-URL: Source, https://github.com/asyntai/dash-ai-chatbot
Project-URL: Issues, https://github.com/asyntai/dash-ai-chatbot/issues
Keywords: dash,plotly,plotly-dash,chatbot,ai,ai-chatbot,live-chat,customer-support,assistant,widget
Classifier: Development Status :: 5 - Production/Stable
Classifier: Environment :: Web Environment
Classifier: Framework :: Dash
Classifier: Framework :: Flask
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: dash>=2.0
Dynamic: license-file

# dash-ai-chatbot

Adds the [Asyntai](https://asyntai.com) AI chat assistant to a
[Plotly Dash](https://dash.plotly.com) app. 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 Dash 2.0 or newer and Python 3.10 or newer
- Documentation: https://asyntai.com/documentation/integrations/plotly-dash/

## Install

```
pip install dash-ai-chatbot
```

Add one line after you create the app:

```python
from dash import Dash, html
import dash_ai_chatbot

app = Dash(__name__)
app.layout = html.Div("Hello")

dash_ai_chatbot.init_app(app, widget_id="asyntai_ab12cd34")

if __name__ == "__main__":
    app.run()
```

You get the ID from the Install page of your
[Asyntai dashboard](https://asyntai.com/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 app, including
multi-page apps.

## No code change (Dash 3 and later)

On Dash 3 and later the package also works with no code change. Install it and
set one environment variable:

```
ASYNTAI_WIDGET_ID=asyntai_ab12cd34
```

Every Dash app that runs with that variable gets the chat. Without the
variable the package does nothing.

## Keep the ID out of the code

Leave out `widget_id` and the package reads `ASYNTAI_WIDGET_ID` each time the
page is built:

```python
dash_ai_chatbot.init_app(app)
```

## Options

```python
dash_ai_chatbot.init_app(
    app,
    widget_id="asyntai_ab12cd34",  # or the whole snippet; empty or invalid = chat off
    script_url=None,               # change only if Asyntai support asks you to
)
```

`script_url` can also come from the `ASYNTAI_SCRIPT_URL` environment variable.
Only an `https` address is accepted.

## How it works

Dash serves one HTML page for the whole app. The package puts a small script
just before the closing body tag of that page. The script waits for the page to
finish loading, then fetches the chat widget from Asyntai, so your app draws
first and its speed is unchanged.

The widget ID and the script address travel to the browser on a data
attribute, never inside the script. The package works with a custom
`index_string`, with a subclass that overrides `interpolate_index`, and with
`url_base_pathname`. It never adds the widget twice.

## Tests

```
pip install -e . pytest
pytest
```

## Support

hello@asyntai.com

## Licence

MIT. See [LICENSE](LICENSE).
