Skip to main content

Ask AI chatbot widget for Next.js

Add an AI chatbot or AI search widget to your Next.js site.

Prerequisites

  • A Biel.ai account. If you don't have one, sign up for free.
  • A project created in your Biel.ai dashboard. Follow the Quickstart guide to create one.
  • A Next.js application ready to install Biel.ai.
  • Node.js installed.

Add the chatbot widget

Chatbot widget for docs

  1. Install the Biel.ai package:

    npm install biel-react
    info

    If you're using yarn as your package manager, run yarn add biel-react instead of the npm command above.

  2. Create a wrapper for the chatbot by creating a file at components/biel-search.tsx:

    import React, { useEffect } from 'react';
    import { BielButton } from 'biel-react';
    import { JSX, defineCustomElements } from 'biel-search/loader';
    import { StyleReactProps } from 'biel-react/dist/types/react-component-lib/interfaces';
    import 'biel-search/dist/biel-search/biel-search.css';

    const DynamicBielButtonComponent = (props: React.JSX.IntrinsicAttributes & JSX.BielButton & Omit<React.HTMLAttributes<HTMLBielButtonElement>, "style"> & StyleReactProps & React.RefAttributes<HTMLBielButtonElement>) => {
    useEffect(() => {
    defineCustomElements(window);
    }, []);

    return <BielButton {...props} />;
    };

    export default DynamicBielButtonComponent;
  3. In the component where you wish to display the chatbot (often pages/_app.tsx or app/layout.tsx), include it as shown below:

    'use client'
    import dynamic from 'next/dynamic';

    export default function Banner() {

    const DynamicBielButton = dynamic(() => import('@/components/biel-search'), {
    ssr: false,
    });

    return (
    <div className="App">
    {/* Other components and content */}
    <DynamicBielButton
    project="<YOUR_PROJECT_ID>"
    header-title="Biel.ai chatbot"
    button-position="bottom-right"
    modal-position="bottom-right"
    button-style="dark">
    Ask AI
    </DynamicBielButton>
    </div>
    );
    }

    Replace <YOUR_PROJECT_ID> with your project's ID from the Biel.ai dashboard.

  4. Start your Next.js app by running npm start or yarn start in your terminal. Once it compiles successfully, verify that the chatbot appears and functions correctly on your site.

Next steps