Declarative History Loading Demo
ℹ️ About This Demo:
This page demonstrates the data-swc-load attribute
that automatically loads chat history when the chatbot initializes. The example below loads from
sample-history.json.
Example 1: Load from External File
HTML Code:
<div data-swc
data-swc-theme-color="#0D9488"
data-swc-bot-name="SenangWebs"
data-swc-load="./sample-history.json">
</div>
Example 2: Load from Inline JSON
HTML Code:
<div data-swc
data-swc-theme-color="#8B5CF6"
data-swc-bot-name="Assistant"
data-swc-load='{...inline JSON...}'>
</div>
Example 3: Normal Initialization
HTML Code:
<div data-swc
data-swc-theme-color="#F59E0B"
data-swc-bot-name="Helper">
</div>
<!-- No data-swc-load attribute -->
Without data-swc-load,
the chatbot starts fresh with the welcome message.
Use Cases
✅ External File Loading
- • Restore previous chat sessions
- • Load predefined conversation flows
- • Share chat history between users
- • Demo/showcase specific conversations
✅ Inline JSON Loading
- • Embed history directly in HTML
- • Dynamic history from server-side rendering
- • Testing and debugging
- • Simple single-page applications
⚠️ Error Handling
- • Invalid JSON → Falls back to default
- • 404 errors → Falls back to default
- • CORS issues → Check server headers
- • Errors logged to console