QuickStart
Send a WhatsApp message, in about ten lines
Set the phone number id and the token, call SendMessageText, and read the response the Graph API sent back.
uses
Classes, SysUtils,
sgcLibs, sgcLib_WhatsApp_Client;
procedure TFRMWhatsApp.btnSendMessageClick(Sender: TObject);
begin
whatsapp.WhatsAppOptions.PhoneNumberId := '1234567890';
whatsapp.WhatsAppOptions.Token := GetToken;
DoLog('Message Sent: ' + whatsapp.SendMessageText(
'+34600000000', 'Hello from Delphi'));
end;
That is the whole send path. Nothing else has to be configured, and no server has to be running. SendMessageImage, SendMessageDocument, SendMessageLocation, SendMessageContact, SendMessageInteractiveButtons and SendMessageTemplate follow the same shape.
procedure TFRMWhatsApp.FormCreate(Sender: TObject);
begin
whatsapp.NotifyEvents := neAsynchronous;
whatsapp.StartServer;
end;
procedure TFRMWhatsApp.whatsappMessageReceived(Sender: TObject;
const aMessage: TsgcWhatsApp_Receive_Message; var aMarkAsRead: Boolean);
begin
if aMessage.Messages.Count > 0 then
begin
DoLog(aMessage.Messages._Message[0].Text.Body);
aMarkAsRead := True;
end;
end;
Receiving is optional. StopServer shuts the listener down again, and OnBeforeSubscribe is where you accept or reject Meta's verification request, through its var Accept: Boolean parameter.
uses
Classes, SysUtils,
sgcLibs, sgcLib_Telegram;
procedure TFRMSGCTelegram.btnStartClick(Sender: TObject);
begin
SetTDJsonPath(ExtractFilePath(ParamStr(0)));
sgcTelegram.Telegram.API.ApiId := GetApiId;
sgcTelegram.Telegram.API.ApiHash := GetApiHash;
sgcTelegram.Telegram.PhoneNumber := '+34600000000';
sgcTelegram.Active := True;
end;
To sign in as a bot instead, leave PhoneNumber empty and set Telegram.BotToken. Authorisation is event driven from there: OnAuthorizationStatus, OnAuthenticationCode and OnAuthenticationPassword ask you for what TDLib needs next.