FastComments.com

FastComments API

FastComments 提供用于与多个资源交互的 API。可与我们的平台构建集成,或构建您自己的客户端!

在本文档中,您将找到 API 支持的所有资源的文档及其请求和响应类型。

对于企业客户,所有 API 访问都会记录在审核日志中。

生成的 SDK

FastComments 现在从我们的代码生成了一个 API 规范(尚未完成,但包含许多 API)。

我们现在还为流行语言提供 SDK:

身份验证

API 的身份验证通过将您的 API 密钥 作为 X-API-KEY 请求头或 API_KEY 查询参数传递来完成。您在调用 API 时还需要 tenantId。可以从与您的 api key 相同的页面检索到它。

安全提示

这些路由应从 服务器 调用。 切勿 从浏览器调用它们。这样会暴露您的 API 密钥——任何能查看页面源代码的人都将获得对您帐户的完全访问权限!

身份验证选项一 - 请求头

  • 请求头: X-API-KEY
  • 请求头: X-TENANT-ID

身份验证选项二 - 查询参数

  • 查询参数: API_KEY
  • 查询参数: tenantId

审计日志结构 Internal Link


一个 AuditLog 对象表示为具有此功能访问权限的租户审计的事件。

AuditLog 对象的结构如下:

AuditLog 结构
Copy Copy
1
2interface AuditLog {
3 id: string;
4 userId?: string;
5 username?: string;
6 resourceName: string;
7 crudType: 'c' | 'r' | 'u' | 'd' | 'login';
8 from: string;
9 url?: string;
10 ip?: string;
11 when: string;
12 description?: string;
13 serverStartDate: string;
14 objectDetails?: object;
15}
16

审计日志是不可变的。它也不能手动写入。FastComments.com 只能决定何时写入审计日志。不过,您可以通过此 API 读取它。

审计日志中的事件在两年后过期。


评论结构 Internal Link

一个 Comment 对象表示用户留下的一条评论。

父评论与子评论之间的关系通过 parentId 定义。

Comment 对象的结构如下:

