FastComments.com

FastComments 的 API

FastComments 提供一個可與多種資源互動的 API。可用來建立與我們平台的整合,或甚至自行建立客戶端!

在本文件中,您將會找到 API 支援的所有資源,並列出它們的請求與回應類型。

對於企業客戶,所有 API 存取都會被記錄在稽核日誌中。

已產生的 SDKs

FastComments 現在會從程式碼產生一份 API Spec(尚未完整,但已包含許多 API)。

我們也提供熱門語言的 SDK:

驗證

API 的驗證方式是將您的 api keyX-API-KEY 標頭或 API_KEY 查詢參數傳送。您還需要您的 tenantId 來進行 API 呼叫。這可以從與您的 api key 相同的頁面取得。

安全注意事項

這些路由應從 伺服器 呼叫。 請勿 從瀏覽器呼叫它們。這樣做會暴露您的 API key - 任何能查看頁面原始碼的人都會取得對您帳戶的完全存取權!

驗證選項一 - 標頭

  • 標頭: X-API-KEY
  • 標頭: X-TENANT-ID

驗證選項二 - 查詢參數

  • 查詢參數: API_KEY
  • 查詢參數: tenantId

稽核日誌結構 Internal Link


An AuditLog 是一個物件,代表對有權使用此功能的租戶所記錄的稽核事件。

The structure for the AuditLog object is as follows:

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 讀取它。

Events in the audit log expire after two years.


評論結構 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 /** 評論者的名稱。始終為必填。如果沒有,可設為像 "Anonymous" 之類的名稱。 **/
20 commenterName: string
21 /** 留下評論的日期,以 UTC epoch 表示。 **/
22 date: number
23 /** 評論的「顯示標籤」,例如 "Admin"、"Moderator",或像 "VIP User" 之類的。 **/
24 displayLabel?: string
25 /** 發表評論的網域。 **/
26 domain?: string
27 /** 唯讀:評論被檢舉的次數。 **/
28 flagCount?: number
29 /** 評論中成功解析的 #hashtag。你也可以手動加入 hashtag 以供查詢,但它們不會自動顯示在評論文字中。 **/
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 /** 評論所使用的語系。若未提供,將從 Accept-Language HTTP 標頭推斷。 **/
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 /** 與評論相關的可選額外資訊(metadata)。 **/
66 meta?: Record<string, string | number | boolean>
67 /** 與此評論相關的可選 moderation 群組 id 清單。 **/
68 moderationGroupIds?: string[]|null
69 /** 唯讀:對應於當前使用者(contextUserId)在此評論上投票的 vote 物件 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 /** 評論的「Karma」(= 讚成票數 - 反對票數)。 **/
98 votes?: number
99}
100

Some of these fields are marked READONLY - these are returned by the API but cannot be set.

評論文字結構

評論以 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 = SSOUser。 **/
10 type: 'user'|'sso'
11 /** 即使使用者選擇不接收通知,這仍會被設為 true。 **/
12 sent: boolean
13}
14

HashTags

當使用 hashtag 並成功解析時,相關資訊會儲存在名為 hashTags 的清單中。該清單中的每個物件具有以下結構。若將 retain 設定為 true,hashtag 也可以手動加入至評論的 hashTags 陣列以供查詢。

