- Configure messages
- Configure message options
Contact Support
Messages in EJ2 TypeScript Chat UI control
27 Jun 202524 minutes to read
The Chat UI allows to add messages using the messages property. The message collection stores all the messages being sent and received.
Configure messages
You can use the text property to add message content for the user. Each message can be configured with options such as id, text, author, timestamp and more.
import { ChatUI, UserModel, MessageModel } from '@syncfusion/ej2-interactive-chat';
import { enableRipple } from '@syncfusion/ej2-base';
enableRipple(true);
let currentUserModel: UserModel = {
id: "user1",
user: "Albert"
};
let michaleUserModel: UserModel = {
id: "user2",
user: "Michale Suyama"
};
let chatMessages: MessageModel[] = [
{
author: currentUserModel,
text: "Hi Michale, are we on track for the deadline?"
},
{
author: michaleUserModel,
text: "Yes, the design phase is complete."
},
{
author: currentUserModel,
text: "I’ll review it and send feedback by today."
}
];
// Initializes the Chat UI control
let chatUI: ChatUI = new ChatUI({
messages: chatMessages,
user: currentUserModel,
width: '450px'
});
// Render initialized Chat UI.
chatUI.appendTo('#width');
<!DOCTYPE html>
<html lang="en">
<head>
<title>EJ2 Chat UI</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="TypeScript Chat UI Control" />
<meta name="author" content="Syncfusion" />
<link href="index.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-base/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-inputs/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-buttons/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-navigations/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-popups/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-interactive-chat/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-splitbuttons/styles/material.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container' style="height: 380px; width: 450px;">
<div id="width"></div>
</div>
</body>
</html>
Setting pinned
You can use the isPinned property to highlight the important message in the chat. Once a message is pinned, you can access the options menu to continue the chat or unpin it.
import { ChatUI, UserModel, MessageModel } from '@syncfusion/ej2-interactive-chat';
import { enableRipple } from '@syncfusion/ej2-base';
enableRipple(true);
let currentUserModel: UserModel = {
id: "user1",
user: "Albert"
};
let michaleUserModel: UserModel = {
id: "user2",
user: "Michale Suyama"
};
let chatMessages: MessageModel[] = [
{
author: currentUserModel,
text: "Hi Michale, are we on track for the deadline?"
},
{
author: michaleUserModel,
text: "Yes, the design phase is complete."
},
{
author: currentUserModel,
text: "I’ll review it and send feedback by today.",
isPinned: true
}
];
// Initializes the Chat UI control
let chatUI: ChatUI = new ChatUI({
messages: chatMessages,
user: currentUserModel
});
// Render initialized Chat UI.
chatUI.appendTo('#pinned');
<!DOCTYPE html>
<html lang="en">
<head>
<title>EJ2 Chat UI</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="TypeScript Chat UI Control" />
<meta name="author" content="Syncfusion" />
<link href="index.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-base/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-inputs/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-buttons/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-navigations/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-popups/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-interactive-chat/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-splitbuttons/styles/material.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<style>
.e-chat-ui .e-message-icon.custom-user {
background-color: #416fbd;
color: white;
border-radius: 5px;
}
</style>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container' style="height: 380px; width: 450px;">
<div id="pinned"></div>
</div>
</body>
</html>
Setting reply to
You can use the replyTo property to respond to the original message preserving context and creating a threaded conversation.
import { ChatUI, UserModel, MessageModel } from '@syncfusion/ej2-interactive-chat';
import { enableRipple } from '@syncfusion/ej2-base';
enableRipple(true);
let currentUserModel: UserModel = {
id: "user1",
user: "Albert"
};
let michaleUserModel: UserModel = {
id: "user2",
user: "Michale Suyama"
};
let chatMessages: MessageModel[] = [
{
author: currentUserModel,
text: "Hi Michale, are we on track for the deadline?",
id: "chat-message-1"
},
{
author: michaleUserModel,
text: "Yes, the design phase is complete.",
id: "chat-message-2"
},
{
author: currentUserModel,
text: "I’ll review it and send feedback by today.",
replyTo: {
user: michaleUserModel,
text: 'Yes, the design phase is complete.',
messageID: 'chat-message-2'
}
}
];
// Initializes the Chat UI control
let chatUI: ChatUI = new ChatUI({
messages: chatMessages,
user: currentUserModel
});
// Render initialized Chat UI.
chatUI.appendTo('#replyto');
<!DOCTYPE html>
<html lang="en">
<head>
<title>EJ2 Chat UI</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="TypeScript Chat UI Control" />
<meta name="author" content="Syncfusion" />
<link href="index.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-base/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-inputs/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-buttons/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-navigations/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-popups/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-interactive-chat/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-splitbuttons/styles/material.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<style>
.e-chat-ui .e-message-icon.custom-user {
background-color: #416fbd;
color: white;
border-radius: 5px;
}
</style>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container' style="height: 380px; width: 450px;">
<div id="replyto"></div>
</div>
</body>
</html>
Setting forward
You can use the isForwarded property to specify the user when the message is forwarded.
import { ChatUI, UserModel, MessageModel } from '@syncfusion/ej2-interactive-chat';
import { enableRipple } from '@syncfusion/ej2-base';
enableRipple(true);
let currentUserModel: UserModel = {
id: "user1",
user: "Albert"
};
let michaleUserModel: UserModel = {
id: "user2",
user: "Michale Suyama"
};
let chatMessages: MessageModel[] = [
{
author: currentUserModel,
text: "Hi Michale, are we on track for the deadline?"
},
{
author: michaleUserModel,
text: "Yes, the design phase is complete."
},
{
author: currentUserModel,
text: "I’ll review it and send feedback by today.",
isForwarded: true
}
];
// Initializes the Chat UI control
let chatUI: ChatUI = new ChatUI({
messages: chatMessages,
user: currentUserModel
});
// Render initialized Chat UI.
chatUI.appendTo('#forwarded');
<!DOCTYPE html>
<html lang="en">
<head>
<title>EJ2 Chat UI</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="TypeScript Chat UI Control" />
<meta name="author" content="Syncfusion" />
<link href="index.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-base/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-inputs/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-buttons/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-navigations/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-popups/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-interactive-chat/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-splitbuttons/styles/material.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<style>
.e-chat-ui .e-message-icon.custom-user {
background-color: #416fbd;
color: white;
border-radius: 5px;
}
</style>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container' style="height: 380px; width: 450px;">
<div id="forwarded"></div>
</div>
</body>
</html>
Setting compact mode
You can use the enableCompactMode
property to align all messages to the left in the chat for creating a streamlined layout ideal for group conversations or space-constrained interfaces. By default, the value is false
.
import { ChatUI, UserModel, MessageModel } from '@syncfusion/ej2-interactive-chat';
import { enableRipple } from '@syncfusion/ej2-base';
enableRipple(true);
let currentUserModel: UserModel = {
id: "user1",
user: "Albert"
};
let michaleUserModel: UserModel = {
id: "user2",
user: "Michale Suyama"
};
let chatMessages: MessageModel[] = [
{
author: currentUserModel,
text: "Hi Michale, are we on track for the deadline?"
},
{
author: michaleUserModel,
text: "Yes, the design phase is complete."
},
{
author: currentUserModel,
text: "I’ll review it and send feedback by today."
}
];
// Initializes the Chat UI control
let chatUI: ChatUI = new ChatUI({
messages: chatMessages,
user: currentUserModel,
enableCompactMode: true
});
// Render initialized Chat UI.
chatUI.appendTo('#compactmode');
<!DOCTYPE html>
<html lang="en">
<head>
<title>EJ2 Chat UI</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="TypeScript Chat UI Control" />
<meta name="author" content="Syncfusion" />
<link href="index.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-base/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-inputs/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-buttons/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-navigations/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-popups/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-interactive-chat/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-splitbuttons/styles/material.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<style>
.e-chat-ui .e-message-icon.custom-user {
background-color: #416fbd;
color: white;
border-radius: 5px;
}
</style>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container' style="height: 380px; width: 450px;">
<div id="compactmode"></div>
</div>
</body>
</html>
Define current user
You can use the author property to identify the current user of the chat. Each user can be configured with options such as id, user, avatarUrl and more.
You can use the user property to display the user name and id property is necessary to differentiate between the multiple users.
import { ChatUI, UserModel, MessageModel } from '@syncfusion/ej2-interactive-chat';
import { enableRipple } from '@syncfusion/ej2-base';
enableRipple(true);
let currentUserModel: UserModel = {
id: "user1",
user: "Albert"
};
let michaleUserModel: UserModel = {
id: "user2",
user: "Michale Suyama"
};
let chatMessages: MessageModel[] = [
{
author: currentUserModel,
text: "Hi Michale, are we on track for the deadline?"
},
{
author: michaleUserModel,
text: "Yes, the design phase is complete."
},
{
author: currentUserModel,
text: "I’ll review it and send feedback by today."
}
];
// Initializes the Chat UI control
let chatUI: ChatUI = new ChatUI({
messages: chatMessages,
user: currentUserModel,
width: '450px'
});
// Render initialized Chat UI.
chatUI.appendTo('#width');
<!DOCTYPE html>
<html lang="en">
<head>
<title>EJ2 Chat UI</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="TypeScript Chat UI Control" />
<meta name="author" content="Syncfusion" />
<link href="index.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-base/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-inputs/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-buttons/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-navigations/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-popups/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-interactive-chat/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-splitbuttons/styles/material.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container' style="height: 380px; width: 450px;">
<div id="width"></div>
</div>
</body>
</html>
Setting avatar URL
You can use the avatarUrl property to define the image URL’s for the user avatar. If no URL is provided, fallback initials of the first and last name from the user’s name will be used.
import { ChatUI, UserModel, MessageModel } from '@syncfusion/ej2-interactive-chat';
import { enableRipple } from '@syncfusion/ej2-base';
enableRipple(true);
let currentUserModel: UserModel = {
id: "user1",
user: "Albert"
};
let michaleUserModel: UserModel = {
id: "user2",
user: "Michale Suyama",
avatarUrl: 'https://ej2.syncfusion.com/demos/src/avatar/images/pic03.png'
};
let chatMessages: MessageModel[] = [
{
author: currentUserModel,
text: "Hi Michale, are we on track for the deadline?"
},
{
author: michaleUserModel,
text: "Yes, the design phase is complete."
},
{
author: currentUserModel,
text: "I’ll review it and send feedback by today."
}
];
// Initializes the Chat UI control
let chatUI: ChatUI = new ChatUI({
messages: chatMessages,
user: currentUserModel
});
// Render initialized Chat UI.
chatUI.appendTo('#avatarUrl');
<!DOCTYPE html>
<html lang="en">
<head>
<title>EJ2 Chat UI</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="TypeScript Chat UI Control" />
<meta name="author" content="Syncfusion" />
<link href="index.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-base/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-inputs/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-buttons/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-navigations/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-popups/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-interactive-chat/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-splitbuttons/styles/material.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container' style="height: 380px; width: 450px;">
<div id="avatarUrl"></div>
</div>
</body>
</html>
Setting avatar background color
You can use the avatarBgColor property to set a specific background color for user avatars using hexadecimal values. If no color is set, a custom background color is set based on specified theme.
import { ChatUI, UserModel, MessageModel } from '@syncfusion/ej2-interactive-chat';
import { enableRipple } from '@syncfusion/ej2-base';
enableRipple(true);
let currentUserModel: UserModel = {
id: "user1",
user: "Albert"
};
let michaleUserModel: UserModel = {
id: "user2",
user: "Michale Suyama",
avatarBgColor: '#ccc9f7'
};
let chatMessages: MessageModel[] = [
{
author: currentUserModel,
text: "Hi Michale, are we on track for the deadline?"
},
{
author: michaleUserModel,
text: "Yes, the design phase is complete."
},
{
author: currentUserModel,
text: "I’ll review it and send feedback by today."
}
];
// Initializes the Chat UI control
let chatUI: ChatUI = new ChatUI({
messages: chatMessages,
user: currentUserModel
});
// Render initialized Chat UI.
chatUI.appendTo('#avatarBg');
<!DOCTYPE html>
<html lang="en">
<head>
<title>EJ2 Chat UI</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="TypeScript Chat UI Control" />
<meta name="author" content="Syncfusion" />
<link href="index.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-base/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-inputs/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-buttons/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-navigations/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-popups/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-interactive-chat/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-splitbuttons/styles/material.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container' style="height: 380px; width: 450px;">
<div id="avatarBg"></div>
</div>
</body>
</html>
Setting CSS class
You can use the cssClass property to customize the appearance of the chat user.
import { ChatUI, UserModel, MessageModel } from '@syncfusion/ej2-interactive-chat';
import { enableRipple } from '@syncfusion/ej2-base';
enableRipple(true);
let currentUserModel: UserModel = {
id: "user1",
user: "Albert"
};
let michaleUserModel: UserModel = {
id: "user2",
user: "Michale Suyama",
cssClass: 'custom-user'
};
let chatMessages: MessageModel[] = [
{
author: currentUserModel,
text: "Hi Michale, are we on track for the deadline?"
},
{
author: michaleUserModel,
text: "Yes, the design phase is complete."
},
{
author: currentUserModel,
text: "I’ll review it and send feedback by today."
}
];
// Initializes the Chat UI control
let chatUI: ChatUI = new ChatUI({
messages: chatMessages,
user: currentUserModel
});
// Render initialized Chat UI.
chatUI.appendTo('#cssClass');
<!DOCTYPE html>
<html lang="en">
<head>
<title>EJ2 Chat UI</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="TypeScript Chat UI Control" />
<meta name="author" content="Syncfusion" />
<link href="index.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-base/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-inputs/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-buttons/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-navigations/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-popups/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-interactive-chat/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-splitbuttons/styles/material.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<style>
.e-chat-ui .e-message-icon.custom-user {
background-color: #416fbd;
color: white;
border-radius: 5px;
}
</style>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container' style="height: 380px; width: 450px;">
<div id="cssClass"></div>
</div>
</body>
</html>
#container {
visibility: hidden;
margin: 20px auto;
}
#loader {
color: #008cff;
height: 40px;
left: 45%;
position: absolute;
top: 45%;
width: 30%;
}
Setting status icon css
You can use the statusIconCss property to identify the user’s presence, including online
, offline
, busy
, and away
status in the Chat UI.
The following are the predefined status styles that can be defined using the statusIconCss
property.
Status | Icon class |
---|---|
Available |
e-user-online |
Away |
e-user-away |
Busy |
e-user-busy |
Offline |
e-user-offline |
import { ChatUI, UserModel, MessageModel } from '@syncfusion/ej2-interactive-chat';
import { enableRipple } from '@syncfusion/ej2-base';
enableRipple(true);
let currentUserModel: UserModel = {
id: "user1",
user: "Albert",
statusIconCss: 'e-icons e-user-online'
};
let michaleUserModel: UserModel = {
id: "user2",
user: "Michale Suyama",
statusIconCss: 'e-icons e-user-away'
};
let chatMessages: MessageModel[] = [
{
author: currentUserModel,
text: "Hi Michale, are we on track for the deadline?"
},
{
author: michaleUserModel,
text: "Yes, the design phase is complete."
},
{
author: currentUserModel,
text: "I’ll review it and send feedback by today."
}
];
// Initializes the Chat UI control
let chatUI: ChatUI = new ChatUI({
messages: chatMessages,
user: currentUserModel
});
// Render initialized Chat UI.
chatUI.appendTo('#statusicon');
<!DOCTYPE html>
<html lang="en">
<head>
<title>EJ2 Chat UI</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="TypeScript Chat UI Control" />
<meta name="author" content="Syncfusion" />
<link href="index.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-base/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-inputs/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-buttons/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-navigations/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-popups/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-interactive-chat/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-splitbuttons/styles/material.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<style>
.e-chat-ui .e-message-icon.custom-user {
background-color: #416fbd;
color: white;
border-radius: 5px;
}
</style>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container' style="height: 380px; width: 450px;">
<div id="statusicon"></div>
</div>
</body>
</html>
#container {
visibility: hidden;
margin: 20px auto;
}
#loader {
color: #008cff;
height: 40px;
left: 45%;
position: absolute;
top: 45%;
width: 30%;
}
Define timestamp
You can use the timeStamp property to indicate the date and time of each messages being sent. By default it is set to the current date and time when the message is sent.
import { ChatUI, UserModel, MessageModel } from '@syncfusion/ej2-interactive-chat';
import { enableRipple } from '@syncfusion/ej2-base';
enableRipple(true);
let currentUserModel: UserModel = {
id: "user1",
user: "Albert"
};
let michaleUserModel: UserModel = {
id: "user2",
user: "Michale Suyama"
};
let chatMessages: MessageModel[] = [
{
author: currentUserModel,
text: "Hi Michale, are we on track for the deadline?",
timeStamp: new Date("December 25, 2024 7:30")
},
{
author: michaleUserModel,
text: "Yes, the design phase is complete.",
timeStamp: new Date("December 25, 2024 8:00")
},
{
author: currentUserModel,
text: "I’ll review it and send feedback by today.",
timeStamp: new Date("December 25, 2024 11:00")
}
];
// Initializes the Chat UI control
let chatUI: ChatUI = new ChatUI({
messages: chatMessages,
user: currentUserModel,
showTimeStamp: false
});
// Render initialized Chat UI.
chatUI.appendTo('#showTimeStamp');
<!DOCTYPE html>
<html lang="en">
<head>
<title>EJ2 Chat UI</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="TypeScript Chat UI Control" />
<meta name="author" content="Syncfusion" />
<link href="index.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-base/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-inputs/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-buttons/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-navigations/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-popups/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-interactive-chat/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-splitbuttons/styles/material.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container' style="height: 380px; width: 450px;">
<div id="showTimeStamp"></div>
</div>
</body>
</html>
Setting timestamp format
You can use the timeStampFormat to display specific time format for the timestamp. The default format is dd/MM/yyyy hh:mm a
, but this can be customized to meet different localization and display needs.
import { ChatUI, UserModel, MessageModel } from '@syncfusion/ej2-interactive-chat';
import { enableRipple } from '@syncfusion/ej2-base';
enableRipple(true);
let currentUserModel: UserModel = {
id: "user1",
user: "Albert"
};
let michaleUserModel: UserModel = {
id: "user2",
user: "Michale Suyama"
};
let chatMessages: MessageModel[] = [
{
author: currentUserModel,
text: "Hi Michale, are we on track for the deadline?"
},
{
author: michaleUserModel,
text: "Yes, the design phase is complete.",
timeStampFormat: 'MMMM hh:mm a'
},
{
author: currentUserModel,
text: "I’ll review it and send feedback by today."
}
];
// Initializes the Chat UI control
let chatUI: ChatUI = new ChatUI({
messages: chatMessages,
user: currentUserModel
});
// Render initialized Chat UI.
chatUI.appendTo('#timeStampFormat');
<!DOCTYPE html>
<html lang="en">
<head>
<title>EJ2 Chat UI</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="TypeScript Chat UI Control" />
<meta name="author" content="Syncfusion" />
<link href="index.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-base/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-inputs/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-buttons/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-navigations/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-popups/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-interactive-chat/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-splitbuttons/styles/material.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container' style="height: 380px; width: 450px;">
<div id="timeStampFormat"></div>
</div>
</body>
</html>
Define message status
You can use the status property to update the status for the message(e.g., sent, received, read). It helps in managing message delivery and read receipts within the chat interface.
Setting icon CSS
You can use the iconCss property to update the styling of status icons associated with messages, aiding visual differentiation between statuses.
import { ChatUI, UserModel, MessageModel } from '@syncfusion/ej2-interactive-chat';
import { enableRipple } from '@syncfusion/ej2-base';
enableRipple(true);
let currentUserModel: UserModel = {
id: "user1",
user: "Albert"
};
let michaleUserModel: UserModel = {
id: "user2",
user: "Michale Suyama"
};
let chatMessages: MessageModel[] = [
{
author: currentUserModel,
text: "Hi Michale, are we on track for the deadline?"
},
{
author: michaleUserModel,
text: "Yes, the design phase is complete."
},
{
author: currentUserModel,
text: "I’ll review it and send feedback by today.",
status: {
iconCss: 'e-icons e-chat-seen'
}
}
];
// Initializes the Chat UI control
let chatUI: ChatUI = new ChatUI({
messages: chatMessages,
user: currentUserModel
});
// Render initialized Chat UI.
chatUI.appendTo('#iconCss');
<!DOCTYPE html>
<html lang="en">
<head>
<title>EJ2 Chat UI</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="TypeScript Chat UI Control" />
<meta name="author" content="Syncfusion" />
<link href="index.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-base/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-inputs/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-buttons/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-navigations/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-popups/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-interactive-chat/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-splitbuttons/styles/material.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container' style="height: 380px; width: 450px;">
<div id="iconCss"></div>
</div>
</body>
</html>
Setting text
You can use the text property to provide information about the messages through descriptive text, providing users with the context of the message.
import { ChatUI, UserModel, MessageModel } from '@syncfusion/ej2-interactive-chat';
import { enableRipple } from '@syncfusion/ej2-base';
enableRipple(true);
let currentUserModel: UserModel = {
id: "user1",
user: "Albert"
};
let michaleUserModel: UserModel = {
id: "user2",
user: "Michale Suyama"
};
let chatMessages: MessageModel[] = [
{
author: currentUserModel,
text: "Hi Michale, are we on track for the deadline?"
},
{
author: michaleUserModel,
text: "Yes, the design phase is complete."
},
{
author: currentUserModel,
text: "I’ll review it and send feedback by today.",
status: {
text: 'Seen'
}
}
];
// Initializes the Chat UI control
let chatUI: ChatUI = new ChatUI({
messages: chatMessages,
user: currentUserModel
});
// Render initialized Chat UI.
chatUI.appendTo('#text');
<!DOCTYPE html>
<html lang="en">
<head>
<title>EJ2 Chat UI</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="TypeScript Chat UI Control" />
<meta name="author" content="Syncfusion" />
<link href="index.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-base/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-inputs/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-buttons/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-navigations/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-popups/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-interactive-chat/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-splitbuttons/styles/material.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container' style="height: 380px; width: 450px;">
<div id="text"></div>
</div>
</body>
</html>
Setting tooltip
You can use the tooltip property to provide information about the messages by tooltips while hovering the status icon, providing users with additional data upon hovering.
import { ChatUI, UserModel, MessageModel } from '@syncfusion/ej2-interactive-chat';
import { enableRipple } from '@syncfusion/ej2-base';
enableRipple(true);
let currentUserModel: UserModel = {
id: "user1",
user: "Albert"
};
let michaleUserModel: UserModel = {
id: "user2",
user: "Michale Suyama"
};
let chatMessages: MessageModel[] = [
{
author: currentUserModel,
text: "Hi Michale, are we on track for the deadline?"
},
{
author: michaleUserModel,
text: "Yes, the design phase is complete."
},
{
author: currentUserModel,
text: "I’ll review it and send feedback by today.",
status: {
iconCss: 'e-icons e-chat-seen',
tooltip: 'Seen'
}
}
];
// Initializes the Chat UI control
let chatUI: ChatUI = new ChatUI({
messages: chatMessages,
user: currentUserModel
});
// Render initialized Chat UI.
chatUI.appendTo('#tooltip');
<!DOCTYPE html>
<html lang="en">
<head>
<title>EJ2 Chat UI</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="TypeScript Chat UI Control" />
<meta name="author" content="Syncfusion" />
<link href="index.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-base/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-inputs/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-buttons/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-navigations/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-popups/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-interactive-chat/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-splitbuttons/styles/material.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container' style="height: 380px; width: 450px;">
<div id="tooltip"></div>
</div>
</body>
</html>
Setting auto scroll
You can use the autoScrollToBottom property to automatically scroll the chats when a new message is received in a conversation. By default, the value is false, requires manual scrolling or the FAB button to quick access to the bottom of the view.
- By default, it scrolls to bottom for each message being sent or when the scroll is maintained at the bottom in the chat, in order to prevent the automatic scroll for different user messages you can use the
autoScrollToBottom
property.
import { ChatUI, UserModel, MessageModel } from '@syncfusion/ej2-interactive-chat';
import { enableRipple } from '@syncfusion/ej2-base';
enableRipple(true);
let currentUserModel: UserModel = {
id: "user1",
user: "Albert"
};
let michaleUserModel: UserModel = {
id: "user2",
user: "Michale Suyama"
};
let chatMessages: MessageModel[] = [
{
author: currentUserModel,
text: "Want to get coffee tomorrow?"
},
{
author: michaleUserModel,
text: "Sure! What time?"
},
{
author: currentUserModel,
text: "How about 10 AM?"
},
{
author: michaleUserModel,
text: "Perfect"
},
{
author: currentUserModel,
text: "See you!"
},
{
author: michaleUserModel,
text: "Bye!"
}
];
// Initializes the Chat UI control
let chatUI: ChatUI = new ChatUI({
messages: chatMessages,
user: currentUserModel,
autoScrollToBottom: true
});
// Render initialized Chat UI.
chatUI.appendTo('#autoScroll');
<!DOCTYPE html>
<html lang="en">
<head>
<title>EJ2 Chat UI</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="TypeScript Chat UI Control" />
<meta name="author" content="Syncfusion" />
<link href="index.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-base/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-inputs/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-buttons/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-navigations/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-popups/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-interactive-chat/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-splitbuttons/styles/material.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container'style="height: 380px; width: 450px;">
<div id="autoScroll"></div>
</div>
</body>
</html>
Setting suggestions
You can use the suggestions property, to add the suggestions in both initial and on-demand which help users to quick-reply options above the input field.
import { ChatUI, UserModel, MessageModel } from '@syncfusion/ej2-interactive-chat';
import { enableRipple } from '@syncfusion/ej2-base';
enableRipple(true);
let currentUserModel: UserModel = {
id: "user1",
user: "Albert"
};
let michaleUserModel: UserModel = {
id: "user2",
user: "Michale Suyama"
};
let suggestions: string[] = ["Okay will check it", "Sounds good!"];
let chatMessages: MessageModel[] = [
{
author: currentUserModel,
text: "Hi Michale, are we on track for the deadline?"
},
{
author: michaleUserModel,
text: "Yes, the design phase is complete."
}
];
// Initializes the Chat UI control
let chatUI: ChatUI = new ChatUI({
messages: chatMessages,
user: currentUserModel,
suggestions: suggestions
});
// Render initialized Chat UI.
chatUI.appendTo('#suggestions');
<!DOCTYPE html>
<html lang="en">
<head>
<title>EJ2 Chat UI</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="TypeScript Chat UI Control" />
<meta name="author" content="Syncfusion" />
<link href="index.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-base/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-inputs/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-buttons/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-navigations/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-popups/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-interactive-chat/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-splitbuttons/styles/material.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container' style="height: 380px; width: 450px;">
<div id="suggestions"></div>
</div>
</body>
</html>
Configure message options
The messageToolbarSettings
property allows customization of the message toolbar for richer chat experience in the Chat UI. It provides options to define the toolbar width
, configure a set of toolbar items
, and handle itemClick
events for enhanced interactivity. By default, the message options available are Copy
, Reply
, Pin
, and Delete
.
Copying a message
You can copy the message item to quickly duplicate the message, by using the toolbar copy icon in the message options.
Deleting a message
You can delete a message item to remove it from the chat conversation, by using the toolbar trash icon in the message options.
Setting width
You can use the width
property to set width of the message toolbar in the chat. By default, the value is 100%
.
import { ChatUI, UserModel, MessageModel } from '@syncfusion/ej2-interactive-chat';
import { enableRipple } from '@syncfusion/ej2-base';
enableRipple(true);
let currentUserModel: UserModel = {
id: "user1",
user: "Albert"
};
let michaleUserModel: UserModel = {
id: "user2",
user: "Michale Suyama"
};
let chatMessages: MessageModel[] = [
{
author: currentUserModel,
text: "Hi Michale, are we on track for the deadline?"
},
{
author: michaleUserModel,
text: "Yes, the design phase is complete."
},
{
author: currentUserModel,
text: "I’ll review it and send feedback by today."
}
];
// Initializes the Chat UI control
let chatUI: ChatUI = new ChatUI({
messages: chatMessages,
user: currentUserModel,
messageToolbarSettings: {
width: '50%'
}
});
// Render initialized Chat UI.
chatUI.appendTo('#width');
<!DOCTYPE html>
<html lang="en">
<head>
<title>EJ2 Chat UI</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="TypeScript Chat UI Control" />
<meta name="author" content="Syncfusion" />
<link href="index.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-base/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-inputs/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-buttons/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-navigations/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-popups/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-interactive-chat/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-splitbuttons/styles/material.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<style>
.e-chat-ui .e-message-icon.custom-user {
background-color: #416fbd;
color: white;
border-radius: 5px;
}
</style>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container' style="height: 380px; width: 450px;">
<div id="width"></div>
</div>
</body>
</html>
Setting items
You can use the items
property to specify the toolbar item in the message toolbar of the chat.
import { ChatUI, UserModel, MessageModel } from '@syncfusion/ej2-interactive-chat';
import { enableRipple } from '@syncfusion/ej2-base';
enableRipple(true);
let currentUserModel: UserModel = {
id: "user1",
user: "Albert"
};
let michaleUserModel: UserModel = {
id: "user2",
user: "Michale Suyama"
};
let chatMessages: MessageModel[] = [
{
author: currentUserModel,
text: "Hi Michale, are we on track for the deadline?"
},
{
author: michaleUserModel,
text: "Yes, the design phase is complete."
},
{
author: currentUserModel,
text: "I’ll review it and send feedback by today."
}
];
// Initializes the Chat UI control
let chatUI: ChatUI = new ChatUI({
messages: chatMessages,
user: currentUserModel,
messageToolbarSettings: {
items: [
{ type: 'Button', iconCss: 'e-icons e-chat-forward', tooltip: 'Forward' },
{ type: 'Button', iconCss: 'e-icons e-chat-copy', tooltip: 'Copy' },
{ type: 'Button', iconCss: 'e-icons e-chat-reply', tooltip: 'Reply' },
{ type: 'Button', iconCss: 'e-icons e-chat-pin', tooltip: 'Pin' },
{ type: 'Button', iconCss: 'e-icons e-chat-trash', tooltip: 'Delete' }
]
}
});
// Render initialized Chat UI.
chatUI.appendTo('#items');
<!DOCTYPE html>
<html lang="en">
<head>
<title>EJ2 Chat UI</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="TypeScript Chat UI Control" />
<meta name="author" content="Syncfusion" />
<link href="index.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-base/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-inputs/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-buttons/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-navigations/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-popups/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-interactive-chat/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-splitbuttons/styles/material.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<style>
.e-chat-ui .e-message-icon.custom-user {
background-color: #416fbd;
color: white;
border-radius: 5px;
}
</style>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container' style="height: 380px; width: 450px;">
<div id="items"></div>
</div>
</body>
</html>
Setting itemClick
You can use the itemClicked
event when the toolbar item is clicked in the message toolbar of the chat.
import { ChatUI, UserModel, MessageModel, MessageToolbarItemClickedEventArgs } from '@syncfusion/ej2-interactive-chat';
import { enableRipple } from '@syncfusion/ej2-base';
enableRipple(true);
let currentUserModel: UserModel = {
id: "user1",
user: "Albert"
};
let michaleUserModel: UserModel = {
id: "user2",
user: "Michale Suyama"
};
let chatMessages: MessageModel[] = [
{
author: currentUserModel,
text: "Hi Michale, are we on track for the deadline?"
},
{
author: michaleUserModel,
text: "Yes, the design phase is complete."
},
{
author: currentUserModel,
text: "I’ll review it and send feedback by today."
}
];
// Initializes the Chat UI control
let chatUI: ChatUI = new ChatUI({
messages: chatMessages,
user: currentUserModel,
messageToolbarSettings: {
items: [
{ type: 'Button', iconCss: 'e-icons e-chat-forward', tooltip: 'Forward' },
{ type: 'Button', iconCss: 'e-icons e-chat-copy', tooltip: 'Copy' },
{ type: 'Button', iconCss: 'e-icons e-chat-reply', tooltip: 'Reply' },
{ type: 'Button', iconCss: 'e-icons e-chat-pin', tooltip: 'Pin' },
{ type: 'Button', iconCss: 'e-icons e-chat-trash', tooltip: 'Delete' }
],
itemClicked: (args: MessageToolbarItemClickedEventArgs) => {
if (args.item.prefixIcon === 'e-icons e-chat-forward') {
var newMessageObj = {
id: 'chat-message-' + (chatUI.messages.length + 1).toString(),
isForwarded: true,
isPinned: args.message.isPinned,
author: args.message.author,
text: args.message.text,
timeStamp: args.message.timeStamp,
timeStampFormat: args.message.timeStampFormat,
status: args.message.status,
replyTo: args.message.replyTo
};
chatUI.addMessage(newMessageObj);
}
}
}
});
// Render initialized Chat UI.
chatUI.appendTo('#itemClicked');
<!DOCTYPE html>
<html lang="en">
<head>
<title>EJ2 Chat UI</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="TypeScript Chat UI Control" />
<meta name="author" content="Syncfusion" />
<link href="index.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-base/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-inputs/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-buttons/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-navigations/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-popups/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-interactive-chat/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/30.1.37/ej2-splitbuttons/styles/material.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<style>
.e-chat-ui .e-message-icon.custom-user {
background-color: #416fbd;
color: white;
border-radius: 5px;
}
</style>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container' style="height: 380px; width: 450px;">
<div id="itemClicked"></div>
</div>
</body>
</html>