评论结构
Copy Copy
1
2interface Comment {
3 /** 只读:如果反垃圾引擎判定该评论为垃圾,则设置为 true。 **/
4 aiDeterminedSpam?: boolean
5 /** 评论是否被批准显示。保存评论时设置为 true,否则将被隐藏。 **/
6 approved?: boolean
7 /** 用户的头像。 **/
8 avatarSrc?: string
9 /** 子评论。并非在所有场景中都会填充。用于通过 API 将 asTree 设置为 true 时。 **/
10 children: Comment[]
11 /** 评论者的原始评论。 **/
12 comment: string
13 /** 只读:将评论者的评论解析为 HTML。 **/
14 commentHTML?: string
15 /** 评论者的邮箱。如果关闭匿名评论,则为必填。 **/
16 commenterEmail?: string
17 /** 评论者的链接(例如,他们的博客)。 **/
18 commenterLink?: string
19 /** 评论者的姓名。始终必填。如果不可用,请设置为类似“匿名”的值。 **/
20 commenterName: string
21 /** 评论留存的日期,UTC 纪元时间。 **/
22 date: number
23 /** 评论的“显示标签”——例如 “Admin”、“Moderator” 或类似 “VIP User”。 **/
24 displayLabel?: string
25 /** 发布该评论的域名。 **/
26 domain?: string
27 /** 只读:该评论被举报的次数。 **/
28 flagCount?: number
29 /** 评论中成功解析的 #hashtags。你也可以手动添加标签以便查询,但它们不会自动在评论文本中显示。 **/
30 hashTags?: CommentHashTag[]
31 /** 只读:评论是否包含图片? **/
32 hasImages?: boolean
33 /** 只读:评论是否包含链接? **/
34 hasLinks?: boolean
35 /** 只读:唯一评论 ID。 **/
36 id: string
37 /** 仅在创建时使用!此项会被哈希后存储。 **/
38 ip?: string
39 /** 只读:当前用户是否屏蔽了撰写此评论的用户? **/
40 isBlocked?: boolean
41 /** 只读:该评论是否由管理员发布?基于 userId 自动设置。 **/
42 isByAdmin?: boolean
43 /** 只读:该评论是否由版主发布?基于 userId 自动设置。 **/
44 isByModerator?: boolean
45 /** 如果评论被软删除(由于其他配置必须保留占位符),则设置为 true。 **/
46 isDeleted?: boolean
47 /** 如果用户账户被删除且必须保留该评论,则设置为 true。 **/
48 isDeletedUser?: boolean
49 /** 只读:当前登录用户(contextUserId)是否已举报该评论? **/
50 isFlagged?: boolean
51 /** 该评论是否被置顶? **/
52 isPinned?: boolean
53 /** 该评论是否锁定以禁止新回复(版主仍可回复)? **/
54 isLocked?: boolean
55 /** 该评论是否为垃圾评论? **/
56 isSpam?: boolean
57 /** 只读:当前用户(contextUserId)是否对该评论点踩? **/
58 isVotedDown?: boolean
59 /** 只读:当前用户(contextUserId)是否对该评论点赞? **/
60 isVotedUp?: boolean
61 /** 评论使用的语言环境。如果未提供,将从 HTTP 的 Accept-Language 头部推断。 **/
62 locale?: 'de_de' | 'en_us' | 'es_es' | 'fr_fr' | 'it_it' | 'ja_jp' | 'ko_kr' | 'pl_pl' | 'pt_br' | 'ru_ru' | 'tr_tr' | 'zh_cn' | 'zh_tw'
63 /** 只读:评论中成功解析的 @提及 列表。 **/
64 mentions?: CommentUserMention[]
65 /** 可选的与评论关联的元数据。 **/
66 meta?: Record<string, string | number | boolean>
67 /** 与此评论关联的可选版务组 ID 列表。 **/
68 moderationGroupIds?: string[]|null
69 /** 只读:对应当前用户(contextUserId)对该评论的投票对象的 ID。 **/
70 myVoteId?: string
71 /** 是否已向评论者发送针对该评论的通知。为防止在导入时发送通知,请将其设置为 true。 **/
72 notificationSentForParent?: boolean
73 /** 是否已向租户用户发送针对该评论的通知。为防止在导入时发送通知,请将其设置为 true。 **/
74 notificationSentForParentTenant?: boolean
75 /** 此评论所在页面的标题。 **/
76 pageTitle?: string
77 /** 如果我们在回复某条评论,则这是我们回复的评论的 ID。 **/
78 parentId?: string|null
79 /** 评论是否被标记为已审核。 **/
80 reviewed: boolean
81 /** 评论所属的租户 ID。 **/
82 tenantId: string
83 /** 撰写该评论的用户。当使用姓名/邮箱保存评论时会自动创建。 **/
84 userId?: string|null
85 /** 该评论可见位置的 URL,例如一篇博文的链接。 **/
86 url: string
87 /** 你提供的 urlId 的“清理”版本。保存时你会指定此字段,但当你取回评论时,该字段会被“清理”,你原始的值会移动到 urlIdRaw。 **/
88 urlId: string
89 /** 只读:你传递的原始 urlId。 **/
90 urlIdRaw?: string
91 /** 用户和该评论是否已验证? **/
92 verified: boolean
93 /** 点赞数量。 **/
94 votesUp?: number
95 /** 点踩数量。 **/
96 votesDown?: number
97 /** 评论的“声望”(= 点赞数 - 点踩数)。 **/
98 votes?: number
99}
100

其中一些字段标注为 READONLY —— 这些字段由 API 返回,但无法设置。

评论文本结构

评论采用 FastComments 风格的 markdown 编写,即在普通 markdown 基础上增加了传统的 bbcode 样式图片标签,例如 [img]path[/img]

文本存储在两个字段中。用户输入的文本未作修改地保存在 comment 字段中。渲染后的结果则存储在 commentHTML 字段中。

允许的 HTML 标签有 b, u, i, strike, pre, span, code, img, a, strong, ul, ol, li, and br

建议渲染该 HTML,因为它只是 HTML 的一个很小的子集,构建渲染器相对简单。例如,有多个用于 React Native 和 Flutter 的库可以提供帮助

你也可以选择渲染 comment 字段的未规范化值。示例解析器在这里。

示例解析器也可以调整以处理 HTML,并将 HTML 标签转换为适合你平台渲染的元素。

提及

当用户在评论中被提及时,信息会存储在名为 mentions 的列表中。该列表中的每个对象具有以下结构。

评论提及对象
Copy CopyRun External Link
1
2interface CommentUserMention {
3 /** 用户 ID。对于 SSO 用户,会在前面加上你的租户 ID 前缀。 **/
4 id: string
5 /** 最终的 @ 提及 标签文本,包括 @ 符号。 **/
6 tag: string
7 /** 原始的 @ 提及 标签文本,包括 @ 符号。 **/
8 rawTag: string
9 /** 被提及的用户类型。user = FastComments.com 帐户。sso = SSO 用户。 **/
10 type: 'user'|'sso'
11 /** 即使用户选择不接收通知,该字段仍会被设置为 true。 **/
12 sent: boolean
13}
14

话题标签

当使用的 hashtag 被成功解析时,信息会存储在名为 hashTags 的列表中。该列表中的每个对象具有以下结构。如果设置了 retain,也可以将话题标签手动添加到评论的 hashTags 数组中以便查询。

