Add your agent to an app on Vercel
Add the Askocto chat widget to a web app deployed on Vercel: load the embed script in your layout and keep the agent ID in an environment variable.
Working draft. These docs are illustrative: names, endpoints and examples describe the intended behaviour and can change before launch.
Use this page when your web app is deployed on Vercel and you want the agent's chat bubble in it. You load the embed script once in your app's root layout and keep the agent ID in an environment variable, so each environment can use its own agent.
Before you start
- An agent with the Website widget turned on. See Channels.
- Access to your app's code and your Vercel project's settings.
- The agent ID, shown in Channels > Website widget > Install.
Store the agent ID
- In your Vercel project, open the environment variables settings.
- Add
NEXT_PUBLIC_OCTO_AGENT_IDwith the valueagt_123, using your own ID. - Choose the environments it applies to, such as Preview and Production.
Use a separate test agent for Preview if you do not want test chats mixed with real ones.
Load the script
In a Next.js app, add the script to the root layout.
import Script from "next/script";
export default function RootLayout({ children }) {
return (
<html lang="en">
<body>
{children}
<Script
src="https://cdn.askocto.co/embed.js"
data-agent-id={process.env.NEXT_PUBLIC_OCTO_AGENT_ID}
strategy="afterInteractive"
/>
</body>
</html>
);
}
In any other framework, add the plain embed script to the HTML shell.
<script src="https://cdn.askocto.co/embed.js" data-agent-id="agt_123" defer></script>
Deploy the change. You should see the chat bubble on the deployed app.
Recognize signed-in users
Call identify after sign-in, with a userHash that your server signs with the agent's identity secret. Keep that secret in a server-only environment variable, without the NEXT_PUBLIC_ prefix. See Identity verification.
Warning: Any variable that starts with
NEXT_PUBLIC_is sent to the browser. Never put the identity secret or an API key in one.
Test it
- Open a Preview deployment and ask a question.
- Compare with the same question in Test > Playground. See Playground.
- Check that production uses the production agent.
Troubleshooting
- No bubble appears. Check that the variable is set for that environment and that you redeployed after adding it.
- The bubble loads the wrong agent. Compare the variable with the agent ID for that environment.
- Content security errors in the console. Allow the script source
https://cdn.askocto.coin your app's content security policy.