How to add an AI chatbot to Astro

On Astro, a chat widget is installed through src/layouts/Layout.astro, before </body>. Applies on your next build and deploy. None.

Where it goes

src/layouts/Layout.astro, before </body>

Availability: None.

Adding the chatbot to Astro

  1. 1

    Open your base layout, usually src/layouts/Layout.astro.

  2. 2

    Paste the snippet immediately before the closing </body> tag.

  3. 3

    Astro leaves plain script tags with a src attribute alone, so no directive is needed.

  4. 4

    Rebuild and deploy.

  5. 5

    Applies on your next build and deploy.

The snippet you paste

<script src="https://rubyrep.com/rubyrep.js" data-rubyrep="rr_your_public_key" defer></script>

Your own key replaces rr_your_public_key — you get it after training RubyRep on your site.

Worth knowing on Astro

  • Astro processes some script tags at build time; an external src with defer is passed through untouched, which is what you want.

  • If you use View Transitions, the widget should mount once — listen for astro:page-load only if it needs re-initialising.

Astro questions

Where does the code go on Astro?
src/layouts/Layout.astro, before </body>. Applies on your next build and deploy.
Do I need a paid Astro plan?
None.
Will a Astro update remove it?
Astro processes some script tags at build time; an external src with defer is passed through untouched, which is what you want.
Does it slow Astro down?
No measurable effect. The snippet is deferred, so it loads after your page has rendered, and the chat interface itself is only fetched when a visitor opens it.

Related

Get your snippet.

Enter your Astro site and RubyRep reads it, builds your representative, and hands you the exact line to paste.

https://

Takes about a minute. No credit card.

Using something else? See all platforms.