评论话题标签对象
Copy CopyRun External Link
1
2interface CommentHashTag {
3 /** 话题标签 ID。 **/
4 id: string
5 /** 最终的 #hashtag 标签文本,包括 # 符号。 **/
6 tag: string
7 /** 如果该话题标签关联了自定义 URL,则会定义此字段。 **/
8 url?: string
9 /** 指在更新评论时是否应保留该话题标签,即使它不出现在评论文本中。用于在不更改评论文本的情况下标记评论。 **/
10 retain?: boolean
11}
12

邮件模板结构 Internal Link

EmailTemplate 对象表示租户的自定义电子邮件模板的配置。

系统将通过以下方式选择要使用的电子邮件模板:

  • 其类型标识符,我们称之为 emailTemplateId。这些是常量。
  • domain。我们会首先尝试查找与相关对象(例如 Comment)关联的域的模板,如果未找到匹配项,则会尝试查找 domain 为 null 或 * 的模板。

EmailTemplate 对象的结构如下:

电子邮件模板结构
Copy Copy
1
2interface EmailTemplate {
3 id: string
4 tenantId: string
5 emailTemplateId: string
6 displayName: string
7 /** 只读 **/
8 createdAt: string
9 /** 只读 **/
10 updatedAt: string
11 /** 只读 **/
12 updatedByUserId: string
13 /** 模板应关联的域。 **/
14 domain?: string | '*' | null
15 /** 使用 EJS 语法的电子邮件模板内容。 **/
16 ejs: string
17 /** 针对每个受支持语言环境的覆盖翻译键到值的映射。 **/
18 translationOverridesByLocale: Record<string, Record<string, string>>
19 /** 表示模板渲染上下文的对象。 **/
20 testData: object
21}
22

注意

  • 您可以从 /definitions 端点获取有效的 emailTemplateId 值。
  • /definitions 端点还包含默认翻译和测试数据。
  • 如果结构或测试数据无效,模板将保存失败。

标签结构 Internal Link


一个 HashTag 对象表示用户可以留下的标签。HashTags 可用于链接到外部内容或 将相关评论联系在一起。

The structure for the HashTag object is as follows:

HashTag 结构
Copy Copy
1
2interface HashTag {
3 /** 应以 "#" 或所需的字符开头。 **/
4 tag: string
5 /** 可选的 URL,话题标签可以指向它。UI 在点击时不会按话题标签过滤评论,而是重定向到此 URL。 **/
6 url?: string
7 /** 只读 **/
8 createdAt: string
9}
10

Notes:

  • In some API endpoints you will see that the hashtag is used in the URL. Remember to URI-Encoded values. For example, # should instead be represented as %23.
  • Some of these fields are marked READONLY - these are returned by the API but cannot be set.

通知计数结构 Internal Link

NotificationCount 对象表示用户的未读通知计数和元数据。

如果没有未读通知,则不会为该用户生成 NotificationCount

NotificationCount 对象会自动创建,无法通过 API 创建。它们也会在一年后过期。

您可以通过删除用户的 NotificationCount 来清除其未读通知计数。

NotificationCount 对象的结构如下:

NotificationCount 结构
Copy Copy
1
2interface NotificationCount {
3 id: string // 用户 id
4 count: number
5 createdAt: string // 日期字符串
6 expireAt: string // 日期字符串
7}
8

通知结构 Internal Link

一个 Notification 对象表示针对用户的通知。

Notification 对象是自动创建的,无法通过 API 创建。它们在一年后会过期。 通知不能被删除。但可以更新将 viewed 设为 false,并且可以按 viewed 查询。

用户也可以通过将通知中的 optedOut 设置为 true 来选择不接收针对特定评论的通知。将其设置为 false 可以重新选择接收。

存在不同的通知类型 —— 请检查 relatedObjectTypetype

通知的创建方式非常灵活,可由多种情景触发(参见 NotificationType)。

截至目前,Notification 的存在并不意味着会或应该发送电子邮件。相反,通知用于通知提要和相关集成。

Notification 对象的结构如下:

