Chat

TsgcHTMLComponent_Chat — un mensajero estilo WhatsApp con mensajes de texto, imagen, archivo, audio y vídeo, confirmaciones de lectura, respuestas y separadores de fecha, en Delphi, C++ Builder y .NET.

TsgcHTMLComponent_Chat

Una superficie de chat completa que emite CSS con ámbito más el marcado del mensajero: una cabecera con avatar, burbujas agrupadas, marcas de estado, adjuntos multimedia y un redactor. Añade mensajes, define la cabecera y luego lee la propiedad HTML.

Clase de componente

TsgcHTMLComponent_Chat

Renderiza

CSS con ámbito + marcado del mensajero

Familia

Chat e IA

Lenguajes

Delphi, C++ Builder, .NET

Créalo, añade mensajes, renderízalo

Define la cabecera (Title, Subtitle, HeaderAvatarInitials), añade mensajes de texto, imagen y archivo, gestiona OnSendMessage y luego lee 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

Propiedades y métodos clave

Los miembros que más vas a usar.

Mensajes

Messages es una colección TsgcHTMLChat_Messages; cada TsgcHTMLChat_Message lleva Text, MessageType (texto/imagen/archivo/audio/vídeo/sistema), Status, ReplyToSender/ReplyToText e IsForwarded.

Añadir mensajes

AddMessage, AddImageMessage, AddFileMessage y AddSystemMessage(...) añaden burbujas; maLeft/maRight eligen el lado.

Cabecera

Title, Subtitle, HeaderAvatarURL y HeaderAvatarInitials construyen la cabecera de la conversación (un subtítulo "online" añade el punto verde).

Redactor

ShowInput, InputPlaceholder, ShowAttachButton, ShowEmojiButton, ShowTypingIndicator y TypingText ajustan la barra inferior.

Opciones

Options (un TsgcHTMLChat_Options) define MaxBubbleWidth, los colores de burbuja/fondo, ShowTimestamp, ShowStatus, GroupConsecutive y ShowDateSeparators.

Eventos y salida

OnSendMessage se dispara cuando el visitante envía el redactor; OnMediaClick se dispara al pulsar un elemento multimedia. HTML devuelve el chat; GetLastMessageHTML devuelve solo la burbuja más reciente para envíos en vivo.

Sigue explorando

Todos los componentes sgcHTMLExplora la matriz completa de más de 60 componentes.
Descargar prueba gratuitaLa prueba de 30 días incluye los proyectos demo 60.HTML.
PreciosLicencias Single, Team y Site con código fuente completo.

¿Listo para empezar?

Descarga la prueba gratuita y empieza a crear interfaces web en Delphi, C++ Builder y .NET.