WhatsApp Client
TsgcWhatsApp_Client는 WhatsApp용 Meta Graph API인 WhatsApp Business Cloud API와 통신합니다. 텍스트, 미디어, 위치, 연락처, 리액션, 인터랙티브 목록과 버튼, 승인된 템플릿을 전송하고, 내장된 웹훅 서버를 통해 응답과 전달 상태를 수신합니다. Delphi와 C++ Builder에서 같은 컴포넌트, 같은 API를 사용합니다.
TsgcWhatsApp_Client는 WhatsApp용 Meta Graph API인 WhatsApp Business Cloud API와 통신합니다. 텍스트, 미디어, 위치, 연락처, 리액션, 인터랙티브 목록과 버튼, 승인된 템플릿을 전송하고, 내장된 웹훅 서버를 통해 응답과 전달 상태를 수신합니다. Delphi와 C++ Builder에서 같은 컴포넌트, 같은 API를 사용합니다.
Meta 애플리케이션에서 발급받은 전화번호 ID와 액세스 토큰을 WhatsAppOptions에 복사하고, SendMessage... 메서드를 호출한 다음, StartServer로 응답을 수신하는 웹훅을 호스팅하세요.
TsgcWhatsApp_Client
WhatsApp Business Cloud API (Meta Graph API)
순수 HTTPS, 모든 Delphi 플랫폼
Delphi, C++ Builder
sgcWebSockets 안에도 포함되어 있습니다. WhatsApp 클라이언트는 sgcWebSockets Professional 에디션부터도 포함되어 있습니다. sgcSocial은 단독 패키지이며 sgcWebSockets Core 런타임이 함께 포함되어 있습니다.
WhatsAppOptions.PhoneNumberId와 Token을 설정하고, 텍스트를 전송한 다음, Meta가 수신 메시지를 전달할 수 있도록 웹훅 서버를 시작하세요. TsgcWhatsApp_Client는 sgcLibs 유닛에 선언되어 있습니다.
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;
}
가장 자주 사용하게 되는 멤버들입니다.
WhatsAppOptions.PhoneNumberId와 WhatsAppOptions.Token 모두 Meta 애플리케이션에서 발급받습니다. 모든 호출은 Graph API에 대한 일반 HTTPS 요청입니다.
SendMessageText는 텍스트를 전송하고, SendMessageReaction은 메시지 ID에 반응하며, MarkMessageRead는 읽음 확인을 전송합니다.
SendMessageImage, SendMessageDocument, SendMessageAudio, SendMessageVideo, SendMessageSticker는 공개 URL에 호스팅된 미디어를 참조합니다.
SendFileImage, SendFileDocument, SendFileAudio, SendFileVideo, SendFileSticker는 로컬 파일을 먼저 업로드한 다음 전송합니다.
SendMessageLocation은 이름과 주소가 있는 좌표를 전송합니다. SendMessageContact는 연락처 카드를 전송합니다.
선택 목록에는 SendMessageInteractiveList, 답장 버튼에는 SendMessageInteractiveButtons를 사용합니다.
SendMessageTemplate는 템플릿 이름, 언어 코드, 매개변수를 받습니다.
UploadMedia, DownloadMedia, DeleteMedia가 Cloud API 미디어 저장소와 직접 작동합니다.
StartServer와 StopServer가 ServerOptions로 구성되는 Meta 웹훅을 호스팅합니다. OnBeforeSubscribe는 검증 요청에 응답하고, OnMessageReceived는 var aMarkAsRead 인자와 함께 수신 메시지를 전달하며, OnMessageSent는 전달 상태를 보고하고, OnRawMessage는 원시 JSON을 노출합니다.
TLSOptions가 HTTPS 클라이언트를 구성하고, OnBeforeSendMessage가 발신 메시지를 검사하며, 파일 로깅이 문제 해결을 위해 트래픽을 기록합니다.