評論 Hashtag 物件
Copy CopyRun External Link
1
2interface CommentHashTag {
3 /** hashtag id。 **/
4 id: string
5 /** 最終的 #hashtag 標籤文字,包含 # 符號。 **/
6 tag: string
7 /** 若該 hashtag 與自訂 URL 關聯,則會定義此欄。 **/
8 url?: string
9 /** 當評論更新時,若需保留該 hashtag(即使它不存在於評論文字中),則設定此欄。這對於在不更改評論文字的情況下標註評論很有用。 **/
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 物件代表使用者可以留下的標籤。HashTag 可用於連結到外部的內容或將相關評論串連起來。

HashTag 物件的結構如下:

HashTag 結構
Copy Copy
1
2interface HashTag {
3 /** 應以 "#" 或其他想要的字元開頭。 **/
4 tag: string
5 /** 可選的 URL,hashtag 可指向此 URL。與其透過 hashtag 篩選評論,UI 在點擊時會導向此處。 **/
6 url?: string
7 /** 唯讀 **/
8 createdAt: string
9}
10

注意:

  • 在某些 API 端點中,你會看到 hashtag 被用在 URL 中。請記得對值進行 URI 編碼。例如,# 應該表示為 %23
  • 其中某些欄位被標示為 READONLY - 這些欄位由 API 回傳,但無法設定。

通知計數結構 Internal Link

A 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

A Notification object represents a notification for a user.

Notification objects are created automatically and cannot be created via the API. They also expire after one year. Notifications cannot be deleted. They can however be updated to set viewed to false, and you can query by viewed.

A user may also opt out of notifications for a specific comment by setting optedOut in the notification to true. You can opt in again by setting it to false.

There are different notification types - check relatedObjectType and type.

The ways notifications are created is quite flexible and can be triggered by many scenarios (see NotificationType).

As of today, the existence of a Notification does not actually imply an email is or should be sent. Rather, the notifications are used for the notification feed and related integrations.

The structure for the Notification object is as follows:

通知結構
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 /** With SSO, the user id is in the format `<tenant id>:<user id>`. **/
31 userId?: string
32 /** When working with SSO, you only have to worry about `userId`. **/
33 anonUserId?: string
34 /** urlId is almost always defined. It is only optional for tenant-level notifications, which are infrequent. **/
35 urlId?: string
36 /** URL is cached for quick navigation to the source of the notification. **/
37 url?: string
38 /** Page Title is cached for quick reading of notification source. **/
39 pageTitle?: string
40 relatedObjectType: NotificationObjectType
41 /** For example, comment id. **/
42 relatedObjectId: string
43 viewed: boolean
44 createdAt: string // 日期字串
45 type: NotificationType
46 fromCommentId?: string
47 fromVoteId?: string
48 /** fromUserName and fromUserAvatarSrc are cached here for quick displaying of the notification. They are updated when the user is updated. **/
49 fromUserName: string
50 fromUserId: string
51 fromUserAvatarSrc?: string
52 /** Set this to true to stop getting notifications for this object. **/
53 optedOut?: boolean
54}
55

頁面結構 Internal Link

一個 Page 物件代表許多評論可能屬於的頁面。這種關係是由 urlId 定義的。

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


A PendingWebhookEvent object represents a queued webhook event that is pending.

PendingWebhookEvent objects are created automatically and cannot be manually created via the API. They also expire after one year. They can be deleted which removes the task from the queue.

There are different event types - check eventType (OutboundSyncEventType) and type (OutboundSyncType).

A common use case for this API is to implement custom monitoring. You may want to call the /count endpoint periodically to poll the outstanding count for given filters.

