Skip to main content

Confluence

Compatibility

仅在 Node.js 上可用。

¥Only available on Node.js.

本教程介绍如何从 Confluence 空间的页面加载文档对象。

¥This covers how to load document objects from pages in a Confluence space.

凭证

¥Credentials

  • 你需要设置一个访问令牌,并将其与你的 Confluence 用户名一起提供,以便对请求进行身份验证。

    ¥You'll need to set up an access token and provide it along with your confluence username in order to authenticate the request

  • 你还需要包含要加载为文档的页面的空间的 space key。导航到你的空间时,可以在 URL 中找到它,例如: https://example.atlassian.net/wiki/spaces/{SPACE_KEY}

    ¥You'll also need the space key for the space containing the pages to load as documents. This can be found in the url when navigating to your space e.g. https://example.atlassian.net/wiki/spaces/{SPACE_KEY}

  • 你需要安装 html-to-text 才能将页面解析为纯文本。

    ¥And you'll need to install html-to-text to parse the pages into plain text

npm install @langchain/community @langchain/core html-to-text

用法

¥Usage

import { ConfluencePagesLoader } from "@langchain/community/document_loaders/web/confluence";

const username = process.env.CONFLUENCE_USERNAME;
const accessToken = process.env.CONFLUENCE_ACCESS_TOKEN;
const personalAccessToken = process.env.CONFLUENCE_PAT;

if (username && accessToken) {
const loader = new ConfluencePagesLoader({
baseUrl: "https://example.atlassian.net/wiki",
spaceKey: "~EXAMPLE362906de5d343d49dcdbae5dEXAMPLE",
username,
accessToken,
});

const documents = await loader.load();
console.log(documents);
} else if (personalAccessToken) {
const loader = new ConfluencePagesLoader({
baseUrl: "https://example.atlassian.net/wiki",
spaceKey: "~EXAMPLE362906de5d343d49dcdbae5dEXAMPLE",
personalAccessToken,
});
const documents = await loader.load();
console.log(documents);
} else {
console.log(
"You need either a username and access token, or a personal access token (PAT), to use this example."
);
}

API Reference: