Genius Chat Headless Chat SDK
The Genius Chat SDK allows you to build customised chat experiences powered by DigitalGenius.
Getting Started
Add your configuration and include the SDK script 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'
}
</script>
<script src="https://chat.digitalgenius.com/init-sdk.js"></script>
</body>
</html>Once the script loads, you can initialise the SDK and subscribe to events.
Basic Example
// Wait for the SDK Script to load
window.addEventListener('onDGSDKScriptLoaded', async () => {
// Initialise the SDK, must be awaited
await window.DGChatSDK.init();
// Fires when messages are received
window.DGChatSDK.onMessage((message) => {
console.log(message)
});
// Send a message
window.DGChatSDK.sendMessage({ someKey: "Some value" });
});Methods
init
initInitialises the SDK by establishing all required connections. This method returns a promise and must be awaited before using any other SDK functionality.
await window.DGChatSDK.init();sendMessage
sendMessageSends a message to the DigitalGenius flow engine.
The method accepts a freeform object in which properties are passed to flow within a metadata flow input.
window.DGChatSDK.sendMessage({ someKey: "Some value" });Event Listeners
onMessage
onMessageCalled whenever a new message is received from the flow engine. Use this to handle and render messages in your UI.
window.DGChatSDK.onMessage((message) => {
console.log(message);
addMessageToDOM(message);
});Updated about 4 hours ago
