メインコンテンツまでスキップ
バージョン: 🚧 Canary

💬 Chat Route Blocks

Chat route blocks provide pre-configured HTTP endpoints for chat management operations in Nodeblocks applications. These routes combine handlers, validators, and middleware to create complete API endpoints with proper authentication, authorization, and error handling.


🎯 Overview

Chat route blocks are designed to:

  • Provide complete API endpoints for chat management operations
  • Combine handlers with validators for secure operations
  • Include authentication and authorization checks
  • Support functional composition patterns
  • Handle logging and error management automatically

📋 Route Structure

Each chat route follows a consistent pattern:

  • HTTP Method: Defines the operation type (GET, POST, PATCH, DELETE)
  • Path: Specifies the endpoint URL with parameters
  • Handler: Composed function chain for business logic
  • Validators: Authentication and authorization checks

🔧 Available Chat Routes

Channel Routes

createChatChannelRoute

Creates a new channel and returns the created resource.

Purpose: Handles channel creation with full resource retrieval

Route Details:

  • Method: POST
  • Path: /channels
  • Authentication: Required (Bearer token)

Handlers: createChatChannel, getChatChannelById, createChatChannelTerminator

Validators: isAuthenticated, some(checkIdentityType(['admin']), isSelf(['params', 'requestBody', 'ownerId']))

Usage:

import { routes } from '@nodeblocks/backend-sdk';

// Register route with Express app
app.use('/api', routes.createChatChannelRoute);

findChatChannelsRoute

Retrieves all channels with normalized list format.

Purpose: Lists channels with pagination

Route Details:

  • Method: GET
  • Path: /channels
  • Authentication: Required (Bearer token)

Handlers: findChatChannels, normalizeChatChannelsListTerminator

Validators: isAuthenticated, some(checkIdentityType(['admin']), isSelf(['params', 'requestQuery', 'ownerId']))

Usage:

import { routes } from '@nodeblocks/backend-sdk';

// Register route with Express app
app.use('/api', routes.findChatChannelsRoute);

getChatChannelRoute

Retrieves a specific channel by ID.

Purpose: Fetches channel data

Route Details:

  • Method: GET
  • Path: /channels/:channelId
  • Authentication: Required (Bearer token)

Handlers: getChatChannelById, normalizeChatChannelTerminator

Validators: isAuthenticated, some(checkIdentityType(['admin']), ownsChannel(['params', 'requestParams', 'channelId']), hasSubscription(['params', 'requestParams', 'channelId']))

Usage:

import { routes } from '@nodeblocks/backend-sdk';

// Register route with Express app
app.use('/api', routes.getChatChannelRoute);

updateChatChannelRoute

Updates an existing channel and returns the updated resource.

Purpose: Modifies channel data with access control

Route Details:

  • Method: PATCH
  • Path: /channels/:channelId
  • Authentication: Required (Bearer token)

Handlers: updateChatChannel, getChatChannelById, normalizeChatChannelTerminator

Validators: isAuthenticated, some(checkIdentityType(['admin']), ownsChannel(['params', 'requestParams', 'channelId']))

Usage:

import { routes } from '@nodeblocks/backend-sdk';

// Register route with Express app
app.use('/api', routes.updateChatChannelRoute);

deleteChatChannelRoute

Deletes a channel by ID.

Purpose: Removes channel with access control

Route Details:

  • Method: DELETE
  • Path: /channels/:channelId
  • Authentication: Required (Bearer token)

Handlers: deleteChatChannel, deleteChatChannelTerminator

Validators: isAuthenticated, some(checkIdentityType(['admin']), ownsChannel(['params', 'requestParams', 'channelId']))

Usage:

import { routes } from '@nodeblocks/backend-sdk';

// Register route with Express app
app.use('/api', routes.deleteChatChannelRoute);

Subscription Routes

createChatSubscriptionRoute

Creates a new subscription and returns the created resource.

Purpose: Handles subscription creation with full resource retrieval

Route Details:

  • Method: POST
  • Path: /subscriptions
  • Authentication: Required (Bearer token)

Handlers: createChatSubscription, getChatSubscriptionById, createChatSubscriptionTerminator

Validators: isAuthenticated, some(checkIdentityType(['admin']), isSelf(['params', 'requestBody', 'subscribedId']))

Usage:

import { routes } from '@nodeblocks/backend-sdk';

// Register route with Express app
app.use('/api', routes.createChatSubscriptionRoute);

findChatSubscriptionsRoute

Retrieves all subscriptions with normalized list format.

Purpose: Lists subscriptions with pagination

Route Details:

  • Method: GET
  • Path: /subscriptions
  • Authentication: Required (Bearer token)

Handlers: findChatSubscriptions, normalizeChatSubscriptionsListTerminator

Validators: isAuthenticated, some(checkIdentityType(['admin']), hasSubscription(['params', 'requestQuery', 'channelId']), ownsChannel(['params', 'requestQuery', 'channelId']), isSelf(['params', 'requestQuery', 'subscribedId']))

Usage:

import { routes } from '@nodeblocks/backend-sdk';

// Register route with Express app
app.use('/api', routes.findChatSubscriptionsRoute);

getChatSubscriptionRoute

Retrieves a specific subscription by ID.

Purpose: Fetches subscription data

