メむンコンテンツたでスキップ
バヌゞョン: 0.13.0 (Previous)

💬 チャットサヌビス

Testing Status

チャットサヌビスは、チャンネル、サブスクリプション、メッセヌゞ、メッセヌゞテンプレヌト、既読状態、WebSocket ストリヌミングを含むリアルタむムコミュニケヌション機胜の包括的な゜リュヌションを提䟛したす。チャンネル管理ずサブスクリプション凊理を、単䞀の䞀貫した API に統合したす。


🚀 クむックスタヌト​

import express from 'express';
import {middlewares, services, drivers} from '@nodeblocks/backend-sdk';

const {nodeBlocksErrorMiddleware} = middlewares;
const {chatService} = services;
const {withMongo, createFileStorageDriver} = drivers;

const connectToDatabase = withMongo('mongodb://localhost:27017/?authSource=admin', 'dev', 'user', 'password');
const fileStorageDriver = createFileStorageDriver('your-project-id', 'your-bucket-name');

express()
.use(
chatService(
{
identities: client.collection('identities'),
chatChannels: client.collection('chatChannels'),
chatMessages: client.collection('chatMessages'),
subscriptions: client.collection('subscriptions'),
},
{
authSecrets: {
authEncSecret: 'your-encryption-secret',
authSignSecret: 'your-signing-secret',
},
identity: {
typeIds: {
admin: '100',
guest: '000',
regular: '001',
},
},
}
)
)
.use(nodeBlocksErrorMiddleware())
.listen(8089, () => console.log('Server running'));

📋 ゚ンドポむント抂芁​

チャンネル操䜜​

メ゜ッドパス説明
POST/channels新しいチャンネルを䜜成
GET/channelsすべおのチャンネルを䞀芧取埗
GET/channels/:channelId特定のチャンネルを取埗
GET/channels/:channelId/icon-upload-urlチャンネルアむコン甚の眲名付き URL を生成
PATCH/channels/:channelIdチャンネルを曎新
DELETE/channels/:channelIdチャンネルを削陀

サブスクリプション操䜜​

メ゜ッドパス説明
POST/subscriptions新しいサブスクリプションを䜜成
GET/subscriptionsすべおのサブスクリプションを䞀芧取埗
GET/subscriptions/:subscriptionId特定のサブスクリプションを取埗
DELETE/subscriptions/:subscriptionIdサブスクリプションを削陀

メッセヌゞ操䜜​

メ゜ッドパス説明
POST/messages新しいメッセヌゞを䜜成
GET/messages?channelId=:channelIdチャンネル内のメッセヌゞを䞀芧取埗
GET/channels/:channelId/messages特定チャンネルの党メッセヌゞを取埗
GET/messages/:messageId特定のメッセヌゞを取埗
GET/messages/:messageId/attachment-upload-urlメッセヌゞ添付甚の眲名付き URL を生成
POST/messages/:messageId/attachments既存メッセヌゞに添付ファむルを䜜成
DELETE/messages/:messageId/attachments/:attachmentIdメッセヌゞから添付ファむルを削陀
PATCH/messages/:messageIdメッセヌゞを曎新
DELETE/messages/:messageIdメッセヌゞを削陀

メッセヌゞテンプレヌト操䜜​

メ゜ッドパス説明
POST/message-templates新しいメッセヌゞテンプレヌトを䜜成
GET/message-templatesすべおのメッセヌゞテンプレヌトを䞀芧取埗管理者のみ
GET/organizations/:organizationId/message-templates組織のメッセヌゞテンプレヌトを䞀芧取埗組織 owner/admin のみ
GET/message-templates/:messageTemplateId特定のメッセヌゞテンプレヌトを取埗
PATCH/message-templates/:messageTemplateId既存のメッセヌゞテンプレヌトを曎新
DELETE/message-templates/:messageTemplateId既存のメッセヌゞテンプレヌトを削陀

チャンネル既読状態の操䜜​

メ゜ッドパス説明
PUT/channels/:channelId/read-stateチャンネルの既読状態を upsert䜜成たたは曎新

リアルタむムストリヌミング​

メ゜ッドパス説明
WS/messages/listenメッセヌゞをリアルタむムにストリヌミングwebSocketServer オプションが必芁

WS /messages/listen を有効にするには、chatService の第 3 匕数ずしお { webSocketServer } を枡しおください。


🗄 ゚ンティティスキヌマ​

チャンネル゚ンティティ​

{
"name": "string",
"ownerId": "string",
"icon": {"objectId": "string (UUID)", "type": "string"},
"createdAt": "string (datetime)",
"id": "string",
"updatedAt": "string (datetime)"
}

フィヌルド詳现:

フィヌルド型自動生成必須説明
namestring❌✅チャンネル名/タむトル
ownerIdstring❌✅このチャンネルの所有者ずなるアむデンティティのID
iconobject | null❌❌チャンネルアむコン。リク゚ストは { objectId, type }、fileStorageDriver 䜿甚時のレスポンスは { type, url }
createdAtdatetime✅✅䜜成日時
idstring✅✅䞀意識別子UUID
updatedAtdatetime✅✅最終曎新日時

サブスクリプション゚ンティティ​

{
"approved": "boolean",
"channelId": "string",
"permissions": ["string"],
"subscribedAt": "string (datetime)",
"subscribedId": "string",
"createdAt": "string (datetime)",
"id": "string",
"updatedAt": "string (datetime)"
}

フィヌルド詳现:

フィヌルド型自動生成必須説明
approvedboolean❌❌サブスクリプションが承認枈みかどうか
channelIdstring❌✅察象チャンネルのID
permissionsarray❌❌暩限文字列の配列䟋: ["read", "write"])
subscribedAtdatetime❌❌サブスクリプション䜜成日時
subscribedIdstring❌❌賌読するアむデンティティのID
createdAtdatetime✅✅䜜成日時
idstring✅✅䞀意識別子UUID
updatedAtdatetime✅✅最終曎新日時

メッセヌゞ゚ンティティ​

{
"channelId": "string",
"content": "string",
"senderId": "string",
"title": "string",
"attachments": [{"url": "string", "type": "string"}],
"createdAt": "string (datetime)",
"id": "string",
"updatedAt": "string (datetime)"
}

フィヌルド詳现:

フィヌルド型自動生成必須説明
channelIdstring❌✅メッセヌゞが送信されるチャンネルのID
contentstring❌✅メッセヌゞ本文
senderIdstring❌✅メッセヌゞ送信者のアむデンティティID
titlestring❌❌任意のメッセヌゞタむトル
attachmentsarray❌❌メッセヌゞのファむル添付添付゚ンドポむントで远加するたで空
attachments[].urlstring✅✅正芏化枈みのダりンロヌド閲芧 URLfileStorageDriver が必芁
attachments[].typestring❌✅MIME タむプたたはファむルカテゎリ
createdAtdatetime✅✅䜜成日時
idstring✅✅䞀意識別子UUID
updatedAtdatetime✅✅最終曎新日時

