Skip to content

Notification Component

The Notification component allows your script to send notifications to the user. This includes standard desktop notifications as well as messages to external services like Discord, Telegram, and Email.

Usage

When implementing your script's onStart, execute, or onFinish methods, you can access the Notification component through the provided ComponentProvider.

The notification DSL function is used to construct the notification object, which is then sent using the sendNotification method.

import com.cereal.sdk.component.notification.notification

suspend fun execute(provider: ComponentProvider) {
    val notificationComponent = provider.notification()

    // Create a notification using the DSL
    val myNotification = notification("Your order has been successfully processed") {
        // Optional title for desktop notification
        title { "Purchase Complete" }

        // Optional Discord message
        discordMessage {
            content { "Order #12345 has been processed." }
            // You can also add embeds, etc.
        }

        // Optional Telegram message
        telegramMessage {
            message { "Order #12345 processed." }
        }
    }

    // Send the notification
    notificationComponent.sendNotification(myNotification)
}

Supported Channels

The Notification component supports the following channels:

  • Desktop Notification: Displays a system-level notification to the user.
  • Discord: Sends a message to a configured Discord webhook.
  • Telegram: Sends a message to a configured Telegram bot/chat.
  • Email: Sends an email to a configured address.

Note: The user must configure the respective external services (Discord Webhook URL, Telegram Bot Token/Chat ID, Email settings) in the Cereal application settings for these channels to work.

Important Considerations

  • Best Effort Delivery: Users can disable notifications globally or for specific channels. There is no guarantee that the user will receive or see the notification.
  • Urgency: Desktop notifications attract immediate attention. Use them only for important events.
  • Logging: For general status updates or debugging information, use the Logger component instead.

Best Practices

Notifications are most appropriate for:

  • Time-sensitive actions requiring user input.
  • Completion of long-running processes.
  • Critical errors that require immediate attention.
  • Important status updates (e.g., successful purchases).