toast

repository·master·Indexed 19 days ago

https://github.com/go-toast/toast

A Go package and CLI tool for triggering Windows 10 toast notifications. It provides a Go API via the gopkg.in/toast.v1 package and a command-line interface for configuring notification titles, messages, icons, audio, and interactive action buttons.

Tokens
1.2K
Snippets
4
Records
4
Agent score
17%

What's inside toast

  1. Send toast notifications using the Go API

    master

    To send notifications within a Go application, use the gopkg.in/toast.v1 package. Create a toast.Notification struct and call its .Push() method.

    Notification Fields:

    • AppID: The application identifier.
    • Title: The notification title.
    • Message: The notification body text.
    • Icon: Path to an existing image file to use as an icon.
    • Actions: A slice of toast.Action objects to provide interactive buttons.
    package main
    
    import (
        "log"
    
        "gopkg.in/toast.v1"
    )
    
    func main() {
        notification := toast.Notification{
            AppID: "Example App",
            Title: "My notification",
            Message: "Some message about how important something is...",
            Icon: "go.png", // This file must exist
            Actions: []toast.Action{
                {"protocol", "I'm a button", ""},
                {"protocol", "Me too!", ""},
            },
        }
        err := notification.Push()
        if err != nil {
            log.Fatalln(err)
        }
    }
  2. Use the Toast CLI for Windows notifications

    master

    You can use the toast CLI tool to trigger Windows 10 toast notifications from any project. Download the appropriate binary (64-bit or 32-bit) and use the following flags to configure your notification:

    • --app-id: The identifier for your application.
    • --title: The heading of the notification.
    • --message: The body text of the notification.
    • --icon: Path to an icon image file.
    • --audio: Specify audio to play (e.g., default).
    • --loop: Enables looping audio.
    • --duration: Sets the notification duration (e.g., long).
    • --activation-arg: An argument passed when the notification is activated.
    • --action: Defines a button. Requires a corresponding --action-arg.
    C:\Users\Example\Downloads\toast64.exe \
      --app-id "Example App" \
      --title "Hello World" \
      --message "Lorem ipsum dolor sit amet, consectetur adipiscing elit." \
      --icon "C:\Users\Example\Pictures\icon.png" \
      --audio "default" --loop \
      --duration "long" \
      --activation-arg "https://google.com" \
      --action "Open maps" --action-arg "bingmaps:?q=sushi" \
      --action "Open browser" --action-arg "http://..."
  3. Reference: toast CLI flags

    master

    The following flags are available to configure the toast notification via the CLI:

    FlagShorthandDescription
    --app-id-idThe app identifier (used for grouping multiple toasts)
    --title-tThe main toast title/heading
    --message-mThe toast's main message (new lines as separator)
    --icon-iThe app icon path (displays to the left of the toast)
    --activation-typeThe type of action to invoke when the user clicks the toast (default: protocol)
    --activation-argThe activation argument
    --actionOptional action button (StringSlice)
    --action-typeThe type of action button (StringSlice)
    --action-argThe action button argument (StringSlice)
    --audioWhich kind of audio should be played (default: silent)
    --loopWhether to loop the audio (Boolean)
    --durationHow long the toast should display for (default: short)
    # Example with multiple action buttons
    toast --title "Alert" --message "System update available" \
      --action "Install Now" --action-type "protocol" --action-arg "myapp://install" \
      --action "Later" --action-type "protocol" --action-arg "myapp://later"
  4. Use the toast CLI to send notifications

    master

    The toast CLI allows you to send Windows 10 toast notifications directly from the command line. You can specify the title, message, icon, and various interaction behaviors like activation types and action buttons using flags.

    toast --title "Hello" --message "This is a notification"