Route Details:

  • Method: GET
  • Path: /subscriptions/:subscriptionId
  • Authentication: Required (Bearer token)

Handlers: getChatSubscriptionById, normalizeChatSubscriptionTerminator

Validators: isAuthenticated, some(checkIdentityType(['admin']), ownsSubscription(['params', 'requestParams', 'subscriptionId']))

Usage:

import { routes } from '@nodeblocks/backend-sdk';

// Register route with Express app
app.use('/api', routes.getChatSubscriptionRoute);

deleteChatSubscriptionRoute

Deletes a subscription by ID.

Purpose: Removes subscription

Route Details:

  • Method: DELETE
  • Path: /subscriptions/:subscriptionId
  • Authentication: Required (Bearer token)

Handlers: deleteChatSubscription, deleteChatSubscriptionTerminator

Validators: isAuthenticated, some(checkIdentityType(['admin']), ownsSubscription(['params', 'requestParams', 'subscriptionId']))

Usage:

import { routes } from '@nodeblocks/backend-sdk';

// Register route with Express app
app.use('/api', routes.deleteChatSubscriptionRoute);

Message Routes

createChatMessageRoute

Creates a new message and returns the created resource.

Purpose: Handles message creation with full resource retrieval

Route Details:

  • Method: POST
  • Path: /messages
  • Authentication: Required (Bearer token)

Handlers: createChatMessage, getChatMessageById, createChatMessageTerminator

Validators: isAuthenticated, isSelf(['params', 'requestBody', 'senderId']), hasSubscription(['params', 'requestBody', 'channelId'])

Usage:

import { routes } from '@nodeblocks/backend-sdk';

// Register route with Express app
app.use('/api', routes.createChatMessageRoute);

findChatMessagesRoute

Retrieves all messages with normalized list format.

Purpose: Lists messages with pagination

Route Details:

  • Method: GET
  • Path: /messages
  • Authentication: Required (Bearer token)

Handlers: findChatMessages, normalizeChatMessagesListTerminator

Validators: isAuthenticated, some(checkIdentityType(['admin']), hasSubscription(['params', 'requestQuery', 'channelId']), isSelf(['params', 'requestQuery', 'senderId']))

Usage:

import { routes } from '@nodeblocks/backend-sdk';

// Register route with Express app
app.use('/api', routes.findChatMessagesRoute);

getChatMessageRoute

Retrieves a specific message by ID.

Purpose: Fetches message data

Route Details:

  • Method: GET
  • Path: /messages/:messageId
  • Authentication: Required (Bearer token)

Handlers: getChatMessageById, normalizeChatMessageTerminator

Validators: isAuthenticated, some(checkIdentityType(['admin']), ownsMessage(['params', 'requestParams', 'messageId']))

Usage:

import { routes } from '@nodeblocks/backend-sdk';

// Register route with Express app
app.use('/api', routes.getChatMessageRoute);

updateChatMessageRoute

Updates an existing message and returns the updated resource.

Purpose: Modifies message data with access control

Route Details:

  • Method: PATCH
  • Path: /messages/:messageId
  • Authentication: Required (Bearer token)

Handlers: updateChatMessage, getChatMessageById, normalizeChatMessageTerminator

Validators: isAuthenticated, some(checkIdentityType(['admin']), ownsMessage(['params', 'requestParams', 'messageId']))

Usage:

import { routes } from '@nodeblocks/backend-sdk';

// Register route with Express app
app.use('/api', routes.updateChatMessageRoute);

deleteChatMessageRoute

Deletes a message by ID.

Purpose: Removes message with access control

Route Details:

  • Method: DELETE
  • Path: /messages/:messageId
  • Authentication: Required (Bearer token)

Handlers: deleteChatMessage, deleteChatMessageTerminator

Validators: isAuthenticated, some(checkIdentityType(['admin']), ownsMessage(['params', 'requestParams', 'messageId']))

Usage:

import { routes } from '@nodeblocks/backend-sdk';

// Register route with Express app
app.use('/api', routes.deleteChatMessageRoute);

Message Template Routes

createChatMessageTemplateRoute

Creates a new chat message template and returns the created resource.

Purpose: Handles message template creation with full resource retrieval

Route Details:

  • Method: POST
  • Path: /message-templates
  • Authentication: Required (Bearer token)

Handlers: createChatMessageTemplate, getChatMessageTemplateById, orThrow

Validators: isAuthenticated, some(checkIdentityType(['admin']), hasOrgRole(['owner','admin'], ['params','requestBody','organizationId']))

Usage:

import { routes } from '@nodeblocks/backend-sdk';

// Register route with Express app
app.use('/api', routes.createChatMessageTemplateRoute);

getChatMessageTemplateRoute

Retrieves a chat message template by ID.

Purpose: Fetches template data with organization access control

Route Details:

  • Method: GET
  • Path: /message-templates/:messageTemplateId
  • Authentication: Required (Bearer token)

Handlers: getChatMessageTemplateById, orThrow

Validators: isAuthenticated, some(checkIdentityType(['admin']), hasOrganizationAccessToMessageTemplate(['owner','admin'], ['params','requestParams','messageTemplateId']))

Usage:

import { routes } from '@nodeblocks/backend-sdk';

// Register route with Express app
app.use('/api', routes.getChatMessageTemplateRoute);