WhatsApp Delphi 컴포넌트

· 컴포넌트

The sgcWebSockets WhatsApp component empowers Delphi teams to deliver instant, personalized conversations at scale. Whether you build CRM integrations, help-desk portals or transactional notification services, the component provides a secure, resilient and fully supported bridge to WhatsApp Business messaging. This article combines the commercial value with the technical detail you need to deliver production-ready chat flows quickly. 

비즈니스 효과 한눈에 보기

아키텍처 개요

The component encapsulates the WhatsApp Business API REST endpoints and WebSocket callbacks into a Delphi-friendly interface. It manages token refreshes, message formatting (text, templates, media) and asynchronous delivery reports. Internally it relies on sgcWebSockets core transports, so you benefit from the same TLS, reconnection and threading model used throughout the framework. 

사전 요구 사항

Delphi에서 컴포넌트 설정

TsgcWhatsAppClient 컴포넌트를 데이터 모듈이나 서비스 폼에 드래그하세요. Object Inspector에서 또는 초기화 코드에서 필수 속성을 설정하세요.

디자인 타임 설정

  1. Meta가 제공한 발신자 전화 ID로 PhoneNumberID를 채워요.
  2. AccessToken을 할당하고, 서명된 요청을 강제하는 경우 선택적으로 AppSecretProof도 할당해요.
  3. AutoReconnect를 true로 설정해 WebSocket 채널을 유지해요.
  4. 배달 확인 및 수신 채팅 처리를 위해 OnMessageStatusOnIncomingMessage 이벤트를 연결해요.

procedure TdmMessaging.DataModuleCreate(Sender: TObject);
begin
  sgcWhatsAppClient.BaseURL := 'https://graph.facebook.com/v18.0/';
  sgcWhatsAppClient.PhoneNumberID := '123456789012345';
  sgcWhatsAppClient.AccessToken := TSecretStore.FetchToken('WA_ACCESS');
  sgcWhatsAppClient.WebhookVerifyToken := 'MyDelphiWebhook';
  sgcWhatsAppClient.AutoReconnect := True;
  sgcWhatsAppClient.Connect;
end; 

메시지 보내기

고수준 시나리오에는 SendTextSendTemplate 헬퍼 메서드를 사용하고, 고급 페이로드에는 Messages 컬렉션에 직접 접근하세요.

procedure TdmMessaging.SendWelcomeMessage(const ADestination: string);
var
  LMessage: TsgcWAOutboundMessage;
begin
  LMessage := sgcWhatsAppClient.Messages.Add;
  LMessage.ToPhone := ADestination;
  LMessage.TypeMessage := watText;
  LMessage.Text.Body := 'Welcome to our premium support channel!';
  sgcWhatsAppClient.SendMessage(LMessage);
end; 

응답 수신 및 자동화

The component includes a built-in webhook listener leveraging sgcWebSockets HTTP server features. Map the webhook path to your published endpoint and process replies inside event handlers. 

procedure TdmMessaging.sgcWhatsAppClientIncomingMessage(Sender: TObject;
  const AMessage: TsgcWAInboundMessage);
begin
  if AMessage.Text.Body.ToLower.Contains('pricing') then
    sgcWhatsAppClient.SendText(AMessage.FromPhone,
      'Ask about our enterprise bundles for priority SLA and analytics dashboards.')
  else
    QueueForAgent(AMessage);
end; 

고급 설정

WhatsApp 컴포넌트 사용 장점