Skip to content

Notify Preview

What one notification destination gets for a message, drawn as its place shows it, from the preview StolonNotifier.Preview returns in C#. A Discord post looks as Discord's dark theme shows it, a webhook shows its request line over the body, a Jellyfin message shows as the web client's toast, and a web push shows as a browser notification. See Notifications for the C# half.

Decision

When Use
A settings page shows what an update looks like on each place it goes Notify Preview, one per destination
A preview with no server, such as plain JSON Code Block

Usage

import { createNotifyPreview } from './configurationpage?name=myplugin_stolon.js';

shared.apiRequest('Notifications/Preview', 'POST', { Title: title, Text: text }).then(function (previews) {
    previews.forEach(function (p) {
        host.appendChild(createNotifyPreview({ preview: p }).element);
    });
});

Classes: stolon-notify-preview, with the parts stolon-notify-preview-line, stolon-notify-preview-method, stolon-notify-preview-address, stolon-notify-preview-type, and stolon-notify-preview-body for a webhook, stolon-notify-preview-screen and stolon-notify-preview-toast for a Jellyfin message, stolon-notify-preview-push and its -icon, -text, -title, -body, -site, and -image for a web push, and stolon-notify-preview-discord and its parts for a Discord post. The handle is { element, setPreview, destroy }.

States and Modifiers

  • The preview's keys may be PascalCase, as Jellyfin's API writes them, or camelCase. Channel is a name, such as Discord, or its number.
  • A preview with an Error shows the error in a Callout, such as "Discord needs a JSON body.".
  • A Discord post reads Discord, the post as data, else parses Body. It shows the name, the "App" tag, the time, any text, and each embed with its color bar, author, title, text, fields three to a row, image, thumbnail, and footer. Discord's markdown in the text is drawn, and a masked link shows in the link color and never as a link. username names a post whose body names none, "Jellyfin" by default.
  • A webhook shows its method, the address as "Saved address" (addressText), since the stored address never reaches the page, and the content type, over the body exactly as sent, laid out when it is JSON.
  • A Jellyfin message shows its text as the toast. A note under it names the header, which apps other than the web client show above the text.
  • A web push shows its title, text, icon, and image, and the page's host as its site (site).
  • setPreview draws another preview in its place, and null clears it.

Gotchas

  • Only http and https images load. Any other address, such as data: or javascript:, is left out.
  • The Discord post keeps Discord's own colors in every Jellyfin theme, from the --stolon-discord-* tokens.

Reference

Generated from the code by scripts/build-docs.mjs. Edit the code, not this section.

createNotifyPreview

function createNotifyPreview(options?: NotifyPreviewOptions): NotifyPreviewHandle

Draws what one destination gets for a message, from the preview StolonNotifier returns: a Discord post as Discord's dark theme shows it, a webhook's request line over its body, a Jellyfin message as the web client's toast, or a web push as a browser notification. A preview with an error shows the error.

Option Type What it does
preview NotifyPreviewData | null the preview from StolonNotifier.Preview [optional]
username string the name a Discord post comes from when its body names none (default 'Jellyfin')
addressText string the address a webhook's request line shows, since the stored address never reaches the page (default 'Saved address')
site string the site a web push names under its text (default the page's host)
now Date the time a Discord post shows (default the time it is drawn)
Handle member Type
setPreview (preview: NotifyPreviewData | null | undefined): void
destroy (): void
Type What it is
NotifyChannelName A channel a notification goes to, by name or by StolonNotifier's number.
NotifyPreviewData What StolonNotifier.Preview returns for one destination, with its keys in PascalCase as Jellyfin's API writes them, or in camelCase.
Class What it looks like
stolon-notify-preview What one notification destination gets, drawn as its place shows it, from StolonNotifier's preview
stolon-notify-preview-line A webhook's request line, its method, address, and content type, joined to the Code Block of its body below
stolon-notify-preview-screen A Jellyfin message as the web client's toast, at the bottom left of a strip of the page, with a note under it
stolon-notify-preview-push A web push as a browser notification on the floating surface: the icon, then the title, text, site, and image
stolon-notify-preview-discord A Discord post in Discord's dark theme, in any Jellyfin theme: the avatar beside the name, app tag, time, text, and embeds
stolon-notify-preview-discord-embed One embed with a bar of its color, from the post as a custom color, beside its parts and an optional thumbnail

Example

Example Code

<!-- title: Notify Preview -->
<div id="mount" style="display: grid; gap: 16px;"></div>
<script type="module">
const base = await window.__baseReady;
const mount = document.getElementById('mount');
const discord = {
    username: 'Jellyfin',
    embeds: [{
        title: 'Approved: Dune (2021)',
        url: 'https://jellyfin.example.com/web/',
        description: 'Dune \\(2021\\) was approved by **admin**.',
        color: 0x00A4DC,
        fields: [{ name: 'Requester', value: 'viewer', inline: true }, { name: 'Seasons', value: 'All', inline: true }, { name: 'Notes', value: 'For movie night', inline: false }],
        timestamp: new Date().toISOString()
    }],
    allowed_mentions: { parse: [] }
};
const previews = [
    { Channel: 'Discord', Method: 'POST', ContentType: 'application/json', Body: JSON.stringify(discord), Discord: discord },
    { Channel: 'Webhook', Method: 'POST', ContentType: 'application/json', Body: JSON.stringify({ title: 'Approved: Dune (2021)', message: 'Dune (2021) was approved.', link: 'https://jellyfin.example.com/web/' }) },
    { Channel: 'Jellyfin', Header: 'Approved: Dune (2021)', Text: 'Dune (2021) was approved.' },
    { Channel: 'WebPush', Method: 'POST', ContentType: 'application/json', Body: JSON.stringify({ title: 'Approved: Dune (2021)', body: 'Dune (2021) was approved.', url: 'https://jellyfin.example.com/web/' }) },
    { Channel: 'Discord', Error: 'Discord needs a JSON body.' }
];
previews.forEach((p) => mount.appendChild(base.createNotifyPreview({ preview: p, site: 'jellyfin.example.com' }).element));
</script>