Quadrillian JavaScript SDK
The Quadrillian JavaScript SDK provides professional-grade chat integration with multiple patterns for different use cases. It supports both simple one-line integration and advanced programmatic control.
- Multiple integration patterns (manual control, commands auto-execution)
- JWT-based authentication
- Real-time messaging
- Topic-based conversations
- Multiple chat instances on same page
- Professional API design
- Automatic user provisioning
- Async loading support
Installation
Choose the integration pattern that best fits your needs:
Professional API Integration
<!-- Professional async loading -->
<script async src="https://quadrillian.com/js/chat/sdk.js"></script>
<script>
function openSupportChat() {
Quadrillian.createChatWindow({
workspace_id: "456",
topic_external_key: "support"
});
}
</script>
<button onclick="openSupportChat()">Open Support Chat</button>
Integration Patterns
The SDK supports three main integration patterns for different use cases:
Pattern 1: Manual Control (Most Flexible)
<!-- Load SDK asynchronously -->
<script async src="https://quadrillian.com/js/chat/sdk.js"></script>
<!-- Create chat instances programmatically -->
<script>
function openSupportChat() {
Quadrillian.createChatWindow({
workspace_id: "456",
topic_external_key: "support",
position: "bottom-right",
width: 400,
height: 600
});
}
</script>
<button onclick="openSupportChat()">Open Support Chat</button>
Pattern 2: Commands Pattern (Auto-Execute)
<!-- Set up commands before SDK loads -->
<script>
window.Quadrillian = window.Quadrillian || {};
window.Quadrillian.cmds = {
openSupportChat: function() {
Quadrillian.createChatWindow({
workspace_id: "456",
topic_external_key: "support"
});
}
};
</script>
<!-- SDK will auto-execute ALL commands when loaded -->
<script async src="https://quadrillian.com/js/chat/sdk.js"></script>
window.Quadrillian.cmds when it loads. This is perfect for auto-opening chat windows on page load.
API Reference
The Quadrillian SDK provides a professional API for creating and managing chat instances:
Core Methods
Instance Methods
Each chat instance returned by createChatWindow() provides these methods:
Authentication
Quadrillian supports JWT-based authentication for secure user identification:
<!-- Professional API with JWT Authentication -->
<script async src="https://quadrillian.com/js/chat/sdk.js"></script>
<script>
async function openAuthenticatedChat() {
// Get fresh JWT from YOUR backend
const response = await fetch('/api/chat/auth', {
method: 'POST',
credentials: 'include'
});
const { jwt } = await response.json();
// Create chat with JWT
Quadrillian.createChatWindow({
workspace_id: "456",
topic_external_key: "support-general",
jwt_token: jwt
});
}
</script>
<button onclick="openAuthenticatedChat()">Start Chat</button>
- Creates the user if they don't exist
- Links existing users by email if found
- Associates the user with your workspace
- Handles all user management automatically
JWT Token Structure
Your backend should create JWT tokens with this payload:
// JWT payload structure
{
"workspace_id": 456,
"external_user_id": "user_123",
"email": "user@example.com",
"name": "John Doe",
"exp": 1704067200
}
Complete Examples
Multiple Chat Windows
<!-- Load SDK once, create multiple instances -->
<script async src="https://quadrillian.com/js/chat/sdk.js"></script>
<script>
// Support chat
function openSupport() {
Quadrillian.createChatWindow({
workspace_id: "456",
topic_external_key: "support",
position: "bottom-right"
});
}
// Sales chat with AI assistant
function openSales() {
Quadrillian.createChatWindow({
workspace_id: "456",
topic_external_key: "sales",
ai_user_id: 5267, // AI assistant user ID
position: "bottom-left"
});
}
</script>
<button onclick="openSupport()">Support</button>
<button onclick="openSales()">Sales</button>
Authenticated Chat with Dynamic JWT
<!-- Get JWT from your backend when user wants to chat -->
<script async src="https://quadrillian.com/js/chat/sdk.js"></script>
<script>
async function openAuthenticatedChat() {
// Get fresh JWT from YOUR backend
const response = await fetch('/api/chat/auth', {
method: 'POST',
credentials: 'include'
});
const { jwt } = await response.json();
// Create chat with JWT
Quadrillian.createChatWindow({
workspace_id: "456",
topic_external_key: "user-session",
jwt_token: jwt
});
}
</script>
<button onclick="openAuthenticatedChat()">Start Chat</button>
Commands Pattern with Auto-Execution
<!-- Set up commands, SDK executes them when ready -->
<script>
window.Quadrillian = window.Quadrillian || {};
window.Quadrillian.cmds = {
openSupportChat: function() {
Quadrillian.createChatWindow({
workspace_id: "456",
topic_external_key: "support"
});
},
openSalesChat: function() {
Quadrillian.createChatWindow({
workspace_id: "456",
topic_external_key: "sales"
});
}
};
</script>
<!-- SDK will auto-execute ALL commands when loaded -->
<script async src="https://quadrillian.com/js/chat/sdk.js"></script>
Programmatic Control
<script>
let chatInstance;
function createChat() {
chatInstance = Quadrillian.createChatWindow({
workspace_id: "456",
topic_external_key: "support",
autoOpen: false // Don't open immediately
});
}
function toggleChat() {
if (chatInstance) {
chatInstance.open();
}
}
function closeChat() {
if (chatInstance) {
chatInstance.close();
}
}
</script>
Troubleshooting
Common Issues
- Widget not appearing: Check that you've provided
workspace_idin yourcreateChatWindow()call - External key not working: Ensure you've provided
topic_external_keyalong withworkspace_id - JWT authentication failing: Verify your JWT token is valid and not expired
- Widget not loading: Check browser console for error messages
- SDK not ready: Use
Quadrillian.isReady()to check if the SDK has loaded
Debug Mode
Open your browser's developer console to see detailed logging from the Quadrillian SDK.
Support
Need help? Contact our integration team:
- Email: integrations@quadrillian.com
- Documentation: quadrillian.com/docs
- Test Page: quadrillian.com/test-embed