Essential rules for PatternFly Chatbot implementation and integration patterns.
- Component Architecture - Chatbot component structure rules
- Styling Standards - CSS and styling best practices
# ✅ Install PatternFly Chatbot package
npm install @patternfly/chatbot// ✅ MUST import CSS - chatbot components require specific styling
import '@patternfly/chatbot/dist/css/main.css';// stylePaths.js - Add to webpack if CSS not loading
module.exports = [
require.resolve('@patternfly/chatbot/dist/css/main.css')
];- ✅ Use dynamic imports - Import from
/dist/dynamic/paths - ❌ Don't use standard imports - May not work with current package structure
// ✅ Correct - Use dynamic imports
import { Chatbot } from '@patternfly/chatbot/dist/dynamic/Chatbot';
import { ChatbotContent } from '@patternfly/chatbot/dist/dynamic/ChatbotContent';
import { MessageBox } from '@patternfly/chatbot/dist/dynamic/MessageBox';
import { Message } from '@patternfly/chatbot/dist/dynamic/Message';
// ❌ Wrong - Standard imports may not work
import { Chatbot, ChatbotContent } from '@patternfly/chatbot';- ✅ Use standard chatbot hierarchy - Chatbot > ChatbotContent > MessageBox + ChatbotFooter
- ✅ Reference official demos - Use PatternFly demo source code as templates
- ❌ Don't create custom chat UI - Use PatternFly chatbot components
// ✅ Required chatbot structure
<Chatbot>
<ChatbotContent>
<ChatbotWelcomePrompt title="Assistant" description="How can I help?" />
<MessageBox>
{messages.map(message => (
<Message key={message.id} role={message.role} content={message.content} />
))}
</MessageBox>
</ChatbotContent>
<ChatbotFooter>
<MessageBar onSendMessage={handleSendMessage} />
</ChatbotFooter>
</Chatbot>- ✅ Use proper message roles - 'user', 'assistant', 'system'
- ✅ Include timestamps - For message ordering and display
- ✅ Handle loading states - Show indicators during API calls
- ✅ Handle error states - Show error messages with retry options
// ✅ Required message structure
const createMessage = (content, role) => ({
id: generateId(),
content,
role, // 'user' | 'assistant' | 'system'
timestamp: new Date(),
status: 'sent'
});- ✅ Study official demos - Basic and Embedded
- ✅ Use demo source code - Copy patterns from "View Code" sections
- ✅ Follow demo structure - Don't deviate from proven patterns
- ✅ Use with PatternFly layout - Integrate in PageSection, Modal, or Card
- ✅ Handle responsive design - Chatbot must work on all screen sizes
- ❌ Don't create standalone chatbot pages - Integrate with app layout
// ✅ Required integration pattern
<PageSection hasBodyWrapper>
<Chatbot>
{/* Chatbot content */}
</Chatbot>
</PageSection>- ✅ Use proper ARIA labels - For screen reader support
- ✅ Implement keyboard navigation - Full keyboard accessibility
- ✅ Use semantic roles - role="application", role="log"
- ✅ Auto-scroll to new messages - For better UX
// ✅ Required accessibility pattern
<Chatbot role="application" aria-label="AI Assistant">
<MessageBox role="log" aria-live="polite" aria-label="Chat messages">
{messages.map(message => (
<Message aria-label={`${message.role} message: ${message.content}`} />
))}
</MessageBox>
</Chatbot>- Import CSS from
@patternfly/chatbot/dist/css/main.css - Use dynamic imports for chatbot components
- Reference official PatternFly demo pages for implementation
- Provide proper ARIA labels and roles for accessibility
- Handle loading states during message processing
- Implement proper error handling for API failures
- Use semantic message roles (user, assistant, system)
- Skip CSS imports - chatbot components require specific styling
- Ignore demo source code from PatternFly documentation
- Create custom chat UI when PatternFly components exist
- Skip accessibility considerations for screen readers
- Hardcode chatbot dimensions without responsive design
- Mix different chatbot libraries with PatternFly Chatbot
- Missing styles: Ensure CSS is imported in main app file
- Webpack config: Add CSS path to stylePaths.js if needed
- Import errors: Use dynamic import paths
/dist/dynamic/ - Component not found: Verify package is installed and paths are correct
- Long conversations: Implement message virtualization
- Memory leaks: Clean up event listeners and subscriptions
- Chatbot Overview - Main documentation
- Basic Demo - Simple implementation
- Embedded Demo - Embedded pattern
Note: This chatbot guidance takes precedence over general PatternFly patterns. Always consult the latest PatternFly Chatbot documentation and demo source code.
For the most up-to-date documentation and code examples, consult both PatternFly.org and the official GitHub repository. When using AI tools, leverage context7 to fetch the latest docs from these sources.
- PatternFly Chatbot Docs
- Message Component API - Message component API documentation
- Accessibility Guide