Fizz RPC メソッド
FizzWorker はチャット・一括配信・WebSocket 管理を担当するサービスです。WorkerEntrypoint<Env> を継承し、23の RPC メソッドを公開します。
チャットルーム
Section titled “チャットルーム”listChatRooms
Section titled “listChatRooms”チャットルーム一覧をカーソルページネーションで取得します。
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;}>getChatRoom
Section titled “getChatRoom”チャットルームの詳細を取得します。連絡先情報・チャットNG状態・purelovers情報を含みます。
async getChatRoom(params: { readonly roomId: string; readonly shopId: string; readonly userId: string; readonly userType: 'shop' | 'customer';}): Promise<ChatRoomDetail | null>initChatRoom
Section titled “initChatRoom”チャットルームを作成、または既存のルームを取得します。
async initChatRoom(params: { readonly shopId: string; readonly contactId: string;}): Promise<{ readonly roomId: string; readonly chatRoom: ChatRoom; readonly created: boolean;}>getChatMessages
Section titled “getChatMessages”チャットメッセージをカーソルページネーションで取得します。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;}>sendChatMessage
Section titled “sendChatMessage”メッセージを送信します。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>searchMessages
Section titled “searchMessages”メッセージを全文検索します(過去365日以内)。
async searchMessages(params: { readonly shopId: string; readonly query: string; readonly limit?: number;}): Promise<readonly SearchResult[]>markAsRead
Section titled “markAsRead”チャットルームを既読にします。相手側に既読通知が WebSocket で配信されます。
async markAsRead(params: { readonly roomId: string; readonly userId: string; readonly userType: 'shop' | 'customer';}): Promise<{ readonly success: boolean; readonly lastReadAt: Date;}>getCustomerLastReadAt
Section titled “getCustomerLastReadAt”顧客の最終既読日時を取得します。
async getCustomerLastReadAt(params: { readonly roomId: string;}): Promise<{ readonly lastReadAt: string | null;}>listBroadcasts
Section titled “listBroadcasts”一括配信一覧をステータスフィルタリングで取得します。
async listBroadcasts(params: { readonly shopId: string; readonly status?: string;}): Promise<readonly Broadcast[]>createBroadcast
Section titled “createBroadcast”一括配信を作成します。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>updateBroadcast
Section titled “updateBroadcast”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>cancelBroadcast
Section titled “cancelBroadcast”DRAFT/SCHEDULED/QUEUED 状態の配信をキャンセルします。
async cancelBroadcast(id: string): Promise<Broadcast>deleteBroadcast
Section titled “deleteBroadcast”DRAFT 状態の配信を削除します。
async deleteBroadcast(id: string): Promise<{ readonly success: boolean }>countBroadcastTargets
Section titled “countBroadcastTargets”配信条件に合致するターゲット数を取得します。
async countBroadcastTargets(params: { readonly shopId: string; readonly criteria: Record<string, unknown>;}): Promise<number>listBroadcastTargets
Section titled “listBroadcastTargets”配信対象の連絡先一覧をページネーションで取得します。
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;}>listBroadcastRecipients
Section titled “listBroadcastRecipients”送信済み配信の実際の受信者一覧を取得します。
async listBroadcastRecipients(params: { readonly broadcastId: string; readonly cursor?: string; readonly limit?: number;}): Promise<{ readonly contacts: readonly Contact[]; readonly hasMore: boolean;}>WebSocket・在席管理
Section titled “WebSocket・在席管理”broadcast
Section titled “broadcast”Durable Objects 経由で全接続クライアントにメッセージをブロードキャストします。
async broadcast(payload: BroadcastPayload): Promise<void>notify
Section titled “notify”特定ユーザーに Durable Objects 経由で通知を送信します。
async notify(payload: NotifyPayload): Promise<void>getShopAvailability
Section titled “getShopAvailability”店舗のチャット受付ステータスを取得します。
async getShopAvailability(params: { readonly shopId: string;}): Promise<{ readonly status: 'online' | 'away'; readonly mode: 'auto' | 'manual';}>updateShopAvailability
Section titled “updateShopAvailability”店舗の受付ステータスを更新し、全店舗ユーザーにブロードキャストします。
async updateShopAvailability(params: { readonly shopId: string; readonly status: 'online' | 'away'; readonly mode: 'auto' | 'manual';}): Promise<{ readonly success: boolean;}>Cron・Queue
Section titled “Cron・Queue”scheduled
Section titled “scheduled”毎時実行の Cron ハンドラ。SCHEDULED 状態の配信を QUEUED に移行します(配信8時間前から)。
broadcast-queue のコンシューマ。バッチ単位で配信メッセージを処理し、リトライロジックを含みます。