集成
将 Jamdesk 文档搜索 API 连接到 Intercom、Zendesk、Slack 和自定义聊天机器人。每种集成均有分步指南。
本指南介绍如何将文档搜索 API 连接到常用工具:Intercom、Zendesk、Slack 和自定义聊天机器人。
Intercom(Fin AI Agent)
Intercom 的 Fin AI 代理支持数据连接器:Fin 会与你的 Intercom 文章一同查询的外部搜索源。连接文档搜索 API,即可让 Fin 基于你的 Jamdesk 文档回答问题。
在 Jamdesk 控制台中,前往 Project Settings → API Keys,点击 Generate Key。将其命名为 "Intercom Fin",并复制 jd_live_ 密钥(共 40 个字符)。
在 Intercom 中,前往 AI Agent → Data Sources → Add Source → API。
输入以下信息:
| 字段 | 值 |
|---|---|
| Endpoint URL | https://your-project.jamdesk.app/_api/search |
| Method | POST |
| Auth header | Authorization: Bearer jd_live_c83003a54ae0a83123454c3f7ec82f0a |
| Query field | query |
| Result path | results[*].content |
使用 Intercom 内置的测试工具发送示例查询。确认 Fin 能返回你文档中的相关段落。
在 Fin 配置中开启数据连接器。此后 Fin 在回答客户问题时会引用你的文档。
Fin 会参考 score 字段。得分较高的结果会优先出现在其回答中。得分低于 0.7 的段落通常不会被使用。
Zendesk(MCP 服务器)
Zendesk 的 AI 功能支持将 MCP 服务器作为知识来源。通过 Jamdesk 内置的 MCP 服务器,将你的文档连接到 Zendesk 的 AI 代理。无需编写自定义代码。
你的 MCP 服务器位于 https://your-project.jamdesk.app/_jd/mcp。MCP 服务器无需 API 密钥,它使用你项目的公开文档。
在 Zendesk 管理中心,前往 AI Agents → Knowledge Sources → Add MCP Server。
粘贴你的 MCP 服务器 URL:https://your-project.jamdesk.app/_jd/mcp
Zendesk 会列出可用工具(searchDocs、getPage)。确认它们已出现后保存。
MCP 服务器与文档搜索 API 使用相同的搜索索引。当你需要认证访问、按密钥限速或吊销控制时,请使用文档搜索 API(配合 jd_live_ 密钥)。
自定义聊天机器人
使用标准的 fetch 调用,即可为任何聊天机器人或 Web 应用添加文档搜索功能。已启用 CORS,浏览器端客户端可直接调用 API,无需后端代理。
async function searchDocs(query) {
const response = await fetch(
"https://your-project.jamdesk.app/_api/search",
{
method: "POST",
headers: {
"Authorization": "Bearer jd_live_c83003a54ae0a83123454c3f7ec82f0a",
"Content-Type": "application/json",
},
body: JSON.stringify({ query, limit: 5 }),
}
);
if (!response.ok) {
const { error } = await response.json();
throw new Error(error);
}
const data = await response.json();
return data.results;
}
// Example usage
const results = await searchDocs("How do I configure a custom domain?");
results.forEach((result) => {
console.log(`[${result.score.toFixed(2)}] ${result.title}`);
console.log(result.content);
console.log(result.url);
console.log("---");
});
构建 AI 代理工具
将搜索结果作为上下文传递给语言模型,以生成有依据的回答:
import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic();
async function answerFromDocs(userQuestion) {
// 1. Search your docs
const results = await searchDocs(userQuestion);
const context = results
.map((r) => `[${r.title}](${r.url})\n${r.content}`)
.join("\n\n---\n\n");
// 2. Pass context to Claude
const message = await client.messages.create({
model: "claude-sonnet-4-5-20241022",
max_tokens: 1024,
messages: [
{
role: "user",
content: `Answer the following question using only the provided documentation excerpts.
If the answer isn't in the docs, say so.
Documentation:
${context}
Question: ${userQuestion}`,
},
],
});
return message.content[0].text;
}
Slack 机器人
构建一个 /docs Slack 斜杠命令,用于搜索你的文档并将结果发布到任意频道。
import { App } from "@slack/bolt";
const app = new App({
token: process.env.SLACK_BOT_TOKEN,
signingSecret: process.env.SLACK_SIGNING_SECRET,
});
app.command("/docs", async ({ command, ack, respond }) => {
await ack();
const query = command.text.trim();
if (!query) {
await respond("Usage: `/docs <your question>`");
return;
}
try {
const response = await fetch(
"https://your-project.jamdesk.app/_api/search",
{
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.JAMDESK_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({ query, limit: 3 }),
}
);
const data = await response.json();
if (data.results.length === 0) {
await respond(`No results found for: _${query}_`);
return;
}
const blocks = [
{
type: "section",
text: {
type: "mrkdwn",
text: `*Results for:* _${query}_`,
},
},
{ type: "divider" },
...data.results.flatMap((result) => [
{
type: "section",
text: {
type: "mrkdwn",
text: `*<${result.url}|${result.title}>*\n${result.content}`,
},
},
{ type: "divider" },
]),
];
await respond({ blocks });
} catch (err) {
await respond(`Error searching docs: ${err.message}`);
}
});
(async () => {
await app.start(process.env.PORT || 3000);
console.log("Slack bot is running");
})();
在 Slack 应用的环境变量中设置 JAMDESK_API_KEY。切勿将密钥硬编码在代码中。
子路径托管(Cloudflare Worker)
如果你使用子路径托管,将文档部署在你域名的某个路径下(默认为 /docs,或自定义子路径如 /help),则也需要通过 Cloudflare Worker 代理 /_api 路由。
在你的 Worker 中,将 /_api 添加到 PROXY_PATHS 数组,并使用你在控制台中配置的路径前缀:
const PROXY_PATHS = [
"/docs", // or your custom subpath, e.g. "/help"
"/_jd",
"/_api", // Add this line
];
此后,发往 yoursite.com/_api/search(或自定义子路径下的 yoursite.com/help/_api/search)的搜索请求将转发到你的 Jamdesk 文档站点。
无论请求如何路由,/_api 路由都需要使用你的 jd_live_ API 密钥进行认证。通过 Cloudflare 代理不会绕过认证。
