> ## Documentation Index
> Fetch the complete documentation index at: https://docs.codenullapp.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Notifications

> In order to use the notifications you need to call it via hooks, and you can notify (send notification)&#x20;

### **How to send a notification**

In order to use the notifications you need to call it via hooks, and you can notify (send notification)&#x20;

depends on your criteria, by users, roles, or all users.

To use it you need to follow these steps:

```javascript theme={null}
// Import the method to send notifications
const sendNotification = require("./utils/sendNotification").default;

const asyncFunctionExample = async (instance) => {

  await sendNotification({ usersTo: "email@test.com", 
  message: "message to send", title: "Notifications title" });
}
asyncFunctionExample(instance);
```

**Parameters**:

1. rolesTo (string): use it to send notifications to specific roles. To send multiple split by comma
2. usersTo (string): use it to send notifications to specific users. To send multiple split by comma
3. message (string): use it to send a message in the notification
4. title (string): use it to send a title in the notification
5. action (string): use it to send the feature you want to navigate
6. messageType (string): success | info | error | warning;

#### **How to send to multiple users**

To send a notification to multiple users, you can send it with the email of the user already registered in the app or the Id of the user in the database, everything separated by commas to add multiple users, also you can combine the Id of the user and/or emails.

Use the parameter **usersTo.**

```javascript theme={null}
sendNotification(
{ 
usersTo: "email@test.com,1386223D-0515-4042-98E7-9DC2ADBE3C39,emailTwo@test.com", 
message: "message to send", title: "Notifications title" }
);
```

#### **How to send to multiple roles**

To send a notification to multiple roles add the parameter **usersTo** and put the roleId and/or rolesId you want to send notifications, it will send a notification to every user with the Role sent in.

To send it to multiple roles add them separated by commas.

```javascript theme={null}
sendNotification(
{ 
rolesTo: "FD6B02C0-AD10-4FDC-83BB-0354880FB4F1,1386223D-0515-4042-98E7-9DC2ADBE3C39", 
message: "message to send", title: "Notifications title" }
);
```

#### Hot to send to multiple roles and users

To send the notification to specific users and/or roles you can combine them just using the both parameters (rolesTo and usersTo).

```javascript theme={null}

sendNotification(
{ 
rolesTo: "FD6B02C0-AD10-4FDC-83BB-0354880FB4F1,1386223D-0515-4042-98E7-9DC2ADBE3C39", 
usersTo: "email@test.com,1386223D-0515-4042-98E7-9DC2ADBE3C39,emailTwo@test.com", 
message: "message to send", title: "Notifications title" }
);
```

#### How to send to all users

If you want to send a notification to all users in the app, do not use the parameters rolesTo and usersTo, to tell the app that need to send it to all users.

```javascript theme={null}
sendNotification({ 
message: "message to send", title: "Notifications title" }
);
```

#### Navigate to a feature when the user clicks the notification

To send a notification that allows navigate to another feature you have to add the **action** parameter with the URL of the feature you want to go.

```javascript theme={null}
sendNotification(
{ 
usersTo: "email@test.com,1386223D-0515-4042-98E7-9DC2ADBE3C39,emailTwo@test.com", 
message: "message to send", title: "Notifications title" },
action: "/feature/6052169f34c619001287669c"
);
```

Also you can use the context of the UI application, To do that you need to send parameters

```javascript theme={null}
//the next two examples are equivalent.

//setup action with params
//this scenario is recomended only when you need some data that only exist on the UI session
//Otherwise we recommend send the action as an URL
sendNotification(
{ 
usersTo: "email@test.com,1386223D-0515-4042-98E7-9DC2ADBE3C39,emailTwo@test.com", 
message: "message to send", title: "Notifications title" },
action: "{featureId: '6052169f34c619001287669c', params: [{type: 'querystring', value: 'abc-123', name='Id'}]}"
);

//the result of this action will be a url like 
// /feature/6052169f34c619001287669c?Id=abc-123

// setup action only with url
sendNotification(
{ 
usersTo: "email@test.com,1386223D-0515-4042-98E7-9DC2ADBE3C39,emailTwo@test.com", 
message: "message to send", title: "Notifications title" },
action: "/feature/6052169f34c619001287669c?Id=abc-123"
);
```
