Skip to content

Forms

A form is a sheet of fields a person fills in and sends once: a poll’s question and answers, a giveaway’s prize, the reason for a report. Your wisp asks with one in answer to a run or a press, the person’s app opens it at once, and what they send reaches the code for the form’s action.

using Woosh.Wisp;
public sealed class Polls(Ballots ballots)
{
[Command("poll", "Ask the channel something")]
public Task New(CommandRun run) => run.AskAsync(NewPoll());
[Form("new-poll")]
public async Task Post(Press sent)
{
var answers = sent.Values.Text("answers")!
.Split('\n')
.Select(a => a.Trim())
.Where(a => a.Length > 0)
.ToArray();
var different = answers.Distinct().Count() == answers.Length;
if (answers.Length is < 2 or > 10 || !different)
{
var error = "2 to 10 answers, each a different one.";
await sent.UpdateAsync(NewPoll().WithError("answers", error));
return;
}
var question = sent.Values.Text("question")!;
var many = sent.Values.Choice("pick") == "many";
var ends = sent.Values.Time("ends");
var poll = ballots.Open(question, answers, many, ends);
// A line in the channel: the sheet closes.
await sent.AnswerAsync($"{sent.User} asks: {question}", poll);
}
private static Form NewPoll()
{
var now = DateTimeOffset.UtcNow;
return new Form("new-poll", "New poll")
.Text("Everyone sees the answers as they come in.")
.Text("question", "Question", required: true, max: 300)
.Text("answers", "Answers", "One per line, 2 to 10",
required: true, lines: 6, max: 900)
.Choice("pick", "People pick",
[("one", "One answer"), ("many", "As many as they like")],
prefill: "one")
.Time("ends", "Ends", required: true,
prefill: now.AddDays(1), min: now, max: now.AddDays(7))
.Submit("Post poll");
}
}

Fields show in the order they are given, up to 10:

Field Holds Its answer
Text lines, min, max (characters) Values.Text
Number min, max Values.Number
Integer min, max, whole numbers only Values.Integer
Member, Channel, Role Values.Member, .Channel, .Role
Choice one of up to 25 Values.Choice
Choices several of up to 25, as tick boxes Values.Choices
Toggle on or off; required means it must be on (“I read the rules”) Values.Toggle, always there
Time min, max: a day and a time, picked to the minute Values.Time

Each takes a description, required, and a prefill filled in as the sheet opens, so settings show as they stand. A field left empty is null, or an empty list for Choices.

Woosh checks every answer against its field before your wisp hears it: required ones are there, each is within its limits, a member is in the server. What is left to you is your own rules.

Answer with the same form and WithError under a field, or WithNotice for the whole form by its send button, and the sheet stays open with everything the person typed.

Answer Shows
sent.UpdateAsync(form) the sheet stays open and moves on: errors or a notice from your rules, or a next step
sent.UpdateAsync(text), (card), (text, card) the sheet closes, and its row in the channel becomes that
sent.AnswerAsync(...), sent.AnswerPrivatelyAsync(...) a line or a private answer, as for any press; the sheet closes

A form is sent once. Moved on with a new form, it can be sent again; answered any other way, it is done and a second sending is refused, so a poll is never posted twice. If your wisp does not answer within 15 seconds, the sheet stays open with everything typed and says so, and the person can send again.

  • A form is always private: only the person who asked sees it. Their other apps show a row to open it again if they close the sheet by mistake.
  • A form never has hidden fields or password fields, and Woosh’s own line at its foot tells the person never to share a password.
  • A form’s value carries up to 100 bytes of your own, which come back with the sending as its value (form.Value(...) and sent.Value; in TypeScript, value and sent.value). Woosh keeps it beside the form, and it never reaches the person.
  • A form and its answers are kept nowhere. Keep what you need.
  • A form that breaks a rule, such as a min above its max, throws where you built it: an ArgumentException in C#, a WispRuleError in TypeScript. form.Fits() (in TypeScript, fits(form)) says whether one built from your own data is within 4,000 characters and 8 KB.

A form’s sending reaches the code for its own action, and a button the code for its own, so a button and a form may share a name and each goes to its own:

The [Form] method for its action, and the [Press] method for the button’s. Without attributes: wisp.OnForm("new-poll", sent => ...).


Writing your own library? Every rule of a form, as cases to test against, is in Forms, raw.

© 2026 Woosh AS. All rights reserved.