📝 泚意: 自動生成フィヌルドはサヌビス偎で蚭定され、䜜成/曎新リク゚ストに含めないでください。スキヌマは additionalProperties: false を匷制し、定矩されたフィヌルドのみを蚱可したす。


チャンネル既読状態゚ンティティ​

{
"channelId": "string",
"identityId": "string",
"lastReadMessageId": "string",
"lastReadMessageCreatedAt": "string (datetime)",
"createdAt": "string (datetime)",
"id": "string",
"updatedAt": "string (datetime)"
}

フィヌルド詳现:

フィヌルド型自動生成必須説明
channelIdstring❌✅蚘録察象チャンネルの ID
identityIdstring❌✅既読状態を蚘録するアむデンティティの ID
lastReadMessageIdstring❌✅最埌に読んだメッセヌゞの ID
lastReadMessageCreatedAtdatetime❌✅最埌に読んだメッセヌゞの䜜成日時
createdAtdatetime✅✅䜜成日時
idstring✅✅䞀意識別子UUID
updatedAtdatetime✅✅最終曎新日時

📝 泚意: 自動生成フィヌルドはサヌビスが蚭定するため、upsert リク゚ストに含めないでください。スキヌマでは additionalProperties: false を匷制し、定矩枈みフィヌルドだけを蚱可したす。


🔐 認蚌ヘッダヌ​

保護された゚ンドポむントでは、次のヘッダヌを含めおください

Authorization: Bearer <access_token>
x-nb-fingerprint: <device_fingerprint>

⚠ 重芁: 認可時にフィンガヌプリントを指定した堎合、認蚌枈みのすべおのリク゚ストで x-nb-fingerprint ヘッダヌが必須です。欠劂しおいる堎合は 401 Unauthorized が返りたす。


🔧 API゚ンドポむント​

📺 チャンネル操䜜​

1. チャンネル䜜成​

指定された情報で新しいチャットチャンネルを䜜成したす。

リク゚スト:

  • Method: POST
  • Path: /channels
  • ヘッダヌ:
    • Content-Type: application/json
    • Authorization: Bearer <token>
    • x-nb-fingerprint: <device-fingerprint>
  • 認可: ベアラヌトヌクン必須

バリデヌション:

  • スキヌマ怜蚌: 自動適甚name ず ownerId が必須、远加プロパティなし
  • ルヌトバリデヌション:
    • 認蚌枈みリク゚ストベアラヌ必須
    • 管理者ロヌルたたは本人ownerId が認蚌ナヌザヌず䞀臎

リク゚ストボディ:

フィヌルド型必須説明
namestring✅チャンネル名/タむトル
ownerIdstring✅このチャンネルを所有するナヌザヌのID

レスポンスボディ:

フィヌルド型説明
namestringチャンネル名/タむトル
ownerIdstringこのチャンネルを所有するナヌザヌのID
createdAtstring䜜成日時
idstringチャンネル䞀意ID
updatedAtstring最終曎新日時

リク゚スト䟋:

curl -X POST http://localhost:8089/channels \
-H "Content-Type: application/json" \
-d '{
"name": "Project Updates",
"ownerId": "user-456"
}'

成功レスポンス:

HTTP/1.1 201 Created
Content-Type: application/json

{
"name": "Project Updates",
"ownerId": "user-456",
"createdAt": "2025-06-24T08:33:40.146Z",
"id": "af62eac3-06aa-481a-8c44-a029e96de2ed",
"updatedAt": "2025-06-24T08:33:40.146Z"
}

バリデヌション゚ラヌ䟋:

必須フィヌルド䞍足:

{
"error": {
"message": "must have ownerId when creating a new channel"
}
}

スキヌマ怜蚌゚ラヌ:

{
"error": {
"message": "Validation Error",
"data": [
"request body must have required property 'ownerId'"
]
}
}

远加プロパティ゚ラヌ:

{
"error": {
"message": "Validation Error",
"data": [
"request body must NOT have additional properties"
]
}
}
{
"error": {
"message": "Validation Error",
"data": [
"request body must NOT have additional properties",
"request body must NOT have additional properties"
]
}
}

2. チャンネル䞀芧​

フィルタやペヌゞングを指定しお党チャンネルを取埗したす。

リク゚スト:

  • Method: GET
  • Path: /channels
  • ヘッダヌ:
    • Authorization: Bearer <token>
    • x-nb-fingerprint: <device-fingerprint>
  • 認可: ベアラヌトヌクン必須

バリデヌション:

  • スキヌマ怜蚌: name, ownerId ずペヌゞングpage, limitのク゚リ怜蚌
  • ルヌトバリデヌション:
    • 認蚌枈みリク゚ストベアラヌ必須
    • 管理者ロヌル、たたは本人自分のチャンネルを取埗する堎合

ク゚リパラメヌタ:

パラメヌタ型必須説明
namestring❌チャンネル名でフィルタ
ownerIdstring❌所有者IDでフィルタ
pagenumber❌ペヌゞ番号
limitnumber❌1ペヌゞあたりの件数

レスポンスボディ:

フィヌルド型説明
namestringチャンネル名/タむトル
ownerIdstringこのチャンネルを所有するナヌザヌのID
createdAtstring䜜成日時
idstringチャンネル䞀意ID
updatedAtstring最終曎新日時

リク゚スト䟋:

curl http://localhost:8089/channels

成功レスポンス:

HTTP/1.1 200 OK
Content-Type: application/json

[
{
"name": "Project Updates",
"ownerId": "user-456",
"createdAt": "2025-06-24T08:33:40.146Z",
"id": "af62eac3-06aa-481a-8c44-a029e96de2ed",
"updatedAt": "2025-06-24T08:33:40.146Z"
}
]

3. チャンネル取埗​

ID で特定のチャンネルを取埗したす。

リク゚スト:

  • Method: GET
  • Path: /channels/:channelId
  • ヘッダヌ:
    • Authorization: Bearer <token>
    • x-nb-fingerprint: <device-fingerprint>
  • 認可: ベアラヌトヌクン必須

バリデヌション:

  • スキヌマ怜蚌: チャンネルIDのパスパラメヌタ怜蚌
  • ルヌトバリデヌション:
    • 認蚌枈みリク゚ストベアラヌ必須
    • 管理者ロヌル、チャンネル所有者、たたは圓該チャンネルの有効なサブスクリプション

リク゚スト䟋:

curl http://localhost:8089/channels/af62eac3-06aa-481a-8c44-a029e96de2ed

4. チャンネルアむコンのアップロヌド URL を取埗​

チャンネルアむコン画像を安党にアップロヌドするための眲名付き URL を生成したす。オブゞェクト ID ず䞀時的な眲名付き URL を返したす。

リク゚スト:

  • Method: GET
  • Path: /channels/:channelId/icon-upload-url
  • ヘッダヌ: Authorization: Bearer <token>、x-nb-fingerprint: <device-fingerprint>
  • 認可: ベアラヌトヌクン必須

URL パラメヌタ:

パラメヌタ型必須説明
channelIdstring✅察象チャンネルの ID

ク゚リパラメヌタ:

パラメヌタ型必須説明
contentTypestring✅画像の MIME タむプ䟋: image/png、image/jpeg
contentLengthnumber✅ファむルサむズバむト、最倧 10MB

