Chat widget customizations
Different possibilities for the technical playout of the chat widget
In addition to the general widget settings and design customisation in the moinAI Hub, the appearance and behaviour of the chat widget can also be adjusted technically.
The chat widget provides a JavaScript API with further control options. These options are described in the technical documentation of the widget API.
The customisations described here are not made in the moinAI Hub but in the source code of your own website. Coordinate the implementation with your development team or IT department. Settings that do not require code are described in the article Chat widget settings.
All code examples in this article follow these rules:
- The commands are called inside the
window.chatWidgetReadyfunction. The function runs as soon as the chat widget is ready. - The code block with
window.chatWidgetReadymust appear in the website source code before the chat widget integration code. If it appears after the integration code, the function does not run. - The same notation also works when the chat widget is integrated via Google Tag Manager.
1. Change widget position
To prevent the chat widget from covering other elements (e.g. a scroll-to-top button or a contact widget), you can place it on the left or right in button mode directly in the Hub, without any code. The Hub is also where you choose whether the widget appears in button mode or input bar mode. If left or right alignment is not enough, you can set the position in button mode more precisely with code. The position then applies to both the closed and the open chat widget. Unlike in input bar mode, users cannot move the widget themselves in button mode. Teasers created in the Hub under Widget & Teaser > Teaser adjust their position to the chat widget automatically.
<script>
window.chatWidgetReady = function () {
window.moin.setPosition({ bottom: 24, right: 32, unit: 'px' });
};
</script>
bottomsets the distance from the bottom edge.rightsets the distance from the side edge. If the chat widget is aligned to the left in the Hub, this value sets the distance from the left edge. Whether the chat widget appears on the left or right is set in the Hub only.unitsets the unit. Any valid CSS unit is possible, e.g.px,rem,vhor%.- On mobile devices, the side offset is ignored so that the chat widget and teaser stay aligned. With the additional parameter
force: true, the teaser and the widget button apply therightvalue. The open chat window stays in place.
All parameters and their permitted values are described in the setPosition section of the API documentation.
2. Open and close widget
Rules or buttons on the website can control when the chat widget opens and closes. For example, the chat widget can open automatically when a specific subpage is called up, after scrolling to the bottom of the page or after a click on a website button. All commands are described in the Widget JS API documentation.
- Open:
window.moin.open()– described in the open section - Close:
window.moin.close()– described in the close section - Toggle:
window.moin.toggle()opens a closed chat widget and closes an open one. Described in the toggle section
If the chat widget should open after a click on a website button and start directly with a request, a topic or a form, use the startWith() function. The article Enhancing interaction between the website and the chat widget explains how, including use cases and a live demo.
3. Hide and show widget
The hideWidget and showWidget sections of the technical documentation list the commands that hide or show the entire chat widget on the website, including the chat widget icon.
- Hide
The following JavaScript command hides the chat widget:window.moin.hideWidget(); - Show
The following commands display the chat widget again and open it, e.g. after a button click:window.moin.showWidget();window.moin.open();
<script>
// The chatWidgetReady function is called as soon as the chat widget is ready
// and the client API can be accessed.
// This code block must appear before the chat widget integration code.
window.chatWidgetReady = function () {
// Both functions can be called several times and do nothing
// if the widget is already in the requested state.
// Hides the widget if it is visible:
window.moin.hideWidget();
// Shows the widget if it is hidden:
window.moin.showWidget();
};
</script>