DEV Community

hayerhans
hayerhans

Posted on

5

๐Ÿค– How to Integrate BotPress Bot into Next.js 13 | ๐Ÿš€ Step-by-Step Guide!

Image description

๐Ÿ• Get the code here:

https://github.com/XamHans/botpress-nextjs

โ›” Make sure that your bot is deployed!

๐Ÿ“น Video Tutorial:
https://www.youtube.com/watch?v=zUTFqEeA0NI&ab_channel=HayerHans

๐Ÿ“š Key Steps Covered:

  • ๐Ÿ”— Clone the repo with: git clone https://github.com/XamHans/botpress-nextjs.git

  • ๐Ÿ“ cd into the folder and install the dependencies with yarn install

  • ๐Ÿ’ป start the application with yarn dev

  • ๐Ÿ“ get the Botpress Webchat Snippet from botpress website

Image description

  • ๐Ÿงฉ Navigate to the layout.tsx file. In the head section use the Script Component to init botpress

Image description



<Script
          src="https://cdn.botpress.cloud/webchat/v0/inject.js"
          onLoad={() => {
            initBotpress();
          }}
        />


Enter fullscreen mode Exit fullscreen mode



const initBotpress = () => {
    window.botpressWebChat.init({
      composerPlaceholder: "Chat with bot",
      botConversationDescription:
        "This chatbot was built surprisingly fast with Botpress",
      botId: "<YOUR_BOT_ID>",
      hostUrl: "<YOUR_BOT_HOST_URL>",
      messagingUrl: "https://messaging.botpress.cloud",
      clientId: "<YOUR_CLIENT_ID>",
    });
  };


Enter fullscreen mode Exit fullscreen mode
  • ๐Ÿ› ๏ธ make sure that you type on top of the layout.tsx "use client" to make it a client component.

Image description

You have successfully integrated your bot into your next.js 13 app! ๐ŸŽ‰

Top comments (1)

Collapse
 
fosteman profile image
Timothy Fosteman โ€ข

Dude, this is a custom integration that needs to be done: botpress.com/docs/building-a-custo...

nextjs tutorial video

Youtube Tutorial Series ๐Ÿ“บ

So you built a Next.js app, but you need a clear view of the entire operation flow to be able to identify performance bottlenecks before you launch. But how do you get started? Get the essentials on tracing for Next.js from @nikolovlazar in this video series ๐Ÿ‘€

Watch the Youtube series