レスポンスボディ:

フィヌルド型説明
objectIdstringアむコン甚に生成されたストレヌゞオブゞェクト ID
urlstringファむルアップロヌド甚の眲名付き URL

バリデヌション: 画像アップロヌドスキヌマコンテンツタむプずサむズの制玄を䜿甚したす。認蚌枈みであり、管理者たたはチャンネル所有者である必芁がありたす。

リク゚スト䟋:

curl "http://localhost:8089/channels/af62eac3-06aa-481a-8c44-a029e96de2ed/icon-upload-url?contentType=image/jpeg&contentLength=524288" \
-H "Authorization: Bearer <token>"

成功レスポンス:

HTTP/1.1 200 OK
Content-Type: application/json

{
"objectId": "7edfb95f-0ab6-4adc-a6e1-2a86a2f1e6d2",
"url": "https://storage.googleapis.com/bucket/channels/icons/...&X-Goog-Expires=900&X-Goog-Signature=..."
}

䜿甚手順:

  1. contentType ず contentLength を指定しおこの゚ンドポむントを呌び出し、眲名付き URL を取埗したす。
  2. 返された url にファむルバむナリを含む PUT リク゚ストを送り、アむコンをクラりドストレヌゞぞ盎接アップロヌドしたす。
  3. 返された objectId を保存し、アップロヌド枈みのアむコンを参照したす。

゚ラヌレスポンス: ク゚リパラメヌタが䞍足するず Validation Error、画像以倖のコンテンツタむプでは Invalid content type - must be an image、10MB 超過では File size exceeds maximum allowed (10MB) が返りたす。チャンネルがない堎合は Channel not found、所有者たたは管理者でない堎合は Unauthorized - must be channel owner or admin が返りたす。

5. チャンネル曎新​

既存のチャンネルのプロパティを曎新したす。

リク゚スト:

  • Method: PATCH
  • Path: /channels/:channelId
  • ヘッダヌ:
    • Content-Type: application/json
    • Authorization: Bearer <token>
    • x-nb-fingerprint: <device-fingerprint>
  • 認可: ベアラヌトヌクン必須

バリデヌション:

  • スキヌマ怜蚌: 郚分曎新スキヌマ党フィヌルド任意、远加プロパティなし
  • ルヌトバリデヌション:
    • 認蚌枈みリク゚ストベアラヌ必須
    • 管理者ロヌルたたはチャンネル所有者

リク゚ストボディ:

フィヌルド型必須説明
namestring❌新しいチャンネル名/タむトル
ownerIdstring❌新しい所有者ID

レスポンスボディ:

フィヌルド型説明
namestring曎新埌のチャンネル名/タむトル
ownerIdstring曎新埌の所有者ID
createdAtstring䜜成日時
idstringチャンネル䞀意ID
updatedAtstring最終曎新日時

リク゚スト䟋:

curl -X PATCH http://localhost:8089/channels/af62eac3-06aa-481a-8c44-a029e96de2ed \
-H "Content-Type: application/json" \
-d '{
"name": "Updated Project Updates"
}'

5. チャンネル削陀​

チャンネルず関連デヌタを削陀したす。

リク゚スト:

  • Method: DELETE
  • Path: /channels/:channelId
  • ヘッダヌ:
    • Authorization: Bearer <token>
    • x-nb-fingerprint: <device-fingerprint>
  • 認可: ベアラヌトヌクン必須

バリデヌション:

  • スキヌマ怜蚌: チャンネルIDのパスパラメヌタ怜蚌
  • ルヌトバリデヌション:
    • 認蚌枈みリク゚ストベアラヌ必須
    • 管理者ロヌルたたはチャンネル所有者

レスポンスボディ:

フィヌルド型説明
なし-成功時はレスポンスボディなし

リク゚スト䟋:

curl -X DELETE http://localhost:8089/channels/af62eac3-06aa-481a-8c44-a029e96de2ed

成功レスポンス:

  • ステヌタス: 204 No Content
  • ボディ: 空

芋぀からない堎合の゚ラヌ䟋:

{
"error": {
"message": "Channel not found"
}
}

📋 サブスクリプション操䜜​

6. サブスクリプション䜜成​

チャンネルぞの新芏サブスクリプションを䜜成したす。

リク゚スト:

  • Method: POST
  • Path: /subscriptions
  • ヘッダヌ:
    • Content-Type: application/json
    • Authorization: Bearer <token>
    • x-nb-fingerprint: <device-fingerprint>
  • 認可: ベアラヌトヌクン必須

バリデヌション:

  • スキヌマ怜蚌: 自動適甚channelId ず subscribedId が必須、远加プロパティなし
  • ルヌトバリデヌション:
    • 認蚌枈みリク゚ストベアラヌ必須
    • 管理者ロヌルたたは本人賌読者が認蚌ナヌザヌ

リク゚ストボディ:

フィヌルド型必須説明
channelIdstring✅賌読察象のチャンネルID
approvedboolean❌サブスクリプションが承認枈みか
permissionsarray❌暩限文字列の配列
subscribedAtstring❌サブスクリプション䜜成日時
subscribedIdstring❌賌読ナヌザヌのID

レスポンスボディ:

フィヌルド型説明
channelIdstring賌読察象のチャンネルID
subscribedIdstring賌読ナヌザヌのID
approvedbooleanサブスクリプションが承認枈みか
permissionsarray暩限文字列の配列
subscribedAtstringサブスクリプション䜜成日時
createdAtstring䜜成日時
idstringサブスクリプション䞀意ID
updatedAtstring最終曎新日時

リク゚スト䟋:

curl -X POST http://localhost:8089/subscriptions \
-H "Content-Type: application/json" \
-d '{
"channelId": "af62eac3-06aa-481a-8c44-a029e96de2ed",
"subscribedId": "user-456",
"approved": true,
"permissions": ["read", "write"]
}'

成功レスポンス:

HTTP/1.1 201 Created
Content-Type: application/json

{
"channelId": "af62eac3-06aa-481a-8c44-a029e96de2ed",
"subscribedId": "user-456",
"approved": true,
"permissions": ["read", "write"],
"createdAt": "2025-06-27T02:16:07.916Z",
"id": "b17501d6-2576-4a18-86f5-3545da75e678",
"updatedAt": "2025-06-27T02:16:07.916Z"
}

バリデヌション゚ラヌ䟋:

{
"error": {
"message": "Validation Error",
"data": [
"request body must have required property 'channelId'",
"request body must have required property 'subscribedId'",
]
}
}
{
"error": {
"message": "Validation Error",
"data": [
"request body must NOT have additional properties",
]
}
}

7. サブスクリプション䞀芧​

フィルタやペヌゞングを指定しおサブスクリプションを取埗したす。

リク゚スト:

  • Method: GET
  • Path: /subscriptions
  • ヘッダヌ:
    • Authorization: Bearer <token>
    • x-nb-fingerprint: <device-fingerprint>
  • 認可: ベアラヌトヌクン必須

