コンテンツにスキップ

検索はプロダクションビルドでのみ利用可能です。 ローカルでテストするには、サイトをビルドしてプレビューしてください。

Fizz RPC メソッド

FizzWorker はチャット・一括配信・WebSocket 管理を担当するサービスです。WorkerEntrypoint<Env> を継承し、23の RPC メソッドを公開します。


チャットルーム一覧をカーソルページネーションで取得します。

async listChatRooms(params: {
readonly shopId: string;
readonly userId: string;
readonly userType: 'shop' | 'customer';
readonly limit?: number;
readonly cursor?: string;
readonly unreadOnly?: boolean;
}): Promise<{
readonly chatRooms: readonly ChatRoom[];
readonly nextCursor: string | null;
readonly hasMore: boolean;
}>

チャットルームの詳細を取得します。連絡先情報・チャットNG状態・purelovers情報を含みます。

async getChatRoom(params: {
readonly roomId: string;
readonly shopId: string;
readonly userId: string;
readonly userType: 'shop' | 'customer';
}): Promise<ChatRoomDetail | null>

チャットルームを作成、または既存のルームを取得します。

async initChatRoom(params: {
readonly shopId: string;
readonly contactId: string;
}): Promise<{
readonly roomId: string;
readonly chatRoom: ChatRoom;
readonly created: boolean;
}>

チャットメッセージをカーソルページネーションで取得します。displayDays を超えたメッセージは除外されます。

async getChatMessages(params: {
readonly roomId: string;
readonly cursor?: string;
readonly limit?: number;
}): Promise<{
readonly messages: readonly ChatMessage[];
readonly nextCursor: string | null;
readonly hasMore: boolean;
}>

メッセージを送信します。DB保存後、Durable Objects 経由で WebSocket 配信し、通知キューにも投入します。

async sendChatMessage(params: {
readonly roomId: string;
readonly senderId: string;
readonly senderType: 'shop' | 'customer';
readonly content: string;
readonly contentType?: 'text' | 'image' | 'file';
readonly messageType?: 'normal' | 'broadcast' | 'system';
readonly displayDays?: number;
readonly metadata?: Record<string, unknown>;
}): Promise<ChatMessage>

メッセージを全文検索します(過去365日以内)。

async searchMessages(params: {
readonly shopId: string;
readonly query: string;
readonly limit?: number;
}): Promise<readonly SearchResult[]>

チャットルームを既読にします。相手側に既読通知が WebSocket で配信されます。

async markAsRead(params: {
readonly roomId: string;
readonly userId: string;
readonly userType: 'shop' | 'customer';
}): Promise<{
readonly success: boolean;
readonly lastReadAt: Date;
}>

顧客の最終既読日時を取得します。

async getCustomerLastReadAt(params: {
readonly roomId: string;
}): Promise<{
readonly lastReadAt: string | null;
}>

一括配信一覧をステータスフィルタリングで取得します。

async listBroadcasts(params: {
readonly shopId: string;
readonly status?: string;
}): Promise<readonly Broadcast[]>

一括配信を作成します。8時間以内の配信は即座にキューイングされます。

async createBroadcast(params: {
readonly shopId: string;
readonly title?: string;
readonly content: string;
readonly status: string;
readonly scheduledAt?: string;
readonly criteria?: Record<string, unknown>;
}): Promise<Broadcast>

DRAFT/SCHEDULED 状態の配信を更新します。ターゲット数が再計算されます。

async updateBroadcast(params: {
readonly id: string;
readonly title?: string;
readonly content?: string;
readonly status?: string;
readonly scheduledAt?: string;
readonly criteria?: Record<string, unknown>;
}): Promise<Broadcast>

DRAFT/SCHEDULED/QUEUED 状態の配信をキャンセルします。

async cancelBroadcast(id: string): Promise<Broadcast>

DRAFT 状態の配信を削除します。

async deleteBroadcast(id: string): Promise<{ readonly success: boolean }>

配信条件に合致するターゲット数を取得します。

async countBroadcastTargets(params: {
readonly shopId: string;
readonly criteria: Record<string, unknown>;
}): Promise<number>

配信対象の連絡先一覧をページネーションで取得します。

async listBroadcastTargets(params: {
readonly shopId: string;
readonly criteria: Record<string, unknown>;
readonly cursor?: string;
readonly limit?: number;
}): Promise<{
readonly contacts: readonly Contact[];
readonly hasMore: boolean;
}>

送信済み配信の実際の受信者一覧を取得します。

async listBroadcastRecipients(params: {
readonly broadcastId: string;
readonly cursor?: string;
readonly limit?: number;
}): Promise<{
readonly contacts: readonly Contact[];
readonly hasMore: boolean;
}>

Durable Objects 経由で全接続クライアントにメッセージをブロードキャストします。

async broadcast(payload: BroadcastPayload): Promise<void>

特定ユーザーに Durable Objects 経由で通知を送信します。

async notify(payload: NotifyPayload): Promise<void>

店舗のチャット受付ステータスを取得します。

async getShopAvailability(params: {
readonly shopId: string;
}): Promise<{
readonly status: 'online' | 'away';
readonly mode: 'auto' | 'manual';
}>

店舗の受付ステータスを更新し、全店舗ユーザーにブロードキャストします。

async updateShopAvailability(params: {
readonly shopId: string;
readonly status: 'online' | 'away';
readonly mode: 'auto' | 'manual';
}): Promise<{
readonly success: boolean;
}>

毎時実行の Cron ハンドラ。SCHEDULED 状態の配信を QUEUED に移行します(配信8時間前から)。

broadcast-queue のコンシューマ。バッチ単位で配信メッセージを処理し、リトライロジックを含みます。