Back to Dashboard

Documentation

Learn how to use Asyntai

aiohttp Package

Add the Asyntai AI chat assistant to your aiohttp site

Create Account

Overview

aiohttp is an asynchronous Python web framework. The Asyntai package is a small middleware. Install it, add one line with your widget ID, and the chat bubble is on every HTML page of your site. You edit no template.

The assistant answers your visitors from your own content, in more than 80 languages, day and night.

Requirements

  • Python 3.9 or later
  • aiohttp 3.8 or later
  • An Asyntai account. The Free plan is enough to try the widget

Installation

Follow these steps to add Asyntai to your site:

1

Get Your Widget ID

Sign in to Asyntai and open the Install page. The widget ID is the value of data-asyntai-id in the snippet shown there. It starts with asyntai_.

2

Install the Package

pip install aiohttp-ai-chatbot
3

Add the Middleware

from aiohttp import web
from aiohttp_ai_chatbot import setup

app = web.Application()
app.router.add_get("/", index)
setup(app, widget_id="asyntai_1a2b3c4d5e6f")

web.run_app(app)

If you build the middleware list yourself, use this instead:

from aiohttp_ai_chatbot import asyntai_middleware

app = web.Application(middlewares=[asyntai_middleware("asyntai_1a2b3c4d5e6f")])

You can paste the whole snippet from the Install page. The package keeps only the ID.

4

Open Your Site

Restart the server and open any page. The chat bubble is in the corner of every HTML page.

Options

OptionDefaultWhat it does
widget_idthe ASYNTAI_WIDGET_ID environment variableYour Asyntai widget ID. An empty value switches the chat off
skip_paths["/admin*"]Paths where the chat never shows. A path that ends in * also covers everything below it
script_urlthe Asyntai CDNAdvanced. Change it only if Asyntai support asks you to

Leave out widget_id to keep the ID in an environment variable. It is read on every request:

setup(app)   # reads ASYNTAI_WIDGET_ID

Placing the Widget by Hand

If you use aiohttp-jinja2 and prefer to choose where the widget goes, register the helper once:

import aiohttp_jinja2
from aiohttp_ai_chatbot import asyntai_widget

env = aiohttp_jinja2.setup(app, loader=...)
env.globals["asyntai_widget"] = asyntai_widget

Then put it just before </body> in your base template:

{{ asyntai_widget() }}
</body>

The helper and the middleware never both add the widget, so it is safe to keep both.

How It Works

The middleware adds a small loader to every HTML page, just before </body>. The loader waits for the page's load event, so your own content always renders first.

The middleware changes complete HTML responses with status 200. It leaves alone JSON and other non-HTML responses, error pages, redirects, websockets, responses that you stream yourself, and pages that already have the widget. Pages that use enable_compression() get the widget too, because aiohttp compresses them after the middleware.

Tip: For plain HTML files that you serve with add_static, paste the widget snippet from the Install page into the files.

Answering From Your Content

Asyntai reads your published pages. Add your site URL in the dashboard, and the assistant answers from the same pages the widget sits on. You can also add documents, and question and answer pairs.

Removing It

Remove the setup() line, or clear the widget ID, and restart the server. The chat bubble is gone.

Plans & Pricing

The package is free. View pricing.

Need Help?

If you have any questions or run into issues, contact us at [email protected].