JavaScript/jQuery Chat - Popup Integration
A common way to add a chat assistant to your website is by embedding it in a modal at the bottom right corner. Follow these steps:
- Place DevExtreme Floating Action Button at the bottom right of the window. Users can click it to open the popup.
- Position our Popup at the bottom right (or another preferred location).
- Add the Chat component for the virtual assistant.
The following code snippet demonstrates this scenario. Check the CSS tab for instructions on how to integrate Popup and Chat.
index.html
index.js
index.css
- <div id="action"></div>
- <div id="popup"></div>
- const assistant = {
- id: "02",
- name: "Assistant"
- };
- const messages = [{
- id: 1,
- timestamp: new Date(),
- author: assistant,
- text: "Hello! How can I help you?"
- }];
- $(() => {
- $("#action").dxSpeedDialAction({
- label: "Chat",
- icon: "send",
- onClick() {
- popup.show();
- }
- });
- const popup = $("#popup").dxPopup({
- position: "right bottom",
- width: 400,
- height: 650,
- shading: false,
- dragEnabled: false,
- contentTemplate: function (contentElement) {
- contentElement.append(
- $("<div />")
- .attr("id", "chat")
- .dxChat({
- width: 400,
- height: 600,
- onMessageEntered: (e) => {
- e.component.renderMessage(e.message);
- },
- items: messages
- })
- );
- }
- }).dxPopup("instance");
- });
- #chat {
- border: none;
- }
- .dx-popup-content-scrollable {
- padding: 0;
- overflow: hidden;
- }