Presses and private cards
A press reaches the code for its action. Here a slot machine only its player sees, which spins when they pull:
A press is a method too, marked with [Press] and named by its action:
using Woosh.Wisp;
public sealed class Slots(Chips chips){ [Command("slots", "A machine only you can see")] public Task Sit(CommandRun run) => run.AnswerPrivatelyAsync(Machine("β β β").Button("pull", "Pull"));
[Press("pull")] public async Task Pull(Press press) { // A frame while it spins. await press.ShowPrivatelyAsync(Machine("π π π")); var reels = chips.Spin(press.User.Id); var again = Machine(reels).Button("pull", "Pull again"); await press.UpdateAsync(reels, again); }
private static Card Machine(string reels) => new Card("#a855f7").Title("Your slots").Text(reels);}wisp.onPress names the action and what answers it:
import { actions, button, card, text, title, type Block, type Wisp } from "@woosh-no/wisp";
const machine = (reels: string, ...more: Block[]) => card({ color: "#a855f7", blocks: [title("Your slots"), text(reels), ...more] });
export function slots(wisp: Wisp, chips: Chips) { wisp.command("slots", "A machine only you can see", (run) => run.answerPrivately(machine("β β β", actions([button("pull", "Pull")]))));
wisp.onPress("pull", async (press) => { // A frame while it spins. await press.showPrivately(machine("π π π")); const reels = chips.spin(press.user.id); const again = machine(reels, actions([button("pull", "Pull again")])); await press.update(reels, again); });}Answering a press
Section titled βAnswering a pressβA press is answered once, within 15 seconds, like a run. Until then the button shows that your wisp is on it, and a second click of it does nothing.
| Answer | Shows |
|---|---|
press.UpdateAsync(text?, card or patch) |
the pressed card changes in place; words left out are written again from the new card |
press.UpdateAsync(text) |
words alone: a line changes its words and keeps its card; a private card becomes the words |
press.AnswerAsync(text, card?), press.AnswerAsync(card) |
a new line, as a reply to the pressed one |
press.AnswerPrivatelyAsync(text, card?), press.AnswerPrivatelyAsync(card) |
a private answer to the person who pressed |
press.ShowAsync(card or patch) |
a live frame on the pressed line while you work, kept nowhere |
press.ShowPrivatelyAsync(card) |
the same on a private card, always a whole card |
press.AskAsync(form) |
a form for the person to fill in |
press.User is who pressed, press.Action which action, and press.Value the value you put on the
button or cell (up to 100 bytes), or the choice picked from a menu.
| Answer | Shows |
|---|---|
press.update(text?, card or patch) |
the pressed card changes in place; words left out are written again from the new card |
press.update(text) |
words alone: a line changes its words and keeps its card; a private card becomes the words |
press.answer(text, card?), press.answer(card) |
a new line, as a reply to the pressed one |
press.answerPrivately(text, card?), press.answerPrivately(card) |
a private answer to the person who pressed |
press.show(card or patch) |
a live frame on the pressed line while you work, kept nowhere |
press.showPrivately(card) |
the same on a private card, always a whole card |
press.ask(form) |
a form for the person to fill in |
press.user is who pressed, press.action which action, and press.value the value you put on the
button or cell (up to 100 bytes), or the choice picked from a menu.
A game can keep its state in its own card that way and stay stateless. One handler can take several actions, with the press saying which:
public sealed class Blackjack(Table table){ [Press("hit"), Press("stand")] public Task Play(Press press) { var player = press.User.Id; var hand = press.Action == "hit" ? table.Hit(player) : table.Stand(player); return press.UpdateAsync(hand); }}Without attributes: wisp.OnPress("pull", press => ...).
const play = (press: Press) => { const player = press.user.id; const hand = press.action === "hit" ? table.hit(player) : table.stand(player); return press.update(hand);};
wisp.onPress("hit", play);wisp.onPress("stand", play);Private cards
Section titled βPrivate cardsβA card answered privately is for its person alone, and a press on it moves it on for them alone. It is the way to show one person something: a hand of cards, a balance, a settings menu. Woosh keeps a private card nowhere: it shows in the apps the person has open, until they dismiss it or close the app.
A card in the channel looks the same to everyone. To show each person something different, answer each one privately.
Tallies: buttons Woosh counts for you
Section titled βTallies: buttons Woosh counts for youβA tally is a button Woosh counts by itself: one press per person, and a second press takes it back. The count shows on the card for everyone, and it costs your wisp nothing, however many press. It is the button for giveaways, polls and sign-ups.
var line = await wisp.SendAsync(channel, new Card() .Title("Win a monitor") .Tally("enter", "Enter", Tone.Accent));const line = await wisp.send(channel, card({ blocks: [title("Win a monitor"), actions([tally("enter", "Enter", { tone: "accent" })])],}));When you want to know who is in, read them, or let Woosh draw winners at random:
var entered = await wisp.TallyAsync(line, "enter").CountAsync();IReadOnlyList<Guid> winners = await wisp.DrawAsync(line, "enter", 3);let entered = 0;for await (const _ of wisp.tally(line, "enter")) entered++;const winners = await wisp.draw(line, "enter", 3);A draw picks afresh each time, so keep the winners it gave you. To hear each press as it comes, add
the tally with tell: true, and your press handler gets it, saying whether it counted the person or
took them back (press.Counted; in TypeScript, press.counted).
Writing your own library? The frames underneath are in Presses and private cards, raw.