Chat

TsgcHTMLComponent_Chat — um mensageiro estilo WhatsApp com mensagens de texto, imagem, arquivo, áudio e vídeo, confirmações de leitura, respostas e separadores de data, em Delphi, C++ Builder e .NET.

TsgcHTMLComponent_Chat

Uma superfície de chat completa que emite CSS com escopo mais o markup do mensageiro: um cabeçalho com avatar, bolhas agrupadas, ticks de status, anexos de mídia e um compositor. Adicione mensagens, defina o cabeçalho e então leia a propriedade HTML.

Classe do componente

TsgcHTMLComponent_Chat

Renderiza

CSS com escopo + markup do mensageiro

Família

Chat & IA

Linguagens

Delphi, C++ Builder, .NET

Crie, adicione mensagens, renderize

Defina o cabeçalho (Title, Subtitle, HeaderAvatarInitials), adicione mensagens de texto, imagem e arquivo, trate OnSendMessage e então leia 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

Principais propriedades & métodos

Os membros que você usa com mais frequência.

Mensagens

Messages é uma coleção TsgcHTMLChat_Messages; cada TsgcHTMLChat_Message carrega Text, MessageType (texto/imagem/arquivo/áudio/vídeo/sistema), Status, ReplyToSender/ReplyToText e IsForwarded.

Adicionar mensagens

AddMessage, AddImageMessage, AddFileMessage e AddSystemMessage(...) adicionam bolhas; maLeft/maRight escolhem o lado.

Cabeçalho

Title, Subtitle, HeaderAvatarURL e HeaderAvatarInitials constroem o cabeçalho da conversa (um subtítulo "online" adiciona o ponto verde).

Compositor

ShowInput, InputPlaceholder, ShowAttachButton, ShowEmojiButton, ShowTypingIndicator e TypingText ajustam a barra inferior.

Opções

Options (uma TsgcHTMLChat_Options) define MaxBubbleWidth, cores de bolha/fundo, ShowTimestamp, ShowStatus, GroupConsecutive e ShowDateSeparators.

Eventos & saída

OnSendMessage dispara quando o visitante envia pelo compositor; OnMediaClick dispara ao tocar em uma mídia. HTML retorna o chat; GetLastMessageHTML retorna apenas a bolha mais recente para envios ao vivo.

Continue explorando

Todos os Componentes sgcHTMLExplore a matriz completa de recursos com mais de 60 componentes.
Baixar Versão de Avaliação GratuitaA avaliação de 30 dias inclui os projetos de demonstração 60.HTML.
PreçosLicenças Single, Team e Site com código-fonte completo.

Pronto para Começar?

Baixe a versão de avaliação gratuita e comece a construir UIs web em Delphi, C++ Builder e .NET.