Posted-file actions and external links
Declare attachments to add an action to the right-click menus of posted files, images and GIFs. Add external_links to open a public HTTPS page from the resulting trusted context, and ui for a disclosure dialog.
Resolve the selected file
Section titled “Resolve the selected file”cleanup.push( await api.attachments.registerContextAction( { id: "file-details", label: "File details", submenu: { id: "tools", label: "Tools" }, }, async (context) => { try { const file = await api.attachments.resolve(context.handle); await api.ui.notify(file.filename + ": " + file.size + " bytes"); } catch { await api.ui.notify( "File context expired or unavailable. Open the file menu again.", ); } }, ),);The callback receives { handle, filename, kind }. Resolution returns { id, filename, size, url }. The host requests only the clicked message’s metadata and resolves an exact attachment ID or unique filename. Ambiguous duplicate names fail rather than guessing.
Images and GIFs
Section titled “Images and GIFs”By default an action appears on posted file cards only. List kinds to choose where it appears: "file" for file cards, "image" for images shown in a message, and "gif" for GIFs, including ones sent from Fluxer’s GIF picker. The context’s kind says which one the user right-clicked, and its filename is a name taken from the media’s address, for display.
cleanup.push( await api.attachments.registerContextAction( { id: "media-name", label: "Show name", kinds: ["image", "gif"] }, (context) => api.ui.notify(`${context.kind}: ${context.filename}`), ),);attachments.resolve works for images and GIFs that were posted as files. An image or GIF embedded from a link has no attachment to resolve and fails with attachment_not_a_file. Videos other than GIFs, and unsent uploads, get no action. This differs from ui.registerAttachmentAction, which adds a composer action.
To turn an image or GIF into a sticker, pass its handle to stickers.add; see stickers.
Open an external page
Section titled “Open an external page”Call await api.externalLinks.open(url) within the live context. A link opens only right after the user acts: a trusted activation of your file-menu action or a native-dialog submission in that context, or any other user action in your plugin’s UI (a menu item, decoration button, dialog submit or shortcut) within the last 1.5 seconds. A file-menu authorization expires after two minutes and is single-use; it never enters the sandbox.
Before sharing an attachment URL with a third-party website, show a disclosure and allow cancellation. URLs may include signed access parameters. Do not log them. Virus Check demonstrates the full consent flow and safe URL encoding.
Lifetime and failures
Section titled “Lifetime and failures”Attachment handles expire after five minutes or upon navigation, replacement, another context selection, or shutdown. Ordinary menu dismissal after activation does not invalidate the selected context.
Lookup is limited to ten seconds, 1 MiB response data, and 100 attachments. External URLs must use public-host HTTPS without credentials or nonstandard ports; literal IPs and local hostnames are rejected.
After context or authorization errors, ask the user to activate the file menu again. External links open the browser; they do not return network response content.
FluxPlugs is an independent project, not affiliated with or endorsed by Fluxer.