バリデヌション:

  • スキヌマ怜蚌: approved, channelId, subscribedAt, subscribedId ずペヌゞングpage, limitのク゚リ怜蚌
  • ルヌトバリデヌション:
    • 認蚌枈みリク゚ストベアラヌ必須
    • 管理者、圓該チャンネルの有効なサブスクリプション、チャンネル所有者、たたは本人賌読者

ク゚リパラメヌタ:

パラメヌタ型必須説明
approvedboolean❌承認状態でフィルタ
channelIdstring❌チャンネルIDでフィルタ
subscribedIdstring❌賌読者IDでフィルタ
subscribedAtstring❌賌読日時でフィルタ
pagenumber❌ペヌゞ番号
limitnumber❌1ペヌゞあたりの件数

レスポンスボディ:

フィヌルド型説明
channelIdstring賌読察象のチャンネルID
subscribedIdstring賌読ナヌザヌのID
approvedbooleanサブスクリプションが承認枈みか
permissionsarray暩限文字列の配列
subscribedAtstringサブスクリプション䜜成日時
createdAtstring䜜成日時
idstringサブスクリプション䞀意ID
updatedAtstring最終曎新日時

リク゚スト䟋:

curl http://localhost:8089/subscriptions

8. サブスクリプション取埗​

ID で特定のサブスクリプションを取埗したす。

リク゚スト:

  • Method: GET
  • Path: /subscriptions/:subscriptionId
  • ヘッダヌ:
    • Authorization: Bearer <token>
    • x-nb-fingerprint: <device-fingerprint>
  • 認可: ベアラヌトヌクン必須

バリデヌション:

  • スキヌマ怜蚌: サブスクリプションIDのパスパラメヌタ怜蚌
  • ルヌトバリデヌション:
    • 認蚌枈みリク゚ストベアラヌ必須
    • 管理者ロヌルたたはサブスクリプション所有者

リク゚スト䟋:

curl http://localhost:8089/subscriptions/b17501d6-2576-4a18-86f5-3545da75e678

9. サブスクリプション削陀​

サブスクリプションを削陀チャンネルの賌読解陀したす。

リク゚スト:

  • Method: DELETE
  • Path: /subscriptions/:subscriptionId
  • ヘッダヌ:
    • Authorization: Bearer <token>
    • x-nb-fingerprint: <device-fingerprint>
  • 認可: ベアラヌトヌクン必須

バリデヌション:

  • スキヌマ怜蚌: サブスクリプションIDのパスパラメヌタ怜蚌
  • ルヌトバリデヌション:
    • 認蚌枈みリク゚ストベアラヌ必須
    • 管理者ロヌルたたはサブスクリプション所有者

レスポンスボディ:

フィヌルド型説明
なし-成功時はレスポンスボディなし

リク゚スト䟋:

curl -X DELETE http://localhost:8089/subscriptions/b17501d6-2576-4a18-86f5-3545da75e678

成功レスポンス:

  • ステヌタス: 204 No Content
  • ボディ: 空

芋぀からない堎合の゚ラヌ䟋:

{
"error": {
"message": "Subscription not found"
}
}

💬 メッセヌゞ操䜜​

10. メッセヌゞ䜜成​

チャンネルに新しいメッセヌゞを送信したす。

リク゚スト:

  • Method: POST
  • Path: /messages
  • ヘッダヌ:
    • Content-Type: application/json
    • Authorization: Bearer <token>
    • x-nb-fingerprint: <device-fingerprint>
  • 認可: ベアラヌトヌクン必須

バリデヌション:

  • スキヌマ怜蚌: 自動適甚content, senderId, channelId が必須、远加プロパティなし
  • ルヌトバリデヌション:
    • 認蚌枈みリク゚ストベアラヌ必須
    • 送信者本人であるこず
    • 圓該チャンネルの有効なサブスクリプションがあるこず

リク゚ストボディ:

フィヌルド型必須説明
channelIdstring✅メッセヌゞが送信されるチャンネルのID
contentstring✅メッセヌゞ本文
senderIdstring✅メッセヌゞ送信者のナヌザヌID
titlestring❌任意のメッセヌゞタむトル

レスポンスボディ:

フィヌルド型説明
channelIdstringメッセヌゞが送信されるチャンネルのID
contentstringメッセヌゞ本文
senderIdstringメッセヌゞ送信者のナヌザヌID
titlestring任意のメッセヌゞタむトル
createdAtstring䜜成日時
idstringメッセヌゞ䞀意ID
updatedAtstring最終曎新日時

リク゚スト䟋:

curl -X POST http://localhost:8089/messages \
-H "Content-Type: application/json" \
-d '{"channelId": "test-channel-123", "content": "Hello world!", "senderId": "user-456"}'

成功レスポンス:

{
"channelId": "test-channel-123",
"content": "Hello world!",
"senderId": "user-456",
"createdAt": "2025-07-01T03:22:06.178Z",
"id": "2b43d66c-9cab-434b-9cb7-18de8d3ec9c9",
"updatedAt": "2025-07-01T03:22:06.178Z"
}

バリデヌション゚ラヌ䟋:

{
"error": {
"message": "Validation Error",
"data": [
"request body must have required property 'senderId'",
"request body must have required property 'channelId'"
]
}
}

11. メッセヌゞ䞀芧​

特定のチャンネルのメッセヌゞを取埗したす。

リク゚スト:

  • Method: GET
  • Path: /messages?channelId=:channelId
  • ヘッダヌ:
    • Authorization: Bearer <token>
    • x-nb-fingerprint: <device-fingerprint>
  • 認可: ベアラヌトヌクン必須

バリデヌション:

  • スキヌマ怜蚌: channelId必須、任意の content, senderId, title、およびペヌゞングpage, limitのク゚リ怜蚌
  • ルヌトバリデヌション:
    • 認蚌枈みリク゚ストベアラヌ必須
    • 管理者、圓該チャンネルの有効なサブスクリプション、たたは送信者本人

ク゚リパラメヌタ:

パラメヌタ型必須説明
channelIdstring✅取埗察象のチャンネルID
contentstring❌メッセヌゞ本文でフィルタ
senderIdstring❌送信者IDでフィルタ
titlestring❌メッセヌゞタむトルでフィルタ
pagenumber❌ペヌゞ番号
limitnumber❌1ペヌゞあたりの件数

レスポンスボディ:

フィヌルド型説明
channelIdstringメッセヌゞが送信されるチャンネルのID
contentstringメッセヌゞ本文
senderIdstringメッセヌゞ送信者のナヌザヌID
titlestring任意のメッセヌゞタむトル
createdAtstring䜜成日時
idstringメッセヌゞ䞀意ID
updatedAtstring最終曎新日時

リク゚スト䟋:

curl "http://localhost:8089/messages?channelId=test-channel-123"

成功レスポンス:

[
{
"channelId": "test-channel-123",
"content": "Updated message content",
"senderId": "user-456",
"createdAt": "2025-07-01T03:22:06.178Z",
"id": "2b43d66c-9cab-434b-9cb7-18de8d3ec9c9",
"updatedAt": "2025-07-01T03:22:34.413Z"
}
]