Notification 对象结构
Copy Copy
1
2enum NotificationObjectType {
3 Comment = 0,
4 Profile = 1,
5 Tenant = 2
6}
7
8enum NotificationType {
9 /** 如果有人回复你。 **/
10 RepliedToMe = 0,
11 /** 如果有人在你评论的线程中的任何位置回复(即使是嵌套的子评论)。 **/
12 RepliedTransientChild = 1,
13 /** 如果你的评论被点赞。 **/
14 VotedMyComment = 2,
15 /** 如果在你订阅的页面根评论处有新的评论。 **/
16 SubscriptionReplyRoot = 3,
17 /** 如果有人在你的个人资料上评论。 **/
18 CommentedOnProfile = 4,
19 /** 如果你有私信。 **/
20 DirectMessage = 5,
21 /** TrialLimits 仅适用于租户用户。 **/
22 TrialLimits = 6,
23 /** 如果你被 @提及。 **/
24 Mentioned = 7
25}
26
27interface Notification {
28 id: string
29 tenantId: string
30 /** 使用 SSO 时,用户 id 的格式为 `<tenant id>:<user id>`。 **/
31 userId?: string
32 /** 在使用 SSO 时,你只需关心 `userId`。 **/
33 anonUserId?: string
34 /** urlId 几乎总是已定义。它仅在租户级通知(不常见)中为可选。 **/
35 urlId?: string
36 /** URL 被缓存以便快速导航到通知来源。 **/
37 url?: string
38 /** 页面标题被缓存以便快速查看通知来源。 **/
39 pageTitle?: string
40 relatedObjectType: NotificationObjectType
41 /** 例如,评论 id。 **/
42 relatedObjectId: string
43 viewed: boolean
44 createdAt: string // 日期字符串
45 type: NotificationType
46 fromCommentId?: string
47 fromVoteId?: string
48 /** fromUserName 和 fromUserAvatarSrc 在此处被缓存以便快速显示通知。用户更新时它们也会更新。 **/
49 fromUserName: string
50 fromUserId: string
51 fromUserAvatarSrc?: string
52 /** 将此设置为 true 以停止接收该对象的通知。 **/
53 optedOut?: boolean
54}
55

页面结构 Internal Link

A Page 对象表示许多评论可能属于的页面。此关系由 urlId 定义。

A Page 存储信息,例如页面标题、评论计数和 urlId

Page 对象的结构如下:

页面结构
Copy Copy
1
2interface Page {
3 id: string
4 urlId: string
5 url: string
6 title?: string
7 createdAt: string
8 commentCount: number
9 rootCommentCount: number
10 /** 将此设置为 null 意味着所有 SSO 用户都可以看到该页面。空列表表示对所有用户关闭。 **/
11 accessibleByGroupIds?: string[] | null
12 /** 此页面是否关闭以添加新评论? **/
13 isClosed?: boolean
14}
15

待处理 Webhook 事件结构 Internal Link

一个 PendingWebhookEvent 对象表示一个处于排队等待中的 webhook 事件。

PendingWebhookEvent 对象会自动创建,不能通过 API 手动创建。它们也会在一年后过期。 可以删除它们,从而将任务从队列中移除。

存在不同的事件类型 —— 请检查 eventType (OutboundSyncEventType) 和 type (OutboundSyncType)。

此 API 的一个常见用例是实现自定义监控。你可能希望定期调用 /count 端点,以轮询给定筛选器下的未完成数量。

PendingWebhookEvent 对象的结构如下:

PendingWebhookEvent 结构
Copy Copy
1
2enum OutboundSyncEventType {
3 Create: 0,
4 Delete: 1,
5 Update: 2
6}
7
8enum OutboundSyncType {
9 /** 特定于 WordPress 的同步任务。 **/
10 WP: 0,
11 Webhook: 1
12}
13
14interface PendingWebhookEvent {
15 id: string
16 /** 与该事件关联的评论 id。 **/
17 commentId: string
18 /** 事件发生时的 comment 对象。我们从 2023 年 11 月开始添加这些。 **/
19 comment: Comment
20 /** 可能与评论关联的外部 id。 **/
21 externalId: string | null
22 createdAt: Date
23 tenantId: string
24 attemptCount: number
25 /** 在第一次尝试前以及每次失败后设置。 **/
26 nextAttemptAt: Date
27 /** 表示这是创建、删除还是更新事件。 **/
28 eventType: OutboundSyncEventType
29 /** 要执行的同步类型(WordPress、调用 API 等)。 **/
30 type: OutboundSyncType
31 /** 与评论匹配的域。我们使用该域来选择 API 密钥。 **/
32 domain: string
33 /** 最近发生的错误。此类型未指定具体类型,是对发生情况的“转储”。通常它包含一个具有 statusCode、body 和 headers 映射的对象。 **/
34 lastError: object | null
35}
36

SSO 用户结构 Internal Link

FastComments provides an easy to use SSO solution. Updating a user's information with the HMAC-based integration is as simple as having the user load the page with an updated payload.

但是,可能希望在该流程之外管理用户,以提高应用程序的一致性。

The SSO User API provides a way to CRUD objects that we call SSOUsers. These objects are different from regular Users and kept separate for type safety.

SSOUser 对象的结构如下:

