Docs menu
Widget SDK

Chat widget

Add the chat widget to any website with one snippet, then adjust it with script options or your own JavaScript.

Embed code

Each chatbot has its own embed code. Copy it from the chatbot's page in the console; it already holds the chatbot's identifier and API key. It looks like this:

Embed code
<!-- DeepFountain Widget -->
<script>
  (function() {
    const script = document.createElement('script');
    script.src = 'https://saas.deep-fountain.com/widget-v3/YOUR_CHATBOT_IDENTIFIER/loader.js?api_key=YOUR_API_KEY';
    script.setAttribute('data-api-key', 'YOUR_API_KEY');
    script.async = true;
    script.defer = true;
    document.head.appendChild(script);
  })();
</script>
<!-- End DeepFountain Widget -->

Paste it on every page where the chat should appear, just before the closing </body> tag. The <head> works too. The script loads in the background and doesn't hold up your page.

YOUR_CHATBOT_IDENTIFIER and YOUR_API_KEY are placeholders. The code in the console has your real values.

Change the widget from the console

The widget's language, colors, texts, images, welcome message and quick buttons come from the chatbot's settings. Save them in the console and your site shows them the next time a page loads. The embed code stays the same.

Turn the chatbot off on its edit page and it stops answering on your site.

Script options

Add these attributes to the script to change where the chat button sits and how big the chat window opens. Values are in pixels.

data-launcher-bottom
Distance of the chat button from the bottom of the screen. Default: 20.
data-launcher-right
Distance of the chat button from the right of the screen. Default: 20.
data-desktop-width
Width of the open chat window on desktop. On phones the chat fills the screen.
data-desktop-height
Height of the open chat window on desktop.

When a visitor moves or resizes the widget, their browser remembers it, and that takes over from these options.

Chat button 96 px from the bottom
<!-- DeepFountain Widget -->
<script>
  (function() {
    const script = document.createElement('script');
    script.src = 'https://saas.deep-fountain.com/widget-v3/YOUR_CHATBOT_IDENTIFIER/loader.js?api_key=YOUR_API_KEY';
    script.setAttribute('data-api-key', 'YOUR_API_KEY');
    script.setAttribute('data-launcher-bottom', '96');
    script.setAttribute('data-launcher-right', '24');
    script.async = true;
    script.defer = true;
    document.head.appendChild(script);
  })();
</script>
<!-- End DeepFountain Widget -->

JavaScript API

Once the script has loaded, window.dfWidget controls the widget from your page.

dfWidget.open()
Opens the chat window.
dfWidget.close()
Closes the chat window.
dfWidget.sendMessage(text)
Sends the text as if the visitor had typed it.
dfWidget.setLauncherPosition(bottom, right)
Moves the chat button, in pixels from the bottom and right of the screen.
dfWidget.setDesktopSize(width, height)
Sets the size of the open chat window on desktop, in pixels.
  • The script loads in the background, so window.dfWidget doesn't exist until it has loaded. Call it from your own buttons, or check that it exists first.
  • If a page loads more than one chatbot, window.dfWidget controls the one that loaded last.
Open the chat from your own button
<button type="button" id="chat-button">Chat with us</button>
<script>
  document.getElementById('chat-button').addEventListener('click', function () {
    if (!window.dfWidget) return;
    window.dfWidget.open();
    window.dfWidget.sendMessage('What are your opening hours?');
  });
</script>

Events

The widget sends these events to window, so your page can react when the chat opens or closes.

deepfountain:widget:opened
The chat window opened.
deepfountain:widget:closed
The chat window closed.
<script>
  window.addEventListener('deepfountain:widget:opened', function () {
    console.log('chat opened');
  });
</script>

Steps for each platform are in the integration guides.