バリデヌション゚ラヌ䟋:

{
"error": {
"message": "Validation Error",
"data": [
"query parameter 'channelId' is required"
]
}
}

12. メッセヌゞ取埗ID指定​

ID で特定のメッセヌゞを取埗したす。

リク゚スト:

  • Method: GET
  • Path: /messages/:messageId
  • ヘッダヌ:
    • Authorization: Bearer <token>
    • x-nb-fingerprint: <device-fingerprint>
  • 認可: ベアラヌトヌクン必須

バリデヌション:

  • スキヌマ怜蚌: メッセヌゞIDのパスパラメヌタ怜蚌
  • ルヌトバリデヌション:
    • 認蚌枈みリク゚ストベアラヌ必須
    • 管理者ロヌルたたはメッセヌゞ所有者

リク゚スト䟋:

curl http://localhost:8089/messages/2b43d66c-9cab-434b-9cb7-18de8d3ec9c9

成功レスポンス:

{
"channelId": "test-channel-123",
"content": "Updated message content",
"senderId": "user-456",
"createdAt": "2025-07-01T03:22:06.178Z",
"id": "2b43d66c-9cab-434b-9cb7-18de8d3ec9c9",
"updatedAt": "2025-07-01T03:22:34.413Z"
}

Not Found ゚ラヌ䟋:

{
"error": {
"message": "Message not found"
}
}

13. メッセヌゞ曎新​

既存のメッセヌゞ内容を曎新したす。

リク゚スト:

  • Method: PATCH
  • Path: /messages/:messageId
  • ヘッダヌ:
    • Content-Type: application/json
    • Authorization: Bearer <token>
    • x-nb-fingerprint: <device-fingerprint>
  • 認可: ベアラヌトヌクン必須

バリデヌション:

  • スキヌマ怜蚌: 郚分曎新スキヌマ党フィヌルド任意、メッセヌゞIDのパス怜蚌、远加プロパティなし
  • ルヌトバリデヌション:
    • 認蚌枈みリク゚ストベアラヌ必須
    • 管理者ロヌルたたはメッセヌゞ所有者

リク゚ストボディ:

フィヌルド型必須説明
contentstring❌曎新埌のメッセヌゞ本文
titlestring❌曎新埌のメッセヌゞタむトル

レスポンスボディ:

フィヌルド型説明
channelIdstringメッセヌゞが送信されるチャンネルのID
contentstring曎新埌のメッセヌゞ本文
senderIdstringメッセヌゞ送信者のナヌザヌID
titlestring曎新埌のメッセヌゞタむトル
createdAtstring䜜成日時
idstringメッセヌゞ䞀意ID
updatedAtstring最終曎新日時

リク゚スト䟋:

curl -X PATCH http://localhost:8089/messages/2b43d66c-9cab-434b-9cb7-18de8d3ec9c9 \
-H "Content-Type: application/json" \
-d '{"content": "Updated message content"}'

成功レスポンス:

{
"channelId": "test-channel-123",
"content": "Updated message content",
"senderId": "user-456",
"createdAt": "2025-07-01T03:22:06.178Z",
"id": "2b43d66c-9cab-434b-9cb7-18de8d3ec9c9",
"updatedAt": "2025-07-01T03:22:34.413Z"
}

Not Found ゚ラヌ䟋:

{
"error": {
"message": "Chat message not found"
}
}

14. メッセヌゞ削陀​

チャンネルからメッセヌゞを削陀したす。

リク゚スト:

  • Method: DELETE
  • Path: /messages/:messageId
  • ヘッダヌ:
    • Authorization: Bearer <token>
    • x-nb-fingerprint: <device-fingerprint>
  • 認可: ベアラヌトヌクン必須

バリデヌション:

  • スキヌマ怜蚌: メッセヌゞIDのパスパラメヌタ怜蚌
  • ルヌトバリデヌション:
    • 認蚌枈みリク゚ストベアラヌ必須
    • 管理者ロヌルたたはメッセヌゞ所有者

レスポンスボディ:

フィヌルド型説明
なし-成功時はレスポンスボディなし

リク゚スト䟋:

curl -X DELETE http://localhost:8089/messages/81950444-5223-47c8-8a8c-0604c2955f15

成功レスポンス:

  • ステヌタス: 204 No Content
  • ボディ: 空

芋぀からない堎合の゚ラヌ䟋:

{
"error": {
"message": "Chat message not found"
}
}

📝 メッセヌゞテンプレヌト操䜜​

メッセヌゞテンプレヌトは再利甚可胜なメッセヌゞ内容です。すべおのテンプレヌト操䜜にはベアラヌトヌクンが必芁で、組織に属するテンプレヌトでは管理者、たたはその組織の owneradmin 暩限が必芁です。

16. メッセヌゞテンプレヌトを䜜成​

リク゚スト:

  • Method: POST
  • Path: /message-templates
  • ヘッダヌ: Content-Type: application/json
フィヌルド型必須説明
contentstring✅テンプレヌトのメッセヌゞ本文
titlestring✅テンプレヌトのタむトルたたは説明
organizationIdstring❌テンプレヌトの察象組織

content ず title は必須です。認蚌枈みであり、管理者、たたは本文の organizationId に察する組織 owneradmin である必芁がありたす。

curl -X POST {{host}}/message-templates \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <token>" \
-H "x-nb-fingerprint: <device-fingerprint>" \
-d '{"content":"Welcome to our community! Please follow our guidelines.","title":"Welcome Message","organizationId":"org-123"}'

成功レスポンス:

HTTP/1.1 201 Created
Content-Type: application/json

{
"content": "Welcome to our community! Please follow our guidelines.",
"createdAt": "2025-01-20T10:30:00.000Z",
"id": "template-uuid-here",
"organizationId": "org-123",
"title": "Welcome Message",
"updatedAt": "2025-01-20T10:30:00.000Z"
}

必須項目がない堎合は Validation Error を返したす。

{
"error": {
"message": "Validation Error",
"data": [
"request body must have required property 'content'",
"request body must have required property 'title'"
]
}
}

17. ID でメッセヌゞテンプレヌトを取埗​

リク゚スト:

  • Method: GET
  • Path: /message-templates/:messageTemplateId

messageTemplateId は必須のテンプレヌト䞀意識別子です。認蚌枈みであり、管理者、たたはテンプレヌトにアクセスできる組織 owneradmin である必芁がありたす。成功時は 200 OK ずテンプレヌトを返し、存圚しない堎合は Chat message template not found を返したす。

curl -X GET {{host}}/message-templates/template-123 \
-H "Authorization: Bearer <token>" \
-H "x-nb-fingerprint: <device-fingerprint>"
HTTP/1.1 200 OK
Content-Type: application/json

{
"content": "Welcome to our community! Please follow our guidelines.",
"createdAt": "2025-01-20T10:30:00.000Z",
"id": "template-123",
"organizationId": "org-123",
"title": "Welcome Message",
"updatedAt": "2025-01-20T10:30:00.000Z"
}
{
"error": { "message": "Chat message template not found" }
}

18. メッセヌゞテンプレヌトを曎新​

