A Flows app for managing conversation messages with automatic TTL-based cleanup.
This app provides blocks for recording and retrieving conversation messages with configurable time-to-live (TTL) settings. It's designed to maintain conversation state temporarily, making it ideal for chat applications or conversational AI systems.
- Message Recording: Store user and assistant messages with role-based categorization
- Conversation Retrieval: Get complete conversation history by ID
- Automatic Cleanup: Messages expire automatically based on configurable TTL
- Type Safety: Full TypeScript implementation with proper error handling
The app accepts one configuration parameter:
- ttl (optional): Time-to-live for messages in seconds (default: 10800 = 3 hours)
Records a user message in a conversation.
Inputs:
content
(string, required): The message contentconversationId
(string, required): The conversation identifier
Outputs:
conversationId
: The conversation IDfound
: Boolean indicating if other messages exist in the conversationmessages
: Array of all messages in the conversation
Records an assistant message in a conversation.
Inputs:
content
(string, required): The message contentconversationId
(string, required): The conversation identifier
Outputs:
conversationId
: The conversation IDfound
: Boolean indicating if other messages exist in the conversationmessages
: Array of all messages in the conversation
Retrieves all messages from a conversation by ID.
Inputs:
conversationId
(string, required): The conversation identifier
Outputs:
conversationId
: The conversation IDfound
: Boolean indicating if messages were foundmessages
: Array of all messages in the conversation
Each message in the conversation has the following structure:
{
content: string; // The message text
role: "user" | "assistant"; // Who sent the message
}
npm install
npm run typecheck
- Type check the codenpm run format
- Format code with Prettiernpm run bundle
- Bundle the app for deployment
conversations/
├── blocks/ # Block implementations
│ ├── recordMessage.ts # Message recording block factory
│ └── getConversation.ts # Conversation retrieval block
├── shared/ # Shared utilities
│ ├── outputs.ts # Common output schema
│ └── listMessages.ts # Message listing utility
├── main.ts # App definition and configuration
└── package.json # Dependencies and scripts
-
Record a user message:
- Use
recordUserMessage
block with content and conversationId - Returns conversation state and message history
- Use
-
Record an assistant response:
- Use
recordAssistantMessage
block with response content - Messages are automatically linked by conversationId
- Use
-
Retrieve conversation:
- Use
getConversation
block with conversationId - Returns complete message history
- Use
- Messages are stored in key-value storage with UUID v7 keys for chronological ordering
- TTL is applied at storage level for automatic cleanup
- All blocks share common output schema for consistency
- Type-safe implementation with comprehensive error handling