Skip to main content
Table of Contents

Getting started with TMS FNC WhatsApp Receiver

Prerequisites

  • TMS FNC Core and TMS FNC WebSocket installed (see Installation).
  • A running TTMSFNCWhatsAppServer that hosts your WhatsApp webhook.
  • For VCL and FMX applications, the OpenSSL libraries next to the executable; the receiver always connects securely.

Add the component

  1. Drop TTMSFNCWhatsAppReceiver from the TMS FNC WebSocket palette page onto a form, or create one at runtime.
  2. Set HostName and Port (and PathName when the server uses one) to the address of the WhatsApp server.
  3. Handle OnWhatsAppMessageReceived, then set Active := True or call Connect.

Handle incoming messages

Connect and handle incoming messagesPascalC++
procedure TForm1.FormCreate(Sender: TObject);
begin
  // wss://hooks.example.com:443/  - the host running TTMSFNCWhatsAppServer
  TMSFNCWhatsAppReceiver1.HostName := 'hooks.example.com';
  TMSFNCWhatsAppReceiver1.Port := 443;
  TMSFNCWhatsAppReceiver1.Active := True;
end;

procedure TForm1.TMSFNCWhatsAppReceiver1WhatsAppMessageReceived(Sender: TObject;
  AMessage: TTMSFNCWhatsAppReceiverMessage);
var
  Line: string;
begin
  // Read what you need now: AMessage is freed when the handler returns.
  Line := AMessage.From.Name + ' (' + AMessage.From.Phone + '): ' + AMessage.Text.Body;

  // In VCL and FMX applications this event runs on a background thread.
  TThread.Queue(nil,
    procedure
    begin
      Memo1.Lines.Add(Line);
    end);
end;
void __fastcall TForm1::FormCreate(TObject *Sender)
{
  // wss://hooks.example.com:443/  - the host running TTMSFNCWhatsAppServer
  TMSFNCWhatsAppReceiver1->HostName = "hooks.example.com";
  TMSFNCWhatsAppReceiver1->Port = 443;
  TMSFNCWhatsAppReceiver1->Active = true;
}

void __fastcall TForm1::AddLine()
{
  Memo1->Lines->Add(FLine);
}

void __fastcall TForm1::TMSFNCWhatsAppReceiver1WhatsAppMessageReceived(TObject *Sender,
  TTMSFNCWhatsAppReceiverMessage *AMessage)
{
  // Read what you need now: AMessage is freed when the handler returns.
  FLine = AMessage->From->Name + " (" + AMessage->From->Phone + "): " + AMessage->Text->Body;

  // In VCL and FMX applications this event runs on a background thread.
  TThread::Queue(nullptr, AddLine);
}

Next steps