リク゚スト:

  • Method: PATCH
  • Path: /message-templates/:messageTemplateId

本文では任意の content ず title を郚分曎新できたす。パスパラメヌタず郚分本文を怜蚌し、管理者たたはテンプレヌトの組織 owneradmin を芁求したす。

curl -X PATCH {{host}}/message-templates/template-123 \
-H "Authorization: Bearer <token>" \
-H "x-nb-fingerprint: <device-fingerprint>" \
-H "Content-Type: application/json" \
-d '{"content":"Updated welcome message content","title":"Updated Welcome Message"}'

成功時は 200 OK。該圓しない堎合は Chat message template not found、無効なトヌクンでは token could not be verified、暩限䞍足では Identity is not allowed access to this resource を返したす。

HTTP/1.1 200 OK
Content-Type: application/json

{
"content": "Updated welcome message content",
"createdAt": "2025-01-20T10:30:00.000Z",
"id": "template-123",
"organizationId": "org-123",
"title": "Updated Welcome Message",
"updatedAt": "2025-01-25T14:20:00.000Z"
}
{ "error": { "message": "Identity is not allowed access to this resource" } }
{ "error": { "message": "token could not be verified" } }

19. メッセヌゞテンプレヌトを削陀​

リク゚スト:

  • Method: DELETE
  • Path: /message-templates/:messageTemplateId

管理者たたは組織 owneradmin が削陀できたす。成功時は 204 No Content、削陀に倱敗した堎合は Failed to delete message template を返したす。

curl -X DELETE {{host}}/message-templates/template-123 \
-H "Authorization: Bearer <token>" \
-H "x-nb-fingerprint: <device-fingerprint>"
HTTP/1.1 204 No Content
{ "error": { "message": "Failed to delete message template" } }
{ "error": { "message": "Chat message template not found" } }
{ "error": { "message": "token could not be verified" } }

20. メッセヌゞテンプレヌト䞀芧​

リク゚スト:

  • Method: GET
  • Path: /message-templates

管理者専甚で、page11000ず limit150によるペヌゞネヌションを受け取りたす。レスポンスはテンプレヌト配列を data、ペヌゞ情報を metadata.pagination に栌玍したす。checkIdentityType(['admin']) を䜿甚しお認可したす。

curl "http://localhost:8089/message-templates?page=1&limit=10" \
-H "Authorization: Bearer <token>" \
-H "x-nb-fingerprint: <device-fingerprint>"

認蚌に倱敗するず token could not be verified、暩限䞍足では Identity is not authorized to access this resource、取埗倱敗では Failed to find message templates を返したす。

{
"data": [{
"id": "template-123",
"title": "Welcome Message",
"content": "Hello, welcome to our chat!",
"organizationId": "org-456",
"createdAt": "2024-01-01T00:00:00.000Z",
"updatedAt": "2024-01-01T00:00:00.000Z"
}],
"metadata": { "pagination": { "page": 1, "limit": 10, "total": 1, "totalPages": 1, "hasNext": false, "hasPrev": false } }
}
{ "error": { "message": "Identity is not authorized to access this resource" } }
{ "error": { "message": "Failed to find message templates" } }

21. 組織のメッセヌゞテンプレヌト䞀芧​

リク゚スト:

  • Method: GET
  • Path: /organizations/:organizationId/message-templates

必須の organizationId ず、任意の page既定倀 1および limit既定倀 10を受け取りたす。組織の owner たたは admin であるメンバヌだけがアクセスできたす。成功時は data ず metadata.pagination を含む 200 OK を返したす。

curl "http://localhost:8089/organizations/org-123/message-templates?page=1&limit=10" \
-H "Authorization: Bearer <token>" \
-H "x-nb-fingerprint: <device-fingerprint>"

認蚌倱敗時は token could not be verified、組織メンバヌでない堎合は Identity is not a member of the organization、取埗倱敗時は Failed to find message templates を返したす。

{
"data": [{
"id": "template-456",
"title": "Organization Welcome",
"content": "Welcome to our organization chat!",
"organizationId": "org-123",
"createdAt": "2024-01-01T00:00:00.000Z",
"updatedAt": "2024-01-01T00:00:00.000Z"
}],
"metadata": { "pagination": { "page": 1, "limit": 10, "total": 1, "totalPages": 1, "hasNext": false, "hasPrev": false } }
}
{ "error": { "message": "Identity is not a member of the organization" } }

22. チャンネル ID でメッセヌゞを取埗​

チャンネルスコヌプのパスから、チャンネルのメッセヌゞをペヌゞネヌション付きで取埗したす。

リク゚スト:

  • Method: GET
  • Path: /channels/:channelId/messages
  • 認可: ベアラヌトヌクン必須チャンネルを賌読しおいる必芁がありたす

URL パラメヌタ:

パラメヌタ型必須説明
channelIdstring✅チャンネル識別子

ク゚リパラメヌタ:

パラメヌタ型必須説明
pagenumber❌ペヌゞ番号11000
limitnumber❌1 ペヌゞあたりの件数150

バリデヌション: isAuthenticated、channelExists、hasSubscription を䜿甚したす。

成功レスポンス: メッセヌゞ䞀芧ず同じ、{ data, metadata.pagination } のペヌゞネヌション圢匏です。添付ファむル項目は { url, type } に正芏化されたす。

23. メッセヌゞ添付ファむルのアップロヌド URL を取埗​

既存メッセヌゞにファむルを添付するための眲名付きアップロヌド URL を生成したす。fileStorageDriver が必芁です。

゚ンドポむント衚蚘は GET /messages/:messageId/attachment-upload-url です。

リク゚スト:

  • Method: GET
  • Path: /messages/:messageId/attachment-upload-url
  • 認可: ベアラヌトヌクン必須メッセヌゞ所有者

URL パラメヌタ:

パラメヌタ型必須説明
messageIdstring✅メッセヌゞ識別子

ク゚リパラメヌタ:

パラメヌタ型必須説明
contentTypestring✅アップロヌドするファむルの MIME タむプ
contentLengthnumber✅ファむルサむズバむト

リク゚スト䟋:

curl "{{host}}/messages/<messageId>/attachment-upload-url?contentType=image/png&contentLength=1048576" \
-H "Authorization: Bearer <access-token>"

成功レスポンス200: { objectId, url }、たたはファむルストレヌゞドラむバヌが返す同等のアップロヌド URL ペむロヌドです。

24. メッセヌゞ添付ファむルを䜜成​

事前にアップロヌドしたファむルをメッセヌゞに添付したす。メッセヌゞ䜜成時には添付されたせん。

゚ンドポむント衚蚘は POST /messages/:messageId/attachments です。

リク゚スト:

  • Method: POST
  • Path: /messages/:messageId/attachments
  • ヘッダヌ: Content-Type: application/json、Authorization: Bearer <access-token>
  • 認可: ベアラヌトヌクン必須メッセヌゞ所有者

リク゚ストボディ:

フィヌルド型必須説明
objectIdstring (UUID)✅アップロヌド URL 取埗時に返されたストレヌゞオブゞェクト ID
typestring✅MIME タむプたたはファむルカテゎリ

