What is Next.js

Next.js is a React framework that provides tools for building web applications with server-side rendering and static generation.

Install the component library

npm install @inkeep/widgets

Customize your settings

Create a useInkeepSettings.ts file that will contain a hook that will return the configuration for Inkeep component(s).

const useInkeepSettings = () => {
  const baseSettings = {
    apiKey: process.env.INKEEP_INTEGRATION_API_KEY!,
    integrationId: process.env.INKEEP_INTEGRATION_ID!,
    organizationId: process.env.INKEEP_ORGANIZATION_ID!,
    primaryBrandColor: "#26D6FF", // your brand color, widget color scheme is derived from this
    organizationDisplayName: "Inkeep",
    // ...optional settings
  };

  const modalSettings = {
    // optional settings
  };

  const searchSettings = {
    // optional settings
  };

  const aiChatSettings = {
    // optional settings
    botAvatarSrcUrl: "/img/logo.svg", // use your own bot avatar
    quickQuestions: [
      "Example question 1?",
      "Example question 2?",
      "Example question 3?",
    ],
  };

  return { baseSettings, aiChatSettings, searchSettings, modalSettings };
};

export default useInkeepSettings;

Make sure to add your Inkeep identifiers to your environment settings. An example next.config.js file is below.

next.config.js
/** @type {import('next').NextConfig} */
const nextConfig = {
  env: {
    INKEEP_INTEGRATION_API_KEY: process.env.INKEEP_INTEGRATION_API_KEY,
    INKEEP_INTEGRATION_ID: process.env.INKEEP_INTEGRATION_ID,
    INKEEP_ORGANIZATION_ID: process.env.INKEEP_ORGANIZATION_ID,
  },
};

module.exports = nextConfig;

You can alternatively use the NEXT_PUBLIC_ prefix in your environment variables to access them without a next.config.js file.

Define the component

Next, create an InkeepChatButton file for our Chat Button component.

For Next.js apps that use the App router, use the use client directive at the top of the file to load the widget on the client side.

import dynamic from 'next/dynamic';
import useInkeepSettings from '../utils/useInkeepSettings';

const ChatButton = dynamic(
  () => import('@inkeep/widgets').then((mod) => mod.InkeepChatButton),
  {
    ssr: false,
  },
);

function InkeepChatButton() {
  const {
    baseSettings, aiChatSettings, searchSettings, modalSettings,
  } = useInkeepSettings();

  const chatButtonProps = {
    baseSettings,
    aiChatSettings,
    searchSettings,
    modalSettings,
  };

  return <ChatButton {...chatButtonProps} />;
}

export default InkeepChatButton;

For a full list of customizations, check out the Chat Button documentation.

FAQ