Cards
A card is a colour and a list of blocks. Woosh draws it natively in every app and every theme. You choose what goes on it, its tones and its sizes; you never write styles.
var card = new Card("#f97316") .Title("Win a monitor") .Picture(prize, "A 27 inch monitor", PictureSize.Large) .Text($"Entries close {Mark.Countdown(closes)}.", size: TextSize.Small) .Field("Prize", "Monitor") .Field("Winners", "1") .Progress(340, 500, label: "340 entries") .Tally("enter", "Enter", Tone.Accent) .Link("rules", "Rules", "https://example.com/rules");
await wisp.SendAsync(channel, card);Parts go on one at a time, in the order they show. Fields one after another share a block, and so do rows of cells, actions and pages; anything else in between starts a new block.
const giveaway = card({ color: "#f97316", blocks: [ title("Win a monitor"), picture(prize, "A 27 inch monitor", { size: "large" }), footnote(`Entries close ${mark.countdown(closes)}.`), fields([["Prize", "Monitor"], ["Winners", "1"]]), progress(340, 500, { label: "340 entries" }), actions([tally("enter", "Enter", { tone: "accent" }), link("rules", "Rules", "https://example.com/rules")]), ],});
await wisp.send(channel, giveaway);A card is a plain object, the JSON Cards, raw shows, and each block has a helper
that writes it with less to type. card() checks it where you made it.
What a card holds
Section titled “What a card holds”| Part | One at a time | From your own data, a block at once |
|---|---|---|
| words | Text(text, size?, tone?), Title(text), Footnote(text) |
|
| a name and its value | Field("Bet", "50"), up to 10 in a block |
Fields(pairs) |
| a row of cells: boards, reels, keypads | Row(Cell.Emoji("🍒"), ...), up to 5 rows of 5 |
Grid(rows) |
| a button, a menu, a tally or a link | Button(action, label, tone?, value?, off?), Menu(...), Tally(...), Link(...), up to 5 in a row |
Actions(...) |
| pages, turned in the app | Page("1 to 10", page => page.Text(...)), up to 10 |
Pages(...) |
| a picture, or several | Picture(url, alt, size?) |
Gallery(pictures) |
| words with a picture or an action beside them | Section(text, picture?, action?) |
|
| a bar | Progress(value, max, label?, tone?) |
|
| space | Divider() |
A cell is Cell.Text(...), Cell.Emoji(...) or Cell.Picture(url, alt), and .Pressable(action, value) makes it something to press, as on a board.
| Part | Helper |
|---|---|
| words | text(words, { size?, tone? }), title(words), footnote(words) |
| names and their values | fields([["Bet", "50"], ...]), up to 10 |
| a grid of cells: boards, reels, keypads | grid([[cell, ...], ...]), up to 5 rows of 5 |
| a button, a menu, a tally or a link | actions([...]) holding button(action, label, { tone?, value?, disabled? }), menu(...), tally(...), link(...), up to 5 |
| pages, turned in the app | pages([{ label: "1 to 10", blocks: [...] }, ...]), up to 10 |
| a picture, or several | picture(url, alt, { size? }), gallery([{ url, alt }, ...]) |
| words with a picture or an action beside them | section(words, { media?, action? }) |
| a bar | progress(value, max, { label?, tone? }) |
| space | divider() |
A cell is { text }, { emoji } or { url, alt }, and an action and a value make it something
to press, as on a board: { text: "·", action: "move", value: "3" }.
Tones colour words, cells, bars and buttons: neutral, accent, good, warn and bad
(Tone.Accent, or "accent"). Sizes are steps of Woosh’s own type: small, normal, large and
huge (TextSize.Large, or "large"). Both look right in every theme, because Woosh draws them.
A card is a value: every builder returns a new card, so a card made in a method is a template you can build on without changing it.
static Card Machine(string reels) => new Card("#a855f7").Title("Your slots").Text(reels);
var won = Machine("🍒 🍒 🍒").Text("Jackpot!", tone: Tone.Good);Words of your own make a card read like your wisp. A method on Card in your code builds on the
library’s:
using Woosh.Wisp;
static class CasinoCards{ public static Card Chips(this Card card, string name, int count) => card.Field(name, count.ToString("N0"));}var stats = new Card().Title("Your chips").Chips("Hands", 12).Chips("Won", 7);A card is a plain object, so a function that makes one is a template you can build on:
const machine = (reels: string, ...more: Block[]) => card({ color: "#a855f7", blocks: [title("Your slots"), text(reels), ...more] });
const won = machine("🍒 🍒 🍒", text("Jackpot!", { tone: "good" }));Words of your own make a card read like your wisp. A function in your code that writes a part builds on the library’s:
export const chips = (name: string, count: number): [string, string] => [name, count.toLocaleString("en")];const stats = card({ blocks: [title("Your chips"), fields([chips("Hands", 12), chips("Won", 7)])] });Marks in words
Section titled “Marks in words”| Mark | Shows |
|---|---|
Mark.Bold(text), Mark.Italic(text), Mark.Code(text) |
bold, italic, code |
Mark.User(id), Mark.Channel(id) |
a member or a channel, by name |
Mark.Countdown(time) |
“in 5 minutes”, counting down in the app, at no cost to you |
Mark.LocalTime(time) |
the time on the reader’s own clock |
| Mark | Shows |
|---|---|
mark.bold(text), mark.italic(text), mark.code(text) |
bold, italic, code |
mark.user(id), mark.channel(id) |
a member or a channel, by name |
mark.countdown(date) |
“in 5 minutes”, counting down in the app, at no cost to you |
mark.localTime(date) |
the time on the reader’s own clock |
Words for notifications
Section titled “Words for notifications”A line with a card carries words too, for notifications and for apps that do not draw cards. Send the card alone and Woosh writes them from the card’s words, block by block, top to bottom. Write your own when those would not say it well, as when the news is in a grid of emoji: the words first, then the card.
Checked before it is sent
Section titled “Checked before it is sent”A card that breaks one of Woosh’s rules, such as six rows in a grid or a key used twice, throws in
plain words where you built it, and costs nothing: an ArgumentException in C#, a WispRuleError
in TypeScript. A card holds at most 40 parts, 4,000 characters and 8 KB. One built from your own
data can outgrow that, such as a table of five players with long hands: card.Fits() (in
TypeScript, fits(card)) says whether it is within the limits, so you can send a shorter one
instead.
Pictures
Section titled “Pictures”Every picture on a card is a file your wisp uploaded. Woosh never shows a picture from somewhere else, so no outside site learns who looked:
string prize = await wisp.UploadPictureAsync("monitor.webp");const prize = await wisp.uploadPicture("monitor.webp");PNG, JPEG, WebP or GIF (animated too), up to 2 MB each and 1 GB in all, deleted with your wisp. Upload a picture once and use its address on as many of your cards as you like; another wisp’s picture is refused, and so is a file that is not the type it says.
Changing a card
Section titled “Changing a card”Edit a line to change its card for good: everyone looking sees the new one, and so does anyone who loads the channel later.
await wisp.EditAsync(line, newCard);await wisp.edit(line, newCard);Change parts, not cards. Give a block or a cell a key, then send only what changed:
var line = await wisp.SendAsync(channel, new Card() .Row(Cell.Emoji("❔").Keyed("reel-1"), Cell.Emoji("❔").Keyed("reel-2")) .Field("Coins", "1,000").Keyed("purse"));
await wisp.EditAsync(line, "cherry, lemon", new CardPatch() .Set("reel-1", Cell.Emoji("🍒")) .Set("reel-2", Cell.Emoji("🍋")) .Set("purse", card => card.Field("Coins", "950")));const line = await wisp.send(channel, card({ blocks: [ grid([[{ emoji: "❔", key: "reel-1" }, { emoji: "❔", key: "reel-2" }]]), fields([["Coins", "1,000"]], { key: "purse" }), ],}));
await wisp.edit(line, "cherry, lemon", patch({ "reel-1": { emoji: "🍒" }, "reel-2": { emoji: "🍋" }, purse: fields([["Coins", "950"]]),}));Motion is a live frame. It changes the card on the screens of the people looking, and Woosh keeps nothing of it: send as many as you like, and only the newest of a burst goes out. Finish with an edit, so the card stays as it ended.
foreach (var frame in spinning) await wisp.ShowAsync(line, frame);await wisp.EditAsync(line, result);for (const frame of spinning) await wisp.show(line, frame);await wisp.edit(line, result);For a reel that spins, an animated picture in a cell costs nothing at all once it has loaded.
Writing your own library? Every block’s keys and limits are in Cards, raw.