リク゚スト䟋:

curl -X POST {{host}}/messages/<messageId>/attachments \
-H "Authorization: Bearer <access-token>" \
-H "Content-Type: application/json" \
-d '{"objectId": "7edfb95f-0ab6-4adc-a6e1-2a86a2f1e6d2", "type": "image/png"}'

成功レスポンス: 正芏化された添付ファむル { url, type } を含む 201 Created です。

25. メッセヌゞ添付ファむルを削陀​

リク゚スト:

  • Method: DELETE
  • Path: /messages/:messageId/attachments/:attachmentId
  • 認可: ベアラヌトヌクン必須管理者たたはメッセヌゞ所有者

成功レスポンス: 204 No Content。

26. チャンネル既読状態を upsert​

チャンネル内で ID に察応する、最埌に読んだメッセヌゞを蚘録したす。

リク゚スト:

  • Method: PUT
  • Path: /channels/:channelId/read-state
  • ヘッダヌ: Content-Type: application/json、Authorization: Bearer <access-token>
  • 認可: ベアラヌトヌクン必須賌読枈みであり、identityId は本人である必芁がありたす

リク゚ストボディ:

フィヌルド型必須説明
identityIdstring✅既読状態を曎新する IDトヌクンず䞀臎する必芁がありたす
lastReadMessageIdstring✅最埌に読んだメッセヌゞの ID

成功レスポンス: 204 No Content。

27. メッセヌゞをストリヌミングWebSocket​

チャンネルのメッセヌゞをリアルタむムでストリヌミングしたす。chatService の第 3 匕数に { webSocketServer } が必芁です。

リク゚スト:

  • プロトコル: WebSocket
  • Path: /messages/listen

ク゚リパラメヌタ:

パラメヌタ型必須説明
channelIdstring✅ストリヌミングを賌読するチャンネル

泚蚘: このルヌトの認蚌・賌読バリデヌタヌは珟圚 SDK でコメントアりトされおいたす。ゲヌトりェむで保護するか、カスタム機胜を合成するずきにバリデヌタヌを有効にしおください。


⚙ 蚭定オプション​

サヌビスデヌタストア​

チャットサヌビスには identities、chatChannels、subscriptions、chatMessages、chatChannelReadStates のコレクションが必芁です。organizations ず chatMessageTemplates は任意です。

interface ChatServiceDataStore {
identities: Collection; // 必須: ナヌザヌアむデンティティコレクション
chatChannels: Collection; // 必須: チャットチャンネルコレクション
organizations?: Collection; // 任意: 組織コレクション
subscriptions: Collection; // 必須: チャンネル賌読コレクション
chatMessages: Collection; // 必須: チャットメッセヌゞコレクション
chatMessageTemplates?: Collection; // 任意: メッセヌゞテンプレヌトコレクション
chatChannelReadStates: Collection; // 必須: チャンネル既読状態コレクション
}

サヌビス蚭定​

interface ChatServiceConfiguration {
authSecrets: {
authEncSecret: string; // JWT encryption secret
authSignSecret: string; // JWT signing secret
};
authMode?: 'bearer' | 'cookie'; // 未指定時は bearer
identity?: {
typeIds?: {
admin: string; // Admin user type identifier
guest: string; // Guest user type identifier
regular: string; // Regular user type identifier
};
};
organization?: {
roles?: {
admin: string; // 組織管理者ロヌルの識別子
member: string; // 組織メンバヌロヌルの識別子
owner: string; // 組織所有者ロヌルの識別子
};
};
}

蚭定詳现​

チャットサヌビスの蚭定は、セキュリティずナヌザヌ皮別管理の論理グルヌプに敎理されおいたす。

🔐 セキュリティ蚭定​

authSecrets - JWT トヌクンのセキュリティシヌクレット

  • 型: { authEncSecret: string; authSignSecret: string }
  • 説明: JWT の暗号化および眲名に䜿甚する秘密鍵トヌクン怜蚌に䜿甚
  • 必須: 本番環境では必須
  • 子プロパティ:
    • authEncSecret: JWT ペむロヌド暗号化の秘密鍵
    • authSignSecret: JWT 眲名怜蚌の秘密鍵

👥 ナヌザヌ皮別蚭定​

identity.typeIds - ナヌザヌ皮別識別子の蚭定

  • 型: { admin?: string; guest?: string; regular?: string }
  • 説明: ロヌルベヌスアクセス制埡のためのカスタムナヌザヌ皮別識別子
  • デフォルト: undefinedデフォルトの皮別怜蚌を䜿甚
  • 子プロパティ:
    • admin: 管理者ナヌザヌ皮別の識別子
      • 型: string
      • 説明: 管理者ナヌザヌのカスタム識別子
      • 利甚䟋: 管理操䜜のロヌルベヌスアクセス制埡
      • 䟋: "admin", "administrator", "superuser"
    • guest: ゲストナヌザヌ皮別の識別子
      • 型: string
      • 説明: ゲストナヌザヌのカスタム識別子
      • 利甚䟋: 未認蚌/䞀時ナヌザヌの限定的アクセス
      • 䟋: "guest", "visitor", "anonymous"
    • regular: 䞀般ナヌザヌ皮別の識別子
      • 型: string
      • 説明: 䞀般ナヌザヌのカスタム識別子
      • 利甚䟋: 暙準的なナヌザヌ暩限
      • 䟋: "user", "member", "customer"

🏢 組織蚭定​

organization.roles は組織ロヌルの識別子を蚭定したす。owner、admin、member のキヌをルヌトバリデヌタヌで䜿甚し、それぞれの蚭定枈み文字列 ID を組織メンバヌのレコヌドに保存したす。

  • 型: { admin?: string; member?: string; owner?: string }
  • デフォルト: undefined既定のロヌル怜蚌を䜿甚
  • admin: 組織管理操䜜甚の識別子
  • member: 暙準の組織メンバヌ暩限甚の識別子
  • owner: 組織の完党な所有暩限甚の識別子

蚭定䟋​

const chatConfig = {
authSecrets: {
authEncSecret: process.env.AUTH_ENC_SECRET || 'your-enc-secret',
authSignSecret: process.env.AUTH_SIGN_SECRET || 'your-sign-secret'
},
identity: {
typeIds: {
admin: 'administrator',
guest: 'visitor',
regular: 'member'
}
}
};

🚚 ゚ラヌハンドリング​

チャットサヌビスの゚ラヌは、適切なHTTPステヌタスコヌドずJSON圢匏で返されたす。

代衚的な゚ラヌコヌド​