SSOUser 结构
Copy Copy
1
2interface SSOUser {
3 id: string
4 username: string
5 email?: string
6 websiteUrl?: string
7 signUpDate: number
8 createdFromUrlId?: string
9 loginCount?: number
10 avatarSrc?: string
11 optedInNotifications?: boolean
12 optedInSubscriptionNotifications?: boolean
13 displayLabel?: string
14 displayName?: string
15 isAccountOwner?: boolean // 管理权限 - 具有此标志的 SSO 用户将作为 SSO 管理员计费(与常规 SSO 用户分开)
16 isAdminAdmin?: boolean // 管理权限 - 具有此标志的 SSO 用户将作为 SSO 管理员计费(与常规 SSO 用户分开)
17 isCommentModeratorAdmin?: boolean // 版主权限 - 具有此标志的 SSO 用户将作为 SSO 版主计费(与常规 SSO 用户分开)
18 /** 如果为 null,则不会对该用户应用访问控制。如果为空列表,则该用户将无法看到任何页面或 @ 提及其他用户。 **/
19 groupIds?: string[] | null
20 createdFromSimpleSSO?: boolean
21 /** 不要让其他用户在其个人资料上看到该用户的活动(包括评论)。默认值为 true,以默认提供安全的个人资料。 **/
22 isProfileActivityPrivate?: boolean
23 /** 不要允许其他用户在该用户的个人资料上留下评论,或查看现有的个人资料评论。默认值为 false。 **/
24 isProfileCommentsPrivate?: boolean
25 /** 不要允许其他用户向该用户发送直接消息。默认值为 false。 **/
26 isProfileDMDisabled?: boolean
27 karma?: number
28 /** 用户徽章的可选配置。 **/
29 badgeConfig?: {
30 /** 要分配给用户的徽章 ID 数组。限制为 30 个徽章。顺序将被保留。 **/
31 badgeIds: string[]
32 /** 如果为 true,则用提供的徽章替换所有现有显示的徽章。如果为 false,则将提供的徽章添加到现有徽章中。 **/
33 override?: boolean
34 /** 如果为 true,则从租户配置更新徽章显示属性。 **/
35 update?: boolean
36 }
37}
38

Billing for SSO Users

SSO users are billed differently based on their permission flags:

  • Regular SSO Users: Users without admin or moderator permissions are billed as regular SSO users
  • SSO Admins: Users with isAccountOwner or isAdminAdmin flags are billed separately as SSO Admins (same rate as regular tenant admins)
  • SSO Moderators: Users with isCommentModeratorAdmin flag are billed separately as SSO Moderators (same rate as regular moderators)

Important: To prevent double billing, the system automatically deduplicates SSO users against regular tenant users and moderators by email address. If an SSO user has the same email as a regular tenant user or moderator, they will not be billed twice.

SSO 用户的计费

根据权限标志,SSO 用户的计费方式不同:

  • 常规 SSO 用户:没有管理员或版主权限的用户按常规 SSO 用户计费
  • SSO 管理员:具有 isAccountOwnerisAdminAdmin 标志的用户将作为 SSO 管理员单独计费(与常规租户管理员费率相同)
  • SSO 版主:具有 isCommentModeratorAdmin 标志的用户将作为 SSO 版主单独计费(与常规版主费率相同)

重要:为防止重复计费,系统会根据电子邮件地址自动对 SSO 用户与常规租户用户和版主进行去重。如果 SSO 用户与常规租户用户或版主的电子邮件相同,则不会被重复计费。

Access Control

Users can be broken into groups. This is what the groupIds field is for, and is optional.

访问控制

用户可以被划分为组。这就是 groupIds 字段的用途,且为可选。

@Mentions

By default @mentions will use username to search for other sso users when the @ character is typed. If displayName is used, then results matching username will be ignored when there is a match for displayName, and the @mention search results will use displayName.

@提及

默认情况下,当输入 @ 字符时,@mentions 将使用 username 来搜索其他 SSO 用户。如果使用 displayName,当有与 displayName 匹配时, 与 username 匹配的结果将被忽略,@mention 搜索结果将使用 displayName

Subscriptions

With FastComments, users can subscribe to a page by clicking the bell icon in the comment widget and clicking Subscribe.

With a regular user, we send them notification emails based on their notification settings.

With SSO Users, we split this up for backwards compatibility. Users will only get sent these additional subscription notification emails if you set optedInSubscriptionNotifications to true.

订阅

在 FastComments 中,用户可以通过在评论小部件中点击铃铛图标并选择订阅来订阅页面。

对于常规用户,我们会根据他们的通知设置向其发送通知电子邮件。

对于 SSO 用户,我们为向后兼容而进行了拆分。只有当您将 optedInSubscriptionNotifications 设置为 true 时,用户才会收到这些额外的订阅通知 电子邮件。

Badges

You can assign badges to SSO users using the badgeConfig property. Badges are visual indicators that appear next to a user's name in comments.

  • badgeIds - An array of badge IDs to assign to the user. These must be valid badge IDs created in your FastComments account. Limited to 30 badges.
  • override - If true, all existing badges displayed on comments will be replaced with the provided ones. If false or omitted, the provided badges will be added to any existing badges.
  • update - If true, badge display properties will be updated from the tenant configuration whenever the user logs in.

