跳到正文
DEV Community· Dahye Ahn·· 2 小時前AI 評分64

讓 AI 編碼智能體為網站加入聊天機械人的簡易方法

The easy way to let your AI coding agent add a chatbot to your website

AI 導讀

作者整理一套讓 AI 編碼智能體為網站加入聊天機械人的做法,涵蓋選擇服務、提供提示詞、把元件放入共用檔案及確認載入。文中比較指出,SiteGPT 可透過 CLI 或 HTTP 先取得限 7 日的預覽 token,但要保留仍需用戶登入;多數其他服務則要人手建立帳戶或複製嵌入程式碼。

正文

Works with Cursor, Claude Code, Lovable, Bolt and v0. Last checked: November 2026.

I build most of my side projects with Cursor and Claude Code now. The agent writes the pages, wires up the database, and deploys. Then I say "add a chatbot to the site," and things get clumsy. Either it stops and tells me to sign up somewhere, or it confidently pastes a widget with a made-up ID into the wrong file.

After doing this a few too many times, I settled on a routine that gets it right on the first try. Here it is, plus what I learned about which chatbot services let the agent do more of the work.

Disclosure up front: I'm building a chatbot service for exactly this, OneLineChat. It isn't live yet. Everything in the steps below works with services you can use today.

Step 1: Pick a chatbot your agent can actually finish

To put a working chatbot on a site, an agent needs three things:

  1. An account or workspace at the chatbot service
  2. A key or an embed snippet tied to that workspace
  3. The snippet placed in the right file of your project

Agents are good at step 3. Steps 1 and 2 are where a person usually has to open a browser. Here's how that looks for the services people usually recommend:

Service Can the agent get a working key without you opening a dashboard? What's still on you
SiteGPT Partly. An anonymous CLI or HTTP call returns a token for one chatbot, valid for a 7-day preview Claiming the bot with a magic link (and any payment step) to keep it. Their API tokens and MCP tools need the Growth plan
Chatbase No Copying the embed script from the dashboard. API keys are created there too, and API v2 starts at the Basic plan
Chat Data No An owner or admin creating a workspace key in the dashboard
tawk.to, Crisp, Tidio, Channel Talk No Signing up and copying the widget snippet
OneLineChat Yes, by design. One HTTP call with your email returns a public key and the snippet. Early access for now Just your email

SiteGPT is the only one I found where the agent can get something running before you touch anything:

npm install -g @sitegpt/cli
sitegpt onboarding start https://example.com --json

That returns a workspace ID, a chatbot ID, an API token, and an onboarding URL. There's also a plain HTTP version (POST https://sitegpt.ai/agent/auth with your websiteUrl). The token only covers that one chatbot, and the preview expires after seven days. To keep it, you open the onboarding URL and sign in. Their own auth docs say clicking the magic link and any payment step "remain the human's."

OneLineChat (mine, see the disclosure above) is built around the same idea, taken one step further. There's no CLI to install and no account to claim. The agent sends one request with your email:

curl -sS -X POST https://onelinechat.com/api/v1/keys \
  -H "Content-Type: application/json" \
  -d '{"email":"you@example.com","site":"https://your-site.com","agent":"claude-code"}'

Once it launches, that call returns a public key and a one-line snippet. localhost and preview domains work without an allowlist, and the first 100 conversations are free with no card on file. Today it's early access only.

Chatbase has a good API, but the key comes from Workspace settings → API keys. Their CLI can log in with chatbase auth login --browser, where you approve a short code at chatbase.co/activate. You don't need an API key just to show the chat bubble, though. The embed script is under Channels → Chat Bubble → Deploy.

tawk.to, Crisp, Tidio and Channel Talk are the classic live-chat widgets. Several have free tiers, and they've been around for years. You sign up and copy a snippet. That's one minute of your time, and the agent can do everything after it.

So for most people the realistic answer is: you spend one minute getting the snippet, and the agent does the rest. The next steps are about making "the rest" go right.

