Skip to main content
Version: 🚧 Canary

💬 Chat Blocks

Chat blocks provide comprehensive functionality for real-time communication in Nodeblocks applications. These blocks handle chat lifecycle operations including channels, messages, and subscriptions.


🎯 Overview

Chat blocks are designed to:

  • Manage chat channels with full CRUD operations
  • Handle message exchange and real-time communication
  • Support secure file attachments with signed URLs and malicious file type filtering
  • Stream messages in real-time via WebSocket with MongoDB change streams
  • Track read states to mark which messages users have read in channels
  • Provide message template management for reusable content
  • Provide subscription management for notifications
  • Support multi-channel communication
  • Enable chat administration with comprehensive controls

📦 Block Types

🔍 Schemas

JSON Schema definitions for chat data validation:

  • ChatChannelIcon: TypeScript type for channel icon metadata
  • chatChannelSchema: Base channel entity structure
  • createChatChannelSchema: Channel creation validation
  • updateChatChannelSchema: Channel modifications
  • getChatChannelSchema: Channel retrieval
  • deleteChatChannelSchema: Channel deletion
  • findChatChannelsSchema: Channel search with filtering and pagination
  • getChannelMessagesSchema: Channel messages retrieval validation
  • chatMessageSchema: Message entity structure
  • chatMessageAttachmentSchema: Message attachment validation with objectId and type
  • createChatMessageAttachmentSchema: Attachment creation validation for adding files to existing messages
  • deleteChatMessageAttachmentSchema: Attachment deletion validation with messageId and attachmentId path parameters
  • createChatMessageSchema: Message creation validation with attachments support
  • updateChatMessageSchema: Message modifications
  • getChatMessageSchema: Message retrieval
  • deleteChatMessageSchema: Message deletion
  • findChatMessagesSchema: Message search with filtering and pagination
  • channelIdQueryParameter: WebSocket query parameter for channel ID
  • streamChatMessagesSchema: Real-time message streaming validation
  • chatMessageTemplateSchema: Message template entity structure
  • createChatMessageTemplateSchema: Message template creation validation
  • getChatMessageTemplateSchema: Message template retrieval validation
  • updateChatMessageTemplateSchema: Message template modifications
  • deleteChatMessageTemplateSchema: Message template deletion validation
  • findChatMessageTemplatesSchema: Message template search with filtering and pagination
  • findChatMessageTemplatesForOrganizationSchema: Organization-scoped message template search with pagination
  • chatSubscriptionSchema: Subscription entity structure
  • createChatSubscriptionSchema: Subscription creation validation
  • getChatSubscriptionSchema: Subscription retrieval
  • deleteChatSubscriptionSchema: Subscription deletion
  • findChatSubscriptionsSchema: Subscription search with filtering and pagination
  • chatChannelReadStateSchema: Channel read state entity structure
  • upsertChatChannelReadStateSchema: Channel read state upsert validation

View Chat Schemas →

🔧 Blocks

Pure business logic functions for chat operations:

View Chat Block Functions →

⚙️ Handlers

Core business logic for chat operations:

  • Channel Operations: createChatChannel, getChatChannelById, findChatChannels, updateChatChannel, deleteChatChannel
  • Channel Terminator Functions: createChatChannelTerminator, normalizeChatChannelTerminator, normalizeChatChannelsListTerminator, deleteChatChannelTerminator
  • Message Operations: createChatMessage, getChatMessageById, findChatMessages, updateChatMessage, deleteChatMessage
  • Message Terminator Functions: createChatMessageTerminator, normalizeChatMessageTerminator, normalizeChatMessagesListTerminator, deleteChatMessageTerminator
  • Subscription Operations: createChatSubscription, getChatSubscriptionById, findChatSubscriptions, deleteChatSubscription
  • Subscription Terminator Functions: createChatSubscriptionTerminator, normalizeChatSubscriptionTerminator, normalizeChatSubscriptionsListTerminator, deleteChatSubscriptionTerminator

View Chat Handlers →

🛣️ Routes

HTTP and WebSocket endpoint definitions for chat operations:

  • Channel Routes: createChatChannelRoute, getChatChannelRoute, findChatChannelsRoute, updateChatChannelRoute, deleteChatChannelRoute, getChannelMessagesRoute, getChatChannelIconUploadUrlRoute
  • Message Routes: createChatMessageRoute, getChatMessageRoute, findChatMessagesRoute, updateChatMessageRoute, deleteChatMessageRoute, getChatMessageAttachmentUploadUrlRoute, createChatMessageAttachmentRoute, deleteChatMessageAttachmentRoute, streamChatMessagesRoute (WebSocket)
  • Message Template Routes: createChatMessageTemplateRoute, getChatMessageTemplateRoute, updateChatMessageTemplateRoute, findChatMessageTemplatesRoute, findChatMessageTemplatesForOrganizationRoute, deleteChatMessageTemplateRoute
  • Subscription Routes: createChatSubscriptionRoute, getChatSubscriptionRoute, findChatSubscriptionsRoute, deleteChatSubscriptionRoute
  • Channel Read State Routes: upsertChatChannelReadStateRoute

View Chat Routes →

🚀 Features

Composed chat features for easy integration:

  • Channel Features: createChannelFeature, getChannelFeature, findChannelsFeature, updateChannelFeature, deleteChannelFeature, getChannelMessagesFeature, getChannelIconUploadUrlFeature
  • Message Features: createChatMessageFeature, getChatMessageFeature, findChatMessagesFeature, updateChatMessageFeature, deleteChatMessageFeature, getChatMessageAttachmentUrlFeature, createChatMessageAttachmentFeature, deleteChatMessageAttachmentFeature, streamChatMessagesFeature (WebSocket)
  • Message Template Features: createChatMessageTemplateFeature, getChatMessageTemplateFeature, updateChatMessageTemplateFeature, findChatMessageTemplatesFeature, findChatMessageTemplatesForOrganizationFeature, deleteChatMessageTemplateFeature
  • Subscription Features: createChatSubscriptionFeature, getChatSubscriptionFeature, findChatSubscriptionsFeature, deleteChatSubscriptionFeature
  • Channel Read State Features: upsertChatChannelReadStateFeature

View Chat Features →

Validators

Validation functions for chat operations:

  • channelExists: Validates that a chat channel exists in the database
  • hasSubscription: Validates that an identity is subscribed to a channel
  • ownsSubscription: Validates subscription ownership by the subscribed identity
  • ownsChannel: Validates channel ownership by the identity
  • ownsMessage: Validates message ownership by the sender
  • hasOrganizationAccessToMessageTemplate: Validates org role-based access to message templates
  • validateChannelAccess (deprecated): Legacy access validator; replaced by ownsChannel
  • validateMessageAccess (deprecated): Legacy access validator; replaced by ownsMessage

View Chat Validators →