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

  • bun

  • pnpm

  • yarn

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 InkeepEmbeddedChat component file for our Embedded Chat 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 EmbeddedChat = dynamic(
  () => import('@inkeep/widgets').then((mod) => mod.InkeepEmbeddedChat),
  {
    ssr: false,
    // loading: () => <div>loading...</div>, // optional: loading animation component
  },
);

function InkeepEmbeddedChat() {
  const {
    baseSettings, aiChatSettings,
  } = useInkeepSettings();

  const embeddedChatProps = {
    baseSettings,
    aiChatSettings,
  };

  return <EmbeddedChat {...embeddedChatProps} />;
}

export default InkeepEmbeddedChat;

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

FAQ