Step 2: Hand the snippet over with a clear prompt

Most mistakes come from a vague request. This is the prompt I use now:

Add this chat widget to my site. Put it in the root layout so it shows on every page, add it only once, and don't change anything else. Use the snippet exactly as given and don't make up any IDs. Here's the snippet from tawk.to:
<paste the snippet>

Two rules worth spelling out to the agent:

  • Widget IDs and public keys are fine in client code. Inline them; no environment variable needed.
  • API secrets are not. If anything in the snippet is called a secret, it must never go into index.html or a NEXT_PUBLIC_ / VITE_ variable.

Step 3: Make sure it lands in the right file

This is where agents slip most often. Usually they put the widget in a single page, so it disappears when you navigate. Here's where it should go:

Project File
Next.js App Router (also v0) app/layout.tsx, with next/script inside <body> after {children}
Next.js Pages Router pages/_app.tsx, with next/script after <Component {...pageProps} />
Vite: React, Vue, Svelte (most Lovable and Bolt projects) the root index.html, just before </body>
Plain HTML every page, or the shared footer
WordPress the vendor's plugin, or the Footer box of a header/footer code plugin
Webflow Site settings → Custom code → Footer code (needs a paid site plan)

For Next.js, one detail trips agents up. tawk.to and Crisp give you inline JavaScript, not a src URL, and an inline next/script needs an id:

// app/layout.tsx
import Script from 'next/script';

export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <html lang="en">
      <body>
        {children}
        <Script id="chat-widget" strategy="lazyOnload">
          {`/* the JavaScript from inside the vendor's <script> tag */`}
        </Script>
      </body>
    </html>
  );
}

If you're working in Lovable, Bolt or v0 chat rather than an editor, the same prompt from Step 2 works. Just mention the file: "index.html, before the closing body tag" for Lovable and Bolt, or "app/layout.tsx with next/script" for v0.

Step 4: Check that it actually loads

Ask the agent to verify, or do it yourself in two minutes:

  1. Open the site (dev server or preview URL), then DevTools → Network. The vendor's script should return 200.
  2. Check the Console for "Refused to load" errors. Those mean your Content-Security-Policy blocks the widget. Add the vendor's domains to script-src and connect-src (live chat often needs wss: too), plus img-src, style-src or frame-src as their docs say.
  3. Navigate to another page. The bubble should still be there, and only once.
  4. Works in production but not in preview, or the other way round? Some vendors only load on domains you list in their dashboard. Add localhost and your preview domain (*.vercel.app, *.lovable.app, ...).
  5. Still nothing? Try a clean browser profile. Ad blockers hide a lot of chat widgets.

Optional: teach your agent once

I got tired of repeating all of this, so I wrote it down as a small, free, vendor-neutral skill for Claude Code and rule for Cursor: add-website-chatbot on GitHub. With it installed, "add my tawk.to widget" is enough. It finds the right file, checks for a CSP, and won't invent IDs. It doesn't depend on my product.

Why there's still a human step, and what I'd like instead

I understand why most services keep a person in the loop. If any script can create accounts, you get spam and abuse, and someone has to own the billing. A magic link is a cheap way to know a real person is there.

What I'd like as a developer is something in between:

  • The agent requests a key with the email address I gave it.
  • The widget works right away on localhost and preview domains, so the agent can test it end to end.
  • I confirm with one click when I'm ready to go live, and nothing is charged until then.

SiteGPT's preview flow is close to that, and it's exactly the flow I'm building OneLineChat around. If you'd use it, you can join early access here, or have your agent send the request above with your email. Either way you'll hear from me when keys go out. And if you think the human step should stay, I'd honestly like to hear why in the comments.

How I checked

I read each vendor's own docs and pricing pages in late November 2026. I didn't test paid plans.

These products change fast. If something here is out of date, tell me and I'll fix it.

來源:DEV Community · dev.to