Sending Notifications
This page explains in detail how to send notifications in ElyOS from both client and server side.
Client Side (Recommended)
Section titled “Client Side (Recommended)”The sendNotification function is the simplest way to send notifications from apps.
import { sendNotification } from '$lib/services/client/notificationService';
await sendNotification({ userId: 123, title: 'Saved successfully', message: 'The data has been successfully saved', type: 'success'});Multilingual Notification
Section titled “Multilingual Notification”await sendNotification({ userId: 123, title: { hu: 'Sikeres mentés', en: 'Successful save' }, message: { hu: 'Az adatok sikeresen mentésre kerültek', en: 'The data has been successfully saved' }, type: 'success'});Notification with App Opening
Section titled “Notification with App Opening”If you provide the appName field, clicking the notification will open the app:
await sendNotification({ userId: 123, appName: 'users', title: { hu: 'Új csoport létrehozva', en: 'New group created' }, message: { hu: 'A "Fejlesztők" csoport sikeresen létrehozva', en: 'The "Developers" group has been successfully created' }, details: { hu: 'A csoport 5 taggal rendelkezik és 3 jogosultsággal', en: 'The group has 5 members and 3 permissions' }, type: 'success', data: { section: 'groups', // Which sidebar menu item to activate groupId: '456' }});Broadcast to All Users
Section titled “Broadcast to All Users”await sendNotification({ broadcast: true, title: { hu: 'Rendszer karbantartás', en: 'System maintenance' }, message: { hu: 'A rendszer 10 perc múlva leáll karbantartás miatt', en: 'The system will shut down in 10 minutes for maintenance' }, type: 'warning'});To Multiple Users
Section titled “To Multiple Users”await sendNotification({ userIds: [123, 456, 789], title: { hu: 'Csapat értesítés', en: 'Team notification' }, message: { hu: 'Új feladat lett hozzárendelve a csapathoz', en: 'A new task has been assigned to the team' }, type: 'info'});Server Side
Section titled “Server Side”You can also send notifications from server actions or API endpoints:
import { sendNotification } from '$lib/server/socket';
export const createGroup = command(createGroupSchema, async (input) => { // ... create group ...
// Send notification await sendNotification({ userId: creatorId, appName: 'users', title: { hu: 'Csoport létrehozva', en: 'Group created' }, message: { hu: `A "${input.name}" csoport sikeresen létrehozva`, en: `The "${input.name}" group has been successfully created` }, type: 'success', data: { section: 'groups', groupId: newGroup.id } });
return { success: true, group: newGroup };});Notification Types
Section titled “Notification Types”info (Default)
Section titled “info (Default)”General informational notifications.
await sendNotification({ userId: 123, title: { hu: 'Emlékeztető', en: 'Reminder' }, message: { hu: 'Ne felejtsd el a meetinget 15:00-kor', en: 'Don\'t forget the meeting at 3 PM' }, type: 'info'});Appearance: Blue icon, toast notification
success
Section titled “success”Feedback for successful operations.
await sendNotification({ userId: 123, title: { hu: 'Sikeres feltöltés', en: 'Upload successful' }, message: { hu: 'A fájl sikeresen feltöltésre került', en: 'The file has been uploaded successfully' }, type: 'success'});Appearance: Green icon, toast notification
warning
Section titled “warning”Warnings that are not critical.
await sendNotification({ userId: 123, title: { hu: 'Figyelmeztetés', en: 'Warning' }, message: { hu: 'A tárhelyed 80%-ban megtelt', en: 'Your storage is 80% full' }, type: 'warning'});Appearance: Yellow icon, toast notification
Errors that require user action.
await sendNotification({ userId: 123, title: { hu: 'Hiba történt', en: 'Error occurred' }, message: { hu: 'A fájl feltöltése sikertelen volt', en: 'File upload failed' }, type: 'error'});Appearance: Red icon, toast notification
critical
Section titled “critical”Critical notifications that appear immediately in a modal dialog.
await sendNotification({ userId: 123, title: { hu: 'Kritikus biztonsági figyelmeztetés', en: 'Critical security warning' }, message: { hu: 'A fiókod gyanús tevékenységet észlelt. Kérlek változtasd meg a jelszavad!', en: 'Suspicious activity detected on your account. Please change your password!' }, type: 'critical'});Appearance: Red icon, modal dialog (interrupts the user’s work)
Important: critical type notifications:
- Appear immediately in a modal dialog
- Interrupt the user’s work
- Must be acknowledged (OK button)
- Are automatically marked as read after acknowledgment
Best Practices
Section titled “Best Practices”1. Always use multilingual content
Section titled “1. Always use multilingual content”// ✅ Goodawait sendNotification({ userId: 123, title: { hu: 'Sikeres mentés', en: 'Successful save' }, message: { hu: 'Az adatok sikeresen mentésre kerültek', en: 'The data has been successfully saved' }, type: 'success'});
// ❌ Avoid (only works for backward compatibility)await sendNotification({ userId: 123, title: 'Successful save', message: 'The data has been successfully saved', type: 'success'});2. Use appName when the notification relates to an app
Section titled “2. Use appName when the notification relates to an app”// ✅ Good - clicking the notification opens the appawait sendNotification({ userId: 123, appName: 'users', title: { hu: 'Új csoport', en: 'New group' }, message: { hu: 'Csoport létrehozva', en: 'Group created' }, type: 'success', data: { section: 'groups', groupId: '456' }});
// ❌ Avoid - clicking the notification does nothingawait sendNotification({ userId: 123, title: { hu: 'Új csoport', en: 'New group' }, message: { hu: 'Csoport létrehozva', en: 'Group created' }, type: 'success'});3. Use the data field for app-specific information
Section titled “3. Use the data field for app-specific information”await sendNotification({ userId: 123, appName: 'users', title: { hu: 'Új csoport', en: 'New group' }, message: { hu: 'Csoport létrehozva', en: 'Group created' }, type: 'success', data: { section: 'groups', // Which sidebar menu item groupId: '456', // Which item action: 'view' // What action }});4. Use the appropriate type
Section titled “4. Use the appropriate type”- info — General information
- success — Successful operations
- warning — Warnings
- error — Errors
- critical — Critical warnings (use sparingly)
5. Provide a details field for detailed information
Section titled “5. Provide a details field for detailed information”await sendNotification({ userId: 123, title: { hu: 'Új csoport', en: 'New group' }, message: { hu: 'Csoport létrehozva', en: 'Group created' }, details: { hu: 'A csoport 5 taggal rendelkezik és 3 jogosultsággal. A csoport adminisztrátora: John Doe.', en: 'The group has 5 members and 3 permissions. Group administrator: John Doe.' }, type: 'success'});