Chat
TsgcHTMLComponent_Chat — a WhatsApp-style messenger with text, image, file, audio and video messages, read receipts, replies and date separators, in Delphi, C++ Builder and .NET.
TsgcHTMLComponent_Chat — a WhatsApp-style messenger with text, image, file, audio and video messages, read receipts, replies and date separators, in Delphi, C++ Builder and .NET.
A full chat surface that emits scoped CSS plus the messenger markup: a header with avatar, grouped bubbles, status ticks, media attachments and a composer. Add messages, set the header, then read the HTML property.
TsgcHTMLComponent_Chat
Scoped CSS + messenger markup
Delphi, C++ Builder, .NET
Set the header (Title, Subtitle, HeaderAvatarInitials), add text, image and file messages, handle OnSendMessage, then read HTML.
uses
sgcHTML_Enums, sgcHTML_Component_Chat;
var
oChat: TsgcHTMLComponent_Chat;
begin
oChat := TsgcHTMLComponent_Chat.Create(nil);
try
oChat.Title := 'Alice Johnson';
oChat.Subtitle := 'online';
oChat.HeaderAvatarInitials := 'AJ';
oChat.Height := '500px';
oChat.ShowTypingIndicator := True;
oChat.OnSendMessage := DoSendMessage; // browser -> your code
oChat.AddSystemMessage('Today');
oChat.AddMessage('Alice', 'Hey! Did you get the file?', maLeft);
oChat.AddImageMessage('You', '/img/receipt.png', maRight,
hcPrimary, 'Here it is');
oChat.AddFileMessage('You', '/files/report.pdf',
'report.pdf', '248 KB', maRight);
WebModule.Response := oChat.HTML; // messenger markup + scoped CSS
finally
oChat.Free;
end;
end;
// OnSendMessage fires when the visitor submits the composer:
procedure TForm1.DoSendMessage(Sender: TObject; const aMessage: string);
begin
oChat.AddMessage('You', aMessage, maRight, hcPrimary);
WebSocket.WriteData(oChat.GetLastMessageHTML);
end;
// includes: sgcHTML_Enums.hpp, sgcHTML_Component_Chat.hpp
TsgcHTMLComponent_Chat *oChat = new TsgcHTMLComponent_Chat(NULL);
try
{
oChat->Title = "Alice Johnson";
oChat->Subtitle = "online";
oChat->HeaderAvatarInitials = "AJ";
oChat->Height = "500px";
oChat->ShowTypingIndicator = true;
oChat->OnSendMessage = DoSendMessage; // browser -> your code
oChat->AddSystemMessage("Today");
oChat->AddMessage("Alice", "Hey! Did you get the file?", maLeft);
oChat->AddImageMessage("You", "/img/receipt.png", maRight,
hcPrimary, "Here it is");
oChat->AddFileMessage("You", "/files/report.pdf",
"report.pdf", "248 KB", maRight);
String html = oChat->HTML; // messenger markup + scoped CSS
}
__finally
{
delete oChat;
}
using esegece.sgcWebSockets;
var chat = new TsgcHTMLComponent_Chat();
chat.Title = "Alice Johnson";
chat.Subtitle = "online";
chat.HeaderAvatarInitials = "AJ";
chat.Height = "500px";
chat.ShowTypingIndicator = true;
chat.OnSendMessage += (sender, message) => // browser -> your code
{
chat.AddMessage("You", message, TsgcHTMLChatMessageAlign.maRight, TsgcHTMLColor.hcPrimary);
};
chat.AddSystemMessage("Today");
chat.AddMessage("Alice", "Hey! Did you get the file?", TsgcHTMLChatMessageAlign.maLeft);
chat.AddImageMessage("You", "/img/receipt.png", TsgcHTMLChatMessageAlign.maRight,
TsgcHTMLColor.hcPrimary, "Here it is");
chat.AddFileMessage("You", "/files/report.pdf",
"report.pdf", "248 KB", TsgcHTMLChatMessageAlign.maRight);
string html = chat.HTML; // messenger markup + scoped CSS
The members you reach for most often.
Messages is a TsgcHTMLChat_Messages collection; each TsgcHTMLChat_Message carries Text, MessageType (text/image/file/audio/video/system), Status, ReplyToSender/ReplyToText and IsForwarded.
AddMessage, AddImageMessage, AddFileMessage and AddSystemMessage(...) append bubbles; maLeft/maRight pick the side.
Title, Subtitle, HeaderAvatarURL and HeaderAvatarInitials build the conversation header (an "online" subtitle adds the green dot).
ShowInput, InputPlaceholder, ShowAttachButton, ShowEmojiButton, ShowTypingIndicator and TypingText tune the bottom bar.
Options (a TsgcHTMLChat_Options) sets MaxBubbleWidth, bubble/background colors, ShowTimestamp, ShowStatus, GroupConsecutive and ShowDateSeparators.
OnSendMessage fires when the visitor submits the composer; OnMediaClick fires on a media tap. HTML returns the chat; GetLastMessageHTML returns just the newest bubble for live pushes.