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.
사전 요구 사항
- sgcWebSockets Professional 또는 Enterprise.
- 유효한 App ID, App Secret, Access Token이 있는 활성 WhatsApp Business Platform 계정.
- WhatsApp 컴포넌트 패키지가 등록된 sgcWebSockets 설치.
Delphi에서 컴포넌트 설정
TsgcWhatsAppClient 컴포넌트를 데이터 모듈이나 서비스 폼에 드래그하세요. Object Inspector에서 또는 초기화 코드에서 필수 속성을 설정하세요.
디자인 타임 설정
- Meta가 제공한 발신자 전화 ID로 PhoneNumberID를 채워요.
- AccessToken을 할당하고, 서명된 요청을 강제하는 경우 선택적으로 AppSecretProof도 할당해요.
- AutoReconnect를 true로 설정해 WebSocket 채널을 유지해요.
- 배달 확인 및 수신 채팅 처리를 위해 OnMessageStatus 및 OnIncomingMessage 이벤트를 연결해요.
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;
메시지 보내기
고수준 시나리오에는 SendText와 SendTemplate 헬퍼 메서드를 사용하고, 고급 페이로드에는 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;
고급 설정
- 템플릿 관리: ListTemplates를 호출해 승인된 메시지 템플릿을 가져와 메모리에 캐시해요.
- 미디어 업로드: TBytesStream과 함께 UploadMedia를 사용해 PDF, 이미지, 음성 메모를 전달해요.
- 예약: TsgcScheduler와 결합해 CRM 트리거 기반 캠페인을 조율해요.
- 분석: OnMessageStatus 이벤트를 연결해 BI 대시보드용 배달/읽음 확인을 로깅해요.
WhatsApp 컴포넌트 사용 장점
- 통합 지원 스택: 기존 sgcWebSockets 전송과 원활하게 통합되어 HTTP, MQTT, AMQP, WhatsApp 메시징을 위한 단일 프레임워크를 유지해요.
- 강력한 보안: TLS 1.3 지원, 설정 가능한 토큰 갱신 간격, 서명 검증이 모든 메시지를 보호해요.
- 높은 처리량: 내장 스로틀링과 병렬 전송 대기열이 Meta 요청 속도 제한을 지키면서 캠페인을 빠르게 전달할 수 있게 해요.
- 개발자 생산성: Delphi 컴포넌트, 이벤트, 속성 편집기가 코드를 강하게 형식화되고 IDE 친화적으로 유지해 유지 보수 부담을 줄여요.
- 확장 가능한 배포: 논블로킹 소켓과 비동기 콜백 덕분에 Windows 서비스, 데스크톱 앱, 부하 분산 서버 전반에서 작동해요.
