Video #08 · 1:24

How to add a chatbot to React, Next.js, Vue or Angular

If your website is a React, Next.js, Vue or Angular app, Install has the code for each. For Next.js you add two lines to your layout. For the others you save one file and add one tag. There is nothing to install: the chat loads from Aparsoft's servers.

In the video

What you need

  • A website already added and read in Apar Chatbot
  • Your app's source code (React, Next.js, Vue 3 or Angular)

Step by step

  1. 1Pick your framework's tab

    Open Install. Under Where is your website built?, choose Something else, or my developer. Next to HTML/JavaScript there is a tab for React, Next.js, Vue and Angular. Each tab has the code with your website's key in it, and a short guide under it.

    The integration code tabs: HTML/JavaScript, React, Next.js, Vue.js and Angular
  2. 2React

    Save the code as its own file, src/AparsoftChatbot.jsx. Then import it in App.jsx and render <AparsoftChatbot /> once. It draws nothing itself: the chat button appears on every page of the app.

    The React tab: save it as src/AparsoftChatbot.jsx, then render it once in App.jsx
  3. 3Next.js

    Add the two marked lines to app/layout.js. The chat shows on every page.

    // app/layout.js: add the two marked lines. The chat then shows on every page.
    import Script from 'next/script'; // add this line
    
    export default function RootLayout({ children }) {
      return (
        <html lang="en">
          <body>
            {children}
            <Script
              src="https://www.aparsoft.com/static/chatbot-widget/widget.loader.js"
              strategy="afterInteractive"
              data-aparsoft-chatbot="true"
              data-api-key="YOUR_WEBSITE_KEY"
            /> {/* add this line */}
          </body>
        </html>
      );
    }
    The Next.js tab: save it in components, then add it to app/layout.js
  4. 4Vue

    Save the code as src/components/AparsoftChatbot.vue. Import it in App.vue and put <AparsoftChatbot /> once in its template. The file is written for Vue 3.

    The Vue.js tab: save it as src/components/AparsoftChatbot.vue, then add it to App.vue
  5. 5Angular

    Save the code as src/app/aparsoft-chatbot.component.ts. Add AparsoftChatbotComponent to your root component's imports, and <app-aparsoft-chatbot></app-aparsoft-chatbot> to its template. In an NgModule app, add it to the module's imports instead.

    The Angular tab: save it as src/app/aparsoft-chatbot.component.ts, then add it to the root component
  6. 6Nothing to install

    Each guide ends the same way: there is no package to add. The chat loads from Aparsoft's servers.

    The Angular guide's last step: nothing to install
  7. 7Open your app

    Here it is in a new Next.js app, saved and added just as the page says. The chat button is there, and it greets you.

    A new Next.js app with the chat open and greeting the visitor

Questions

Do I need to install an npm package?

No. The code loads the chat from Aparsoft's servers, so there is nothing to add to package.json.

Will it slow down my Next.js layout or make it a client component?

No. The chat loads after your page, and app/layout.js stays a server component.

Did you try these files in real apps?

Yes. Before filming, each file was saved and added as its guide says in a new app: Vite with React, Vite with Vue, Next.js with the App Router, and Angular. In each one the chat opened and greeted.

What about a plain HTML website, or WordPress?

On WordPress, search for "Apar Chatbot" in Plugins > Add New Plugin: Install has the steps. For plain HTML, choose Something else, or my developer.

Next guide

How to train a chatbot on your PDFs and documents