Skip to content

contactsViral

친구에게 공유하고 리워드를 받을 수 있는 기능을 제공해요. 사용자가 친구에게 공유를 완료하면, 앱 브릿지를 통해 이벤트가 전달되고, 해당 이벤트를 기반으로 리워드 정보를 받을 수 있어요.

주의하세요

  • 본 기능은 토스앱 5.223.0 버전부터 지원해요. 하위 버전에서는 undefined가 반환됩니다.
  • 기능 사용을 위해서는 미니앱 승인이 반드시 필요합니다. 미승인 상태에서는 Internal Server Error가 발생합니다.

참고하세요

  • 테스트 환경(샌드박스 앱)에서는 빈 화면으로 보여요. 리워드 지급 버튼을 눌러도 실제로 동작하지 않아요.
  • 콘솔 내 QR코드로 테스트를 진행해 주세요.
  • 콘솔에 등록된 리워드 ID를 활용하여 테스트를 할 수 있어요.
  • 친구 목록은 상호 연락처 저장 여부 외에도 다음 조건에 따라 달라질 수 있어요
    • 마케팅 수신 동의 여부
    • 야간 마케팅 수신 동의 여부
    • 푸시 토큰 등록 여부
    • 연락처 알림 차단 여부

시그니처

ts
function contactsViral(params: ContactsViralParams): () => void;

파라미터

  • params필수

    연락처 공유 기능을 실행할 때 사용하는 파라미터예요. 옵션 설정과 이벤트 핸들러를 포함해요.
    자세한 내용은 ContactsViralParams 문서를 참고하세요.

반환값

  • () => void

    앱브릿지 cleanup 함수를 반환해요. 공유 기능이 끝나면 반드시 이 함수를 호출해서 리소스를 해제해야 해요.

예제

친구에게 공유하고 리워드 받기

tsx
import { contactsViral } from '@apps-in-toss/web-framework';
import { Button } from '@toss-design-system/mobile';
import { useCallback } from 'react';

function ContactsViralButton({ moduleId }: { moduleId: string }) {
  const handleContactsViral = useCallback(() => {
    try {
      const cleanup = contactsViral({
        options: { moduleId: moduleId.trim() },
        onEvent: (event) => {
          if (event.type === 'sendViral') {
            console.log('리워드 지급:', event.data.rewardAmount, event.data.rewardUnit);
          } else if (event.type === 'close') {
            console.log('모듈 종료:', event.data.closeReason);
          }
        },
        onError: (error) => {
          console.error('에러 발생:', error);
        },
      });

      return cleanup;
    } catch (error) {
      console.error('실행 중 에러:', error);
    }
  }, [moduleId]);

  return <Button onClick={handleContactsViral}>친구에게 공유하고 리워드 받기</Button>;
}
tsx
import { contactsViral } from '@apps-in-toss/framework';
import { Button } from '@toss-design-system/react-native';
import { useCallback } from 'react';

function ContactsViralButton({ moduleId }: { moduleId: string }) {
  const handleContactsViral = useCallback(() => {
    try {
      const cleanup = contactsViral({
        options: { moduleId: moduleId.trim() },
        onEvent: (event) => {
          if (event.type === 'sendViral') {
            console.log('리워드 지급:', event.data.rewardAmount, event.data.rewardUnit);
          } else if (event.type === 'close') {
            console.log('모듈 종료:', event.data.closeReason);
          }
        },
        onError: (error) => {
          console.error('에러 발생:', error);
        },
      });

      return cleanup;
    } catch (error) {
      console.error('실행 중 에러:', error);
    }
  }, [moduleId]);

  return <Button onPress={handleContactsViral}>친구에게 공유하고 리워드 받기</Button>;
}