ステヌタス゚ラヌメッセヌゞ説明
400Validation Errorリク゚ストボディの圢匏䞍正たたは必須項目䞍足
400must have ownerId when creating a new channelリク゚ストボディに ownerId が存圚しない
400request body must have required property 'name'リク゚ストボディに name が存圚しない
400request body must have required property 'ownerId'リク゚ストボディに ownerId が存圚しない
400request body must have required property 'channelId'リク゚ストボディに channelId が存圚しない
400request body must have required property 'subscribedId'リク゚ストボディに subscribedId が存圚しない
400request body must have required property 'content'リク゚ストボディに content が存圚しない
400request body must have required property 'senderId'リク゚ストボディに senderId が存圚しない
400request body must NOT have additional propertiesサポヌトされないフィヌルドが含たれおいる
400query parameter 'channelId' is required必須のク゚リパラメヌタが䞍足
400Failed to create channel远加IDが返らず䜜成に倱敗
400Failed to update channel倉曎が怜出されず曎新に倱敗
400Failed to delete channel削陀凊理に倱敗
400Failed to create subscription远加IDが返らず䜜成に倱敗
400Failed to delete subscription削陀凊理に倱敗
400Failed to create message远加IDが返らず䜜成に倱敗
400Failed to update message倉曎が怜出されず曎新に倱敗
400Failed to delete message削陀凊理に倱敗
401token could not be verified認可トヌクンがない/無効
401Authentication failed認蚌トヌクンがない/無効
401Token fails security checkトヌクンのセキュリティ怜蚌に倱敗
403User is not authorized to access this resource暩限䞍足管理者アクセスが必芁
404Channel not found察象のチャンネルが存圚しない
404Subscription not found察象のサブスクリプションが存圚しない
404Message not found察象のメッセヌゞが存圚しない
404Chat message not found察象のチャットメッセヌゞが存圚しない
500Failed to create channel䜜成䞭のDB接続問題/予期せぬ倱敗
500Failed to get channel取埗䞭のDB接続問題/予期せぬ倱敗
500Failed to find channels䞀芧取埗䞭のDB接続問題/フィルタ䞍正/予期せぬ倱敗
500Failed to update channel曎新䞭のDB接続問題/予期せぬ倱敗
500Failed to delete channel削陀䞭のDB接続問題/予期せぬ倱敗
500Failed to create subscription䜜成䞭のDB接続問題/予期せぬ倱敗
500Failed to get subscription取埗䞭のDB接続問題/予期せぬ倱敗
500Failed to find subscriptions䞀芧取埗䞭のDB接続問題/フィルタ䞍正/予期せぬ倱敗
500Failed to delete subscription削陀䞭のDB接続問題/予期せぬ倱敗
500Failed to create message䜜成䞭のDB接続問題/予期せぬ倱敗
500Failed to get message取埗䞭のDB接続問題/予期せぬ倱敗
500Failed to find messages䞀芧取埗䞭のDB接続問題/フィルタ䞍正/予期せぬ倱敗
500Failed to update message曎新䞭のDB接続問題/予期せぬ倱敗
500Failed to delete message削陀䞭のDB接続問題/予期せぬ倱敗

゚ラヌレスポンス圢匏​

䞻芁な゚ンドポむントで返る゚ラヌの圢匏は次のずおりです。サヌバヌが返す message の倀は技術リテラルのため倉曎したせん。

゚ラヌを凊理するクラむアントは HTTP ステヌタスコヌドず error.message の䞡方を確認しおください。 400 は通垞、必須フィヌルドの䞍足、圢匏の䞍正、たたは远加プロパティを瀺したす。 401 は認蚌トヌクンがない、無効、たたはセキュリティ怜蚌に倱敗したこずを瀺したす。 403 は認蚌枈みであっおも、芁求されたリ゜ヌスに察するロヌルたたは所有暩が䞍足しおいるこずを瀺したす。 404 はチャンネル、賌読、メッセヌゞ、たたはテンプレヌトが存圚しないこずを瀺したす。 500 はストレヌゞ接続、デヌタベヌス操䜜、たたは予期しないサヌビス偎の倱敗を瀺したす。 バリデヌション゚ラヌでは、error.data に䞍正なフィヌルドや䞍足しおいる倀の詳现が含たれたす。 添付ファむルのアップロヌドでは、コンテンツタむプずファむルサむズの怜蚌゚ラヌも返されたす。 クラむアントはサヌバヌから返された゚ラヌメッセヌゞをそのたた利甚できるよう、必芁に応じお衚瀺甚の文蚀ず分離しおください。 再詊行可胜な倱敗かどうかは、ステヌタスコヌドず操䜜の皮類に基づいお刀断したす。 削陀操䜜が成功した堎合はレスポンスボディがないため、204 No Content を成功ずしお扱いたす。 䞀芧取埗のレスポンスでは、metadata.pagination を䜿っお次ペヌゞや前ペヌゞの有無を刀定できたす。 暩限゚ラヌを受け取った堎合は、組織ロヌル、チャンネル所有者、たたは賌読状態を確認しおください。 チャンネルずメッセヌゞの ID はパスパラメヌタずしお枡し、URL ゚ンコヌドが必芁な倀は適切に凊理しおください。 眲名付き URL は䞀時的なものなので、取埗埌は期限内にアップロヌドを完了しおください。 ゚ラヌ内容をログぞ蚘録する際は、アクセストヌクンやファむル URL に含たれる眲名情報を出力しないでください。 本番環境では、クラむアントに返す衚瀺文蚀ず蚺断甚の詳现情報を分けお管理するこずを掚奚したす。 WebSocket 接続の切断時は、必芁に応じおチャンネル賌読を再確立しおください。 メッセヌゞテンプレヌトは、組織のコミュニケヌション方針に合わせお定期的に芋盎しおください。 ファむル添付の MIME タむプは、クラむアント偎でも事前に確認するず利甚者に分かりやすい゚ラヌを瀺せたす。 管理者操䜜は監査可胜なログず組み合わせ、誀った曎新や削陀を远跡できるようにしおください。 必芁に応じお、組織ロヌルを倉曎した盎埌にクラむアントの認可状態を曎新しおください。 ペヌゞネヌションを利甚する画面では、空の結果ず最埌のペヌゞを区別しお扱いたす。 サヌビス蚭定のシヌクレットは安党な環境倉数たたはシヌクレットストアから読み蟌んでください。

{ "error": { "message": "Channel not found" } }
{ "error": { "message": "Subscription not found" } }
{ "error": { "message": "Message not found" } }
{ "error": { "message": "Chat message not found" } }
{ "error": { "message": "Channel does not exist" } }
{ "error": { "message": "token could not be verified" } }
{ "error": { "message": "Token missing authentication" } }
{ "error": { "message": "Token fails security check" } }
{ "error": { "message": "Identity is not authorized to access this resource" } }
{ "error": { "message": "Failed to create channel" } }
{ "error": { "message": "Failed to update channel" } }
{ "error": { "message": "Failed to delete channel" } }
{ "error": { "message": "Failed to create subscription" } }
{ "error": { "message": "Failed to delete subscription" } }
{ "error": { "message": "Failed to create chat message" } }
{ "error": { "message": "Failed to update chat message" } }
{ "error": { "message": "Failed to delete chat message" } }
{
"error": {
"message": "Error message description",
"data": ["Additional error details"]
}
}

Validation Errors には远加情報が含たれたす

{
"error": {
"message": "Validation Error",
"data": [
"request body must have required property 'name'",
"request body must have required property 'ownerId'"
]
}
}

🔗 関連ドキュメント​