# Notification Functions

> You'll need to import the javascript file in your website before starting from this [link](https://docs.webtonative.com/javascript-apis/getting-started).

## Register Notification

Registers the app for push notifications and returns the user's permission status along with the OneSignal player ID and Firebase token.

{% tabs %}
{% tab title="Plain Javascript" %}

```javascript
window.WTN.registerNotification({
  callback: function (response) {
    console.log(response.permissionStatus);
    console.log(response.oneSignalPlayerId);
    console.log(response.firebaseToken);
  },
});
```

{% endtab %}

{% tab title="ES5+" %}

```javascript
import { registerNotification } from "webtonative";

registerNotification({
  callback: (response) => {
    console.log(response.permissionStatus);
    console.log(response.oneSignalPlayerId);
    console.log(response.firebaseToken);
  },
});
```

{% endtab %}
{% endtabs %}

**Parameters:**

| Key        | Type       | Required | Description                                  |
| ---------- | ---------- | -------- | -------------------------------------------- |
| `callback` | `Function` | No       | Callback function invoked with the response. |

**Callback Response:**

| Key                 | Type     | Description                                                         |
| ------------------- | -------- | ------------------------------------------------------------------- |
| `type`              | `String` | Always `"registerNotification"`.                                    |
| `permissionStatus`  | `String` | The notification permission status: `"ALLOWED"` or `"NOT_ALLOWED"`. |
| `oneSignalPlayerId` | `String` | The OneSignal player ID for this device.                            |
| `firebaseToken`     | `String` | The Firebase Cloud Messaging token for this device.                 |

***

## Remove All Notifications

Removes all currently displayed push notifications for the app from the device's notification tray/center.

{% tabs %}
{% tab title="Plain Javascript" %}

```javascript
window.WTN.removeAllNotifications({
  callback: function (response) {
    console.log(response.isSuccess);
  },
});
```

{% endtab %}

{% tab title="ES5+" %}

```javascript
import { removeAllNotifications } from "webtonative";

removeAllNotifications({
  callback: (response) => {
    console.log(response.isSuccess);
  },
});
```

{% endtab %}
{% endtabs %}

**Parameters:**

| Key        | Type       | Required | Description                                  |
| ---------- | ---------- | -------- | -------------------------------------------- |
| `callback` | `Function` | No       | Callback function invoked with the response. |

**Callback Response:**

| Key         | Type               | Description                                                               |
| ----------- | ------------------ | ------------------------------------------------------------------------- |
| `type`      | `String`           | Always `"removeAllNotifications"`.                                        |
| `isSuccess` | `Boolean`          | `true` if all notifications were removed successfully, `false` otherwise. |
| `error`     | `String` or `null` | `null` on success. Error message describing what went wrong on failure.   |

**Example:**

```javascript
window.WTN.removeAllNotifications({
  callback: function (response) {
    if (response.isSuccess) {
      console.log("All notifications removed successfully.");
    } else {
      console.error("Failed to remove notifications:", response.error);
    }
  },
});
```


---

# Agent Instructions: 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:

```
GET https://docs.webtonative.com/javascript-apis/notification-functions.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