徽章

您可以使用 badgeConfig 属性为 SSO 用户分配徽章。徽章是在评论中显示在用户名称旁的视觉指示器。

  • badgeIds - 要分配给用户的徽章 ID 数组。这些必须是您 FastComments 帐户中创建的有效徽章 ID。限制为 30 个徽章。
  • override - 如果为 true,则评论中显示的所有现有徽章将被提供的徽章替换。如果为 false 或省略,则将提供的徽章添加到任何现有徽章中。
  • update - 如果为 true,则在用户登录时将根据租户配置更新徽章显示属性。

订阅结构 Internal Link

A Subscription object 表示用户的订阅。

Subscription objects 在用户在评论小部件中点击通知铃铛并点击 "订阅此页面" 时创建。

Subscriptions 也可以通过 API 创建。

Having a Subscription object causes Notification objects to be generated, and emails sent, when new comments are left on the root of the associated page that the Subscription is for. 电子邮件的发送取决于用户类型。对于普通用户,这取决于 optedInNotifications。对于 SSO 用户,这取决于 optedInSubscriptionNotifications。注意,有些应用可能没有可通过 Web 访问的页面的概念,在这种情况下,只需将 urlId 设置为您要订阅的项目的 id(与传递给评论小部件的 urlId 值相同)。

The structure for the Subscription object is as follows:

订阅结构
Copy Copy
1
2interface Subscription {
3 id: string
4 tenantId: string
5 /** 使用 SSO 时,用户 ID 的格式为 `<tenant id>:<user id>`。 **/
6 userId: string
7 anonUserId?: string
8 urlId: string
9 url?: string
10 pageTitle?: string
11 createdAt: string // 日期字符串
12}
13

租户每日使用量结构 Internal Link

一个 TenantDailyUsage 对象表示租户在某一天的使用情况。如果在某租户的某个给定 天没有活动,则该天将不会有 TenantDailyUsage 对象。

The TenantDailyUsage object is 不是 real time and may be minutes behind actual usage.

The structure for the TenantDailyUsage object is as follows:

TenantDailyUsage 结构
Copy Copy
1
2export interface TenantDailyUsage {
3 yearNumber: number
4 monthNumber: number
5 dayNumber: number
6 commentFetchCount?: number
7 commentCreateCount?: number
8 conversationCreateCount?: number
9 voteCount?: number
10 accountCreatedCount?: number
11 userMentionSearch?: number
12 hashTagSearch?: number
13 gifSearchTrending?: number
14 gifSearch?: number
15 apiCreditsUsed?: number
16 createdAt: string
17 billed: boolean
18 /** 忽略计费。 **/
19 ignored: boolean
20}
21

租户结构 Internal Link

The Tenant 定义了一个 FastComments.com 客户。具有白标访问权限的租户可以通过 API 创建它们。白标租户 不能创建其他白标租户(只允许一层嵌套)。

The structure for the Tenant object is as follows:

租户结构
Copy Copy
1
2export enum SiteType {
3 Unknown = 0,
4 WordPress = 1
5}
6
7/** 这也可以通过 DomainConfig API 处理。 **/
8export interface TenantDomainConfig {
9 domain: string
10 emailFromName?: string
11 emailFromEmail?: string
12 createdAt?: string,
13 siteType?: FastCommentsSiteType, // 你可能想要 Unknown
14 logoSrc?: string, // 原始图像路径
15 logoSrc100px?: string, // 为缩略图调整大小
16 footerUnsubscribeURL?: string,
17 emailHeaders?: Record<string, string>,
18 disableUnsubscribeLinks?: boolean,
19 dkim?: {
20 domainName: string,
21 keySelector: string,
22 privateKey: string
23 }
24}
25
26export interface TenantBillingInfo {
27 name: string
28 address: string
29 city: string
30 state: string
31 zip: string
32 country: string
33}
34
35export enum TenantPaymentFrequency {
36 Monthly = 0,
37 Annually = 1
38}
39
40export interface Tenant {
41 id: string
42 name: string
43 email?: string
44 signUpDate: number; // 由于“遗留”原因为 number
45 packageId?: string | null
46 paymentFrequency?: TenantPaymentFrequency
47 billingInfoValid?: boolean
48 billingHandledExternally?: boolean
49 createdBy?: string
50 isSetup?: boolean
51 domainConfiguration: FastCommentsAPITenantDomainConfig[]
52 billingInfo?: FastCommentsAPITenantBillingInfo
53 stripeCustomerId?: string
54 stripeSubscriptionId?: string
55 stripePlanId?: string
56 enableProfanityFilter?: boolean
57 enableSpamFilter?: boolean
58 lastBillingIssueReminderDate?: string
59 removeUnverifiedComments?: boolean
60 unverifiedCommentsTTLms?: number
61 commentsRequireApproval?: boolean
62 autoApproveCommentOnVerification?: boolean
63 sendProfaneToSpam?: boolean
64 /** @readonly - 基于 packageId 计算。 **/
65 hasFlexPricing?: boolean
66 /** @readonly **/
67 flexLastBilledAmount?: number
68 /** @readonly - 基于 packageId 计算。 **/
69 hasAuditing?: boolean
70 /** 你可以在租户上存储一个键值对并用于查询。键不能包含 "." 或 "$",或超过 100 个字符。值不能超过 2k 个字符。 **/
71 meta?: Record<string, string | null>
72}
73

