> For the complete documentation index, see [llms.txt](https://developers-apps-in-toss.toss.im/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developers-apps-in-toss.toss.im/documentation/api-and-sdk-en/sdk/domains-api/promotion/promotion.opencontactsinvite.md).

# Promotion.openContactsInvite

> Functional API `contactsViral`You can use the same function here as well. The functional API returns an empty cleanup function instead of throwing an error if the app version does not support it.

### Feature description

It provides a feature to share with friends and receive rewards. When a user completes sharing with a friend, reward information is delivered through an event.

Toss app **5.223.0** can be used on versions above. Before calling, `Promotion.openContactsInvite.isSupported()`You can check support with it. If called in an unsupported version, `UNSUPPORTED_APP_VERSION` an error occurs.

The returned cleanup function must be called after the sharing feature ends to release resources.

### Type

```ts
Promotion.openContactsInvite(params: ContactsViralParams): () => void;
```

**Params**

```ts
type ContactsViralOption = {
  /** This is a unique UUID-form ID that identifies the sharing reward. You can check it in the Mini App > Share Rewards menu in the Appintos console. */
  moduleId: string;
};

type RewardFromContactsViralEvent = {
  type: "sendViral";
  data: {
    rewardAmount: number;
    rewardUnit: string;
  };
};

type ContactsViralSuccessEvent = {
  type: "close";
  data: {
    closeReason: "clickBackButton" | "noReward";
    sentRewardAmount?: number;
    sendableRewardsCount?: number;
    sentRewardsCount: number;
    rewardUnit?: string;
  };
};

type ContactsViralEvent =
  RewardFromContactsViralEvent | ContactsViralSuccessEvent;

type ContactsViralParams = {
  options: ContactsViralOption;
  onEvent: (event: ContactsViralEvent) => void;
  onError: (error: unknown) => void;
};
```

**Response**

It returns the app bridge cleanup function.

### Error code

The error code is `onError`can be received or the `try/catch`error caught in `error.code` value.

| Code                      | Description                                                                                                                                                                                                                                        |
| ------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `UNSUPPORTED_APP_VERSION` | If the running Toss app version does not support this feature, it occurs immediately upon calling. `Promotion.openContactsInvite.isSupported()`Check in advance with, and if it occurs `error.message`show the user the (update guidance message). |

### Example code

```js
import { Promotion } from "@apps-in-toss/web-framework";

function handleOpenContactsInvite(moduleId) {
  try {
    const cleanup = Promotion.openContactsInvite({
      options: { moduleId: moduleId.trim() },
      onEvent: (event) => {
        if (event.type === "sendViral") {
          console.log(
            "Reward granted:",
            event.data.rewardAmount,
            event.data.rewardUnit,
          );
        } else if (event.type === "close") {
          console.log("Module closed:", event.data.closeReason);
          cleanup();
        }
      },
      onError: (error) => {
        console.error("Error occurred:", error);
        cleanup?.();
      },
    });
  } catch (error) {
    console.error("Runtime error:", error);
  }
}

document
  .querySelector("#contacts-invite")
  .addEventListener("click", () => handleOpenContactsInvite("MODULE_ID"));
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://developers-apps-in-toss.toss.im/documentation/api-and-sdk-en/sdk/domains-api/promotion/promotion.opencontactsinvite.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
