Genius Chat Headless Chat SDK
The Genius Chat SDK allows you to build customised chat experiences powered by DigitalGenius.
Getting Started
Include your configuration and the SDK script in your HTML just before the closing body tag:
<!DOCTYPE html>
<html>
<head></head>
<body>
<script>
window.DG_SDK_CONFIG = {
widgetId: 'your-widget-id',
env: 'eu', // 'eu', 'us', or 'dev.us'
generalSettings: {
persistSession: true // whether the SDK reconnects to an existing session on page reload
}
}
</script>
<script src="https://chat.digitalgenius.com/init-sdk.js"></script>
</body>
</html>
Initialisation
Initialise the SDK and subscribe to events
// Ensure the browser has loaded the SDK script
window.addEventListener('DGSDKScriptLoaded', () => {
// Initialise the SDK
window.DGChatSDK.init();
// Fires once the SDK has initialised. You can now start using the SDK methods
window.DGChatSDK.onReady(() => {
console.log('DG Chat SDK is ready');
window.DGChatSDK.startConversation();
});
// Subscribe to messages
window.DGChatSDK.onMessage((message) => {
console.log('Received message:', message);
});
// Subscribe to system events
window.DGChatSDK.onSystemEvent((event) => {
console.log('System event:', event);
});
});
Methods
init
init
Initialises the SDK and establishes WebSocket connection. Must be called after the DGSDKScriptLoaded
event.
window.DGChatSDK.init();
startConversation
startConversation
Initiates a new conversation with the bot.
window.DGChatSDK.startConversation();
endConversation
endConversation
Ends the current conversation, disconnects WebSocket, and clears session data.
window.DGChatSDK.endConversation();
restartConversation
restartConversation
Restarts the current conversation, returning to the beginning of the flow.
window.DGChatSDK.restartConversation();
sendTextMessage
sendTextMessage
Sends a text message from the user to the bot.
window.DGChatSDK.sendTextMessage('Hello, I need help with my order');
submitQuickReply
submitQuickReply
Submits a quick reply selection. The entire selected quick reply object should be passed.
window.DGChatSDK.submitQuickReply(selectedQuickReplyObject);
Event Listeners
onReady
onReady
Fired when the SDK is ready for interaction.
window.DGChatSDK.onReady(() => {
console.log('SDK is ready');
});
onMessage
onMessage
Fired when the bot sends a message.
window.DGChatSDK.onMessage((message) => {
console.log('Received message:', message);
switch (message.type) {
case 'message':
displayTextMessage(message);
break;
case 'carousel':
displayCarousel(message);
break;
case 'quick_reply':
displayQuickReplies(message);
break;
}
});
Supported Message Types:
message
- Text messagescarousel
- Product carouselsselect_dropdown
- Dropdown selectionsquick_reply
- Quick reply buttonscalendar
- Calendar pickerform
- Form inputslist
- List selectionsattachment
- File attachmentscrm_handover
- CRM integration handoverbatch
- Batch messagesorder_tracker
- Order tracking informationvideo
- Video messagesreturn_overdue
- Return process messagesadvanced
- Advanced message
onSystemEvent
onSystemEvent
Fired when the bot sends system events for chat state changes.
window.DGChatSDK.onSystemEvent((event) => {
console.log('System event:', event);
handleSystemEvent(event);
});
System Events
The SDK emits various system events to inform you about chat state changes:
General Events
typing_start
- Bot / Agent started typingtyping_stop
- Bot / Agent stopped typingjoined
- Helpdesk agent joineddisconnect
- Helpdesk agent disconnectedagent_joining
- Helpdesk agent is joiningagent_transferred
- Helpdesk agent transferred user to another agenttimeout
- Chat session timed out (default: 24 hours)system_message
- Generic system message from the flowuploadFileRequest
- Flow requests file uploaduploadPictureRequest
- Flow requests image uploaderror
- Error occurred in the flowhelpdesk_handover
- Handover to helpdesk initiatedhandover_error
- Error during handover processqueue_update
- Queue position updatedcsat_request
- CSAT feedback requestedunassigned
- Agent unassigned from chat
Salesforce-Specific Events
idle_timeout_countdown
- Warning before idle timeoutidle_timeout
- Idle timeout reachedfile_transfer_request
- Agent requests file uploadfile_transfer_cancel
- Agent cancels file upload request
Updated about 2 hours ago