用户结构 Internal Link

User 是表示所有用户的最通用属性的对象。

请记住,在 FastComments 中,我们有多种不同的用户使用场景:

  • Secure SSO
  • Simple SSO
  • Tenant Users (例如:管理员)
  • Commenters

This API is for Commenters and users created via Simple SSO. Basically, any user created through your site can be accessed via this API. Tenant Users can also be fetched this way, but you'll get more information by interacting with the /tenant-users/ API.

For Secure SSO please use the /sso-users/ API.

You cannot update these types of users. They created their account through your site, so we provide some basic read-only access, but you cannot make changes. If you want to have this type of flow - you need to setup Secure SSO.

The structure for the User object is as follows:

用户结构
Copy Copy
1
2export interface User {
3 /** 这也是在评论对象上作为 userId 使用的 id。 **/
4 id: string
5 username: string
6 /** 例如,指向评论者博客的链接。 **/
7 websiteUrl?: string
8 email: string
9 signUpDate: number
10 createdFromUrlId: string
11 createdFromTenantId: string
12 avatarSrc?: string
13 locale: FastCommentsLocale
14 displayLabel?: string
15 karma?: number
16}
17

投票结构 Internal Link


A Vote 对象表示用户留下的投票。

评论与投票之间的关系通过 commentId 来定义。

Vote 对象的结构如下:

Vote 对象结构
Copy Copy
1
2interface Vote {
3 id: string
4 urlId: string
5 commentId: string
6 userId: string
7 direction: 1 | -1
8 createdAt: string
9}
10

问题配置结构 Internal Link


FastComments 提供了一种构建问题并汇总其结果的方式。一个问题的示例(以下称为 QuestionConfig)可以是星级评分、滑块,或 NPS 问题(由 type 决定)。

问题数据可以按单个、组合、随时间、总体、按页面等方式汇总。

该框架具备构建客户端小部件(在此 API 之前由您的服务器处理)、管理面板和报表工具所需的所有功能。

首先,我们必须定义一个 QuestionConfig。其结构如下:

QuestionConfig 结构
Copy Copy
1
2type QuestionConfigType = 'nps' | 'slider' | 'star' | 'thumbs';
3
4interface QuestionConfig {
5 id: string
6 tenantId: string
7 name: string
8 question: string
9 helpText?: string
10 createdAt: string
11 createdBy: string
12 /** 只读 - 对每个新响应递增。 **/
13 usedCount: number
14 /** 表示配置最后一次被使用(留下结果)的日期字符串。 **/
15 lastUsed?: string
16 type: QuestionConfigType
17 numStars?: number
18 min?: number
19 max?: number
20 defaultValue?: number
21 labelNegative?: string
22 labelPositive?: string
23 subQuestionIds?: string[]
24 alwaysShowSubQuestions?: boolean
25 reportingOrder: number
26}
27

问题结果结构 Internal Link

为了保存问题的结果,您需要创建一个 QuestionResult。您随后可以对问题结果进行汇总,并且 将它们与评论关联以用于报告目的。

QuestionResult 结构
Copy Copy
1
2interface QuestionResultMeta {
3 name: string
4 values: string[]
5}
6
7interface QuestionResult {
8 id: string
9 tenantId: string
10 urlId: string
11 anonUserId?: string
12 userId?: string
13 createdAt?: string
14 value: number
15 commentId?: string
16 questionId: string
17 meta?: QuestionResultMeta[]
18}
19

用户徽章结构 Internal Link

UserBadge 是一个对象,表示分配给 FastComments 系统中用户的徽章。

徽章可以根据用户的活动(例如评论数量、回复时间、资深用户状态)自动分配,也可以由站点管理员手动分配。

以下是 UserBadge 对象的结构:

