WhatsApp Client 컴포넌트: sgcSocial | eSeGeCe

WhatsApp Client

TsgcWhatsApp_Client는 WhatsApp용 Meta Graph API인 WhatsApp Business Cloud API와 통신합니다. 텍스트, 미디어, 위치, 연락처, 리액션, 인터랙티브 목록과 버튼, 승인된 템플릿을 전송하고, 내장된 웹훅 서버를 통해 응답과 전달 상태를 수신합니다. Delphi와 C++ Builder에서 같은 컴포넌트, 같은 API를 사용합니다.

TsgcWhatsApp_Client

Meta 애플리케이션에서 발급받은 전화번호 ID와 액세스 토큰을 WhatsAppOptions에 복사하고, SendMessage... 메서드를 호출한 다음, StartServer로 응답을 수신하는 웹훅을 호스팅하세요.

컴포넌트 클래스

TsgcWhatsApp_Client

API

WhatsApp Business Cloud API (Meta Graph API)

전송

순수 HTTPS, 모든 Delphi 플랫폼

언어

Delphi, C++ Builder

sgcWebSockets 안에도 포함되어 있습니다. WhatsApp 클라이언트는 sgcWebSockets Professional 에디션부터도 포함되어 있습니다. sgcSocial은 단독 패키지이며 sgcWebSockets Core 런타임이 함께 포함되어 있습니다.

텍스트를 보내고 응답을 수신하기

WhatsAppOptions.PhoneNumberIdToken을 설정하고, 텍스트를 전송한 다음, Meta가 수신 메시지를 전달할 수 있도록 웹훅 서버를 시작하세요. TsgcWhatsApp_ClientsgcLibs 유닛에 선언되어 있습니다.

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;
}

주요 속성 & 메서드

가장 자주 사용하게 되는 멤버들입니다.

Cloud API 자격 증명

WhatsAppOptions.PhoneNumberIdWhatsAppOptions.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 미디어 저장소와 직접 작동합니다.

웹훅 서버

StartServerStopServerServerOptions로 구성되는 Meta 웹훅을 호스팅합니다. OnBeforeSubscribe는 검증 요청에 응답하고, OnMessageReceivedvar aMarkAsRead 인자와 함께 수신 메시지를 전달하며, OnMessageSent는 전달 상태를 보고하고, OnRawMessage는 원시 JSON을 노출합니다.

TLS와 로깅

TLSOptions가 HTTPS 클라이언트를 구성하고, OnBeforeSendMessage가 발신 메시지를 검사하며, 파일 로깅이 문제 해결을 위해 트래픽을 기록합니다.

계속 살펴보기

sgcSocial 개요두 컴포넌트, 에디션, 라이선스를 한눈에 볼 수 있습니다.
기능 매트릭스: WhatsApp이 컴포넌트의 모든 기능을 표 형태로 확인하세요.
WhatsApp API 심화온라인 도움말과 PDF 링크가 포함된 API 레퍼런스 페이지입니다.
블로그: WhatsApp Delphi 컴포넌트Cloud API 클라이언트를 다루는 안내입니다.
블로그: WhatsApp API로 로컬 파일 전송하기SendFile 메서드로 로컬 미디어를 업로드합니다.
최고의 가성비: All-Access모든 eSeGeCe 제품과 프리미엄 지원이 포함되어 연 €1,059부터 이용할 수 있어요.
All-Access 가격 보기

WhatsApp 메시지를 보낼 준비가 되셨나요?

무료 체험판을 다운로드하고 Delphi 애플리케이션을 WhatsApp Business Cloud API에 연결해 보세요.