How to send notifications to users of Totalum
1. What are notifications in Totalum?
A Totalum notification, sends an email to all or some of the users of your Totalum that you want to notify with a custom text. Also, the user can see the notification visually in their Totalum account.
2. How to send notifications to users of Totalum
2.1 body of the notification
The notification object has the following structure:
interface NotificationI {
name: string;
title: string;
description: string;
visibility: {
sendTo: 'all' | 'admins' | 'specificUsers'; // "all" will send the notification to all users of Totalum, "admins" will send the notification to all admins of Totalum, "specificUsers" will send the notification to the users that you specify in the field specificUsersEmails
specificUsersEmails?: string[]; // this field is only required if sendTo is 'specificUsers' (put here the list of emails of the users you want to send the notification to)
},
action: {
actionType: 'link' | 'none'; //put link if you want to set a button clickable that opens the link in the Totalum account
actionName?: string;
link?: string;
};
email: {
sendEmail: boolean; //put it true if you want to send an email to the users, else put it false and the users will only see the notification in their Totalum account
};
}
Using Totalum SDK
If you don't have the Totalum SDK installed, follow the instructions in the installation section.
const notification = {
name: "your notification name",
title: "Your Notification Title",
description: "The text that you want to send to the users",
visibility: {
sendTo: "all",
specificUsersEmails: []
},
action: {
actionType: "link",
actionName: "activar",
link: "https://www.google.com/" //put custom link if needed
},
email: {
sendEmail: true,
}
};
const resultCreation = await totalumClient.notification.createNotification(notification);
Using Totalum API
This is an example using javascript and axios, but you can use any language and library to make the request.
const notification = {
name: "your notification name",
title: "Your Notification Title",
description: "The text that you want to send to the users",
visibility: {
sendTo: "all",
specificUsersEmails: []
},
action: {
actionType: "link",
actionName: "activar",
link: "https://www.google.com/" //put custom link if needed
},
email: {
sendEmail: true,
}
};
const resultCreation = await axios.post('https://api.totalum.app/api/v1/notifications/', {notification: notification}, {
headers: {
'Content-Type': 'application/json',
'api-key': 'your api key here', // replace 'your api key here' with your api key
}
});