UserBadge 结构
Copy Copy
1
2export interface UserBadge {
3 /** 此用户徽章分配的唯一标识符 */
4 id: string
5 /** 该徽章分配给的用户 ID */
6 userId: string
7 /** 来自租户徽章目录的徽章定义 ID */
8 badgeId: string
9 /** 创建/分配此徽章的租户 ID */
10 fromTenantId: string
11 /** 此徽章的创建时间(自纪元以来的毫秒) */
12 createdAt?: number
13 /** 用户收到此徽章的时间(自纪元以来的毫秒) */
14 receivedAt?: number
15 /**
16 * 徽章类型:
17 * 0=CommentCount, 1=CommentUpVotes, 2=CommentReplies, 3=CommentsPinned,
18 * 4=Veteran, 5=NightOwl, 6=FastReplyTime, 7=ModeratorCommentsDeleted,
19 * 8=ModeratorCommentsApproved, 9=ModeratorCommentsUnapproved, 10=ModeratorCommentsReviewed,
20 * 11=ModeratorCommentsMarkedSpam, 12=ModeratorCommentsMarkedNotSpam, 13=RepliedToSpecificPage,
21 * 14=Manual
22 */
23 type: number
24 /** 对于基于阈值的徽章,阈值 */
25 threshold?: number
26 /** 徽章的名称/标签 */
27 name?: string
28 /** 徽章的详细描述 */
29 description?: string
30 /** 徽章上显示的文字 */
31 displayLabel?: string
32 /** 徽章上显示图像的 URL */
33 displaySrc?: string
34 /** 徽章的背景颜色(十六进制代码) */
35 backgroundColor?: string
36 /** 徽章的边框颜色(十六进制代码) */
37 borderColor?: string
38 /** 徽章的文字颜色(十六进制代码) */
39 textColor?: string
40 /** 用于样式的额外 CSS 类 */
41 cssClass?: string
42 /** 对于资深徽章,时间阈值(毫秒) */
43 veteranUserThresholdMillis?: number
44 /** 此徽章是否显示在用户的评论上 */
45 displayedOnComments: boolean
46 /** 徽章的显示顺序 */
47 order?: number
48}
49
---

用户徽章进度结构 Internal Link

UserBadgeProgress 是一个对象,表示用户在 FastComments 系统中获取各种徽章的进度。

此跟踪有助于确定何时应根据用户在社区的活动和参与自动授予徽章。

UserBadgeProgress 对象的结构如下:

UserBadgeProgress 结构
Copy Copy
1
2export interface UserBadgeProgress {
3 /** 此进度记录的唯一标识符 */
4 id: string
5 /** 此进度记录所属租户的 ID */
6 tenantId: string
7 /** 此进度记录所跟踪的用户的 ID */
8 userId: string
9 /** 用户在系统中的第一条评论的 ID */
10 firstCommentId?: string
11 /** 用户第一条评论的日期(自纪元以来的毫秒数) */
12 firstCommentDate?: number
13 /** 基于用户活动自动计算的信任因子 */
14 autoTrustFactor?: number
15 /** 由管理员手动设置的信任因子 */
16 manualTrustFactor?: number
17 /** 包含各种指标的详细进度对象,键与 BadgeType 枚举匹配 */
18 progress: {
19 /** 0: CommentCount - 用户发布的评论数量 */
20 '0'?: number
21 /** 1: CommentUpVotes - 用户收到的赞数 */
22 '1'?: number
23 /** 2: CommentReplies - 用户发布的回复数量 */
24 '2'?: number
25 /** 3: CommentsPinned - 用户的被置顶评论数量 */
26 '3'?: number
27 /** 4: Veteran - 用户账户年龄 */
28 '4'?: number
29 /** 5: NightOwl - 用户在夜间时段发布的次数 */
30 '5'?: number
31 /** 6: FastReplyTime - 平均回复时间(以毫秒为单位) */
32 '6'?: number
33 /** 7: ModeratorCommentsDeleted - 针对版主徽章,已删除评论的数量 */
34 '7'?: number
35 /** 8: ModeratorCommentsApproved - 针对版主徽章,已通过审核的评论数量 */
36 '8'?: number
37 /** 9: ModeratorCommentsUnapproved - 针对版主徽章,未批准的评论数量 */
38 '9'?: number
39 /** 10: ModeratorCommentsReviewed - 针对版主徽章,已审核的评论数量 */
40 '10'?: number
41 /** 11: ModeratorCommentsMarkedSpam - 针对版主徽章,被标记为垃圾评论的数量 */
42 '11'?: number
43 /** 12: ModeratorCommentsMarkedNotSpam - 针对版主徽章,被标记为非垃圾评论的数量 */
44 '12'?: number
45 /** 13: RepliedToSpecificPage - 针对每个页面的回复数量 */
46 '13'?: Record<string, number>
47 }
48}
49

总结

我们希望您认为我们的 API 文档详尽且易于理解。如果您发现任何遗漏,请在下方告诉我们。