The structure for the PendingWebhookEvent object is as follows:

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 /** 事件發生時對應的評論物件。我們從 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 提供易於使用的 SSO 解決方案。使用基於 HMAC 的整合更新使用者資訊,就像讓使用者載入帶有更新載荷的頁面一樣簡單。

不過,您可能會希望在該流程之外管理使用者,以改善應用程式的一致性。

SSO 使用者 API 提供一種對我們稱為 SSOUser 的物件進行 CRUD 的方式。這些物件不同於一般的 Users,並為了型別安全而分開保存。

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

SSO 使用者計費

SSO 使用者會根據其權限標記以不同方式計費:

  • 一般 SSO 使用者:沒有管理員或版主權限的使用者將以一般 SSO 使用者計費
  • SSO 管理員:具有 isAccountOwnerisAdminAdmin 標記的使用者會被另外計費為 SSO 管理員(與一般租戶管理員相同費率)
  • SSO 版主:具有 isCommentModeratorAdmin 標記的使用者會被另外計費為 SSO 版主(與一般版主相同費率)

重要:為了避免重複計費,系統會自動根據電子郵件地址將 SSO 使用者與一般租戶使用者和版主去重。如果 SSO 使用者與一般租戶使用者或版主具有相同的電子郵件,則不會被重複計費。

存取控制

使用者可以被分到不同群組。這就是 groupIds 欄位的用途,且為選用。

@ 提及

預設情況下,當輸入 @ 字元時,@mentions 會使用 username 來搜尋其他 SSO 使用者。如果使用 displayName,當 displayName 有匹配時,符合 username 的結果將被忽略,而 @mention 的搜尋結果會使用 displayName

訂閱

在 FastComments 中,使用者可以透過在留言小工具中點擊鈴鐺圖示並選擇訂閱來訂閱頁面。

對於一般使用者,我們會根據他們的通知設定發送通知電子郵件。

對於 SSO 使用者,我們為了向後相容將此行為拆分。只有當您將 optedInSubscriptionNotifications 設為 true 時,使用者才會收到這些額外的訂閱通知電子郵件。

徽章

您可以使用 badgeConfig 屬性為 SSO 使用者指定徽章。徽章是在留言中顯示於使用者名稱旁的視覺指標。

  • badgeIds - 指派給使用者的徽章 ID 陣列。這些必須是您在 FastComments 帳戶中建立的有效徽章 ID。最多限制為 30 個徽章。
  • override - 如果為 true,留言上所有現有顯示的徽章將被提供的徽章取代。如果為 false 或省略,提供的徽章將會新增到現有徽章中。
  • update - 如果為 true,當使用者登入時徽章的顯示屬性會從租戶設定更新。

訂閱結構 Internal Link

一個 Subscription 物件代表使用者的訂閱。

Subscription 物件會在使用者在評論小工具中點擊通知鈴鐺並點選 "訂閱此頁面" 時建立。

也可以透過 API 建立訂閱。

擁有 Subscription 物件會在與該 Subscription 相關聯的頁面 根層留下新留言時,會產生 Notification 物件並發送電子郵件。

是否發送電子郵件取決於使用者類型。對於一般使用者,這取決於 optedInNotifications。對於 SSO 使用者,則取決於 optedInSubscriptionNotifications。請注意,有些應用程式可能沒有可由網頁存取的頁面概念,在這種情況下,只需將 urlId 設為 您要訂閱的項目的 id(與傳遞給評論小工具的 urlId 值相同)。

以下為 Subscription 物件的結構:

訂閱結構
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

A TenantDailyUsage object represents the usage for a tenant on a given day. If there was no activity for a given tenant on a given day, that day will not have a TenantDailyUsage object.

The TenantDailyUsage object is not 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 建立這些租戶。白標租戶無法建立其他白標租戶(僅允許一層巢狀)。

Tenant 物件的結構如下:

租戶結構
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 is an object that represents a most-common denominator of all users.

Keep in mind that at FastComments we have a bunch of different use cases for users:

  • 安全 SSO
  • 簡易 SSO
  • 租戶使用者(例如:管理者)
  • 留言者

This API is for 留言者 and users created via 簡易 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

一個 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 /** 此徽章建立時間(以 epoch 起算的毫秒) */
12 createdAt?: number
13 /** 使用者收到此徽章的時間(以 epoch 起算的毫秒) */
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 /** 使用者第一則評論的日期(自 epoch 起的毫秒數) */
12 firstCommentDate?: number
13 /** 根據使用者活動自動計算的信任係數 */
14 autoTrustFactor?: number
15 /** 由管理員手動設定的信任係數 */
16 manualTrustFactor?: number
17 /** 包含各種指標的詳細進度物件,鍵與 BadgeType enum 相符 */
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 文件詳盡且易於理解。如果您發現任何缺漏,請在下方告知我們。