WhatsApp Client Component: sgcSocial | eSeGeCe

WhatsApp Client

TsgcWhatsApp_Client talks to the WhatsApp Business Cloud API, the Meta Graph API for WhatsApp. Send text, media, locations, contacts, reactions, interactive lists and buttons, and approved templates, then receive replies and delivery status through the built-in webhook server. The same component and the same API in Delphi and C++ Builder.

TsgcWhatsApp_Client

Copy the Phone Number ID and access token from your Meta application into WhatsAppOptions, call the SendMessage... methods, then StartServer to host the webhook that receives replies.

Component class

TsgcWhatsApp_Client

API

WhatsApp Business Cloud API (Meta Graph API)

Transport

Pure HTTPS, all Delphi platforms

Languages

Delphi, C++ Builder

Also inside sgcWebSockets. The WhatsApp client also ships inside sgcWebSockets editions from Professional up. sgcSocial is the standalone package, the sgcWebSockets Core runtime is bundled in.

Send a text, receive the reply

Set WhatsAppOptions.PhoneNumberId and Token, send a text, then start the webhook server so Meta can deliver inbound messages. TsgcWhatsApp_Client is declared in the sgcLibs unit.

uses
  sgcLibs;

var
  WhatsApp: TsgcWhatsApp_Client;
begin
  WhatsApp := TsgcWhatsApp_Client.Create(nil);
  WhatsApp.WhatsAppOptions.PhoneNumberId := '123456789012345';
  WhatsApp.WhatsAppOptions.Token := 'EAAG...';

  WhatsApp.SendMessageText('+34666555444', 'hello from Delphi');

  // webhook server: receive messages and status updates
  WhatsApp.ServerOptions.Port := 443;
  WhatsApp.ServerOptions.SSL := True;
  WhatsApp.ServerOptions.SSLOptions.CertFile := 'cert.pem';
  WhatsApp.ServerOptions.SSLOptions.KeyFile  := 'key.pem';
  WhatsApp.ServerOptions.SSLOptions.Port := 443;
  WhatsApp.OnMessageReceived := WhatsAppMessageReceived;
  WhatsApp.StartServer;
end;

procedure TForm1.WhatsAppMessageReceived(Sender: TObject;
  const aMessage: TsgcWhatsApp_Receive_Message;
  var aMarkAsRead: Boolean);
begin
  Memo1.Lines.Add(aMessage.RawMessage);
  aMarkAsRead := True;
end;
// include: sgcLibs.hpp

TsgcWhatsApp_Client *WhatsApp = new TsgcWhatsApp_Client(this);
WhatsApp->WhatsAppOptions->PhoneNumberId = "123456789012345";
WhatsApp->WhatsAppOptions->Token = "EAAG...";

WhatsApp->SendMessageText("+34666555444", "hello from Delphi");

// webhook server: receive messages and status updates
WhatsApp->ServerOptions->Port = 443;
WhatsApp->ServerOptions->SSL = true;
WhatsApp->ServerOptions->SSLOptions->CertFile = "cert.pem";
WhatsApp->ServerOptions->SSLOptions->KeyFile  = "key.pem";
WhatsApp->ServerOptions->SSLOptions->Port = 443;
WhatsApp->OnMessageReceived = WhatsAppMessageReceived;
WhatsApp->StartServer();

void __fastcall TForm1::WhatsAppMessageReceived(TObject *Sender,
    TsgcWhatsApp_Receive_Message * const aMessage, bool &aMarkAsRead)
{
  Memo1->Lines->Add(aMessage->RawMessage);
  aMarkAsRead = true;
}

Key properties & methods

The members you reach for most often.

Cloud API credentials

WhatsAppOptions.PhoneNumberId and WhatsAppOptions.Token, both from your Meta application. Every call is a plain HTTPS request to the Graph API.

Text, reactions, receipts

SendMessageText sends text, SendMessageReaction reacts to a message id, and MarkMessageRead sends the read receipt.

SendMessageImage, SendMessageDocument, SendMessageAudio, SendMessageVideo and SendMessageSticker reference media hosted at a public URL.

Media from a local file

SendFileImage, SendFileDocument, SendFileAudio, SendFileVideo and SendFileSticker upload the local file first, then send it.

Location and contacts

SendMessageLocation sends coordinates with a name and address. SendMessageContact sends contact cards.

Interactive messages

SendMessageInteractiveList for selection lists, SendMessageInteractiveButtons for reply buttons.

Templates

SendMessageTemplate takes the template name, the language code and the parameters.

Media store

UploadMedia, DownloadMedia and DeleteMedia work with the Cloud API media store directly.

Webhook server

StartServer and StopServer host the Meta webhook, configured through ServerOptions. OnBeforeSubscribe answers the verification request, OnMessageReceived delivers inbound messages with a var aMarkAsRead argument, OnMessageSent reports delivery status and OnRawMessage exposes the raw JSON.

TLS and logging

TLSOptions configures the HTTPS client, OnBeforeSendMessage inspects outbound messages, and file logging records the traffic for troubleshooting.

Keep exploring

sgcSocial OverviewBoth components, editions and licensing at a glance.
Feature Matrix: WhatsAppEvery capability of this component in table form.
WhatsApp API Deep DiveThe API reference page, with online help and PDF links.
Blog: WhatsApp Delphi ComponentA walkthrough of the Cloud API client.
Blog: Send Local Files with the WhatsApp APIUploading local media with the SendFile methods.
Best value: All-AccessEvery eSeGeCe product, Premium Support included, from €1,059/year.
See All-Access pricing

Ready to Send WhatsApp Messages?

Download the free trial and connect your Delphi application to the WhatsApp Business Cloud API.