message.answer(values)
Answers a question (a message that carries a form) with the values chosen by the person.
const result = await message.answer({ direction: 'left' });answer is a method of the message (not of the world) and only a message with a form has it.
Parameters
| Parameter | What it is |
|---|---|
values | An object keyed by the name of the fields in message.form.fields. |
The value of a field depends on its type:
| Field type | Value |
|---|---|
'select' | The value of the chosen option as a string. A field that allows more than one option (max above 1) takes an array of values. |
'text', 'textarea' | A string. |
'number', 'integer' | A number. |
'bool' | true or false. |
'date' | A date as '2026-11-05'. |
Returns
Like send, a Promise that resolves to a SendResult:
| Result | What it means |
|---|---|
'sent' | The answer was delivered. |
'failed' | Sent but not delivered. The answer stays in messages and its retry() sends it again. |
'not-allowed' | Nothing was sent. The question is already answered or no longer among the messages, no key of values names a field of the form or canSend is false. |
Usage
Find the open questions
A question has a form and stays open while isAnswered is false:
world.subscribe((node) => {
const open = node.messages.filter((message) => message.form && !message.isAnswered);
drawQuestions(open);
});Answer from a form you draw
Render one control per field and pass all the values to a single answer call:
function drawQuestion(message) {
const field = message.form.fields[0]; // e.g. { name: 'direction', type: 'select', options: [...] }
const select = document.createElement('select');
for (const option of field.options) select.add(new Option(option.label, option.value));
const button = document.createElement('button');
button.textContent = 'Answer';
button.onclick = () => message.answer({ [field.name]: select.value });
return [select, button];
}Even when the sender wrote plain strings, the options of a 'select' field always arrive in a message as { value, label } objects.
What follows
The answer becomes a new message of the person. It carries values, a readable text ("direction: left") and the id of the question in answers. In the same update of the world the question gets isAnswered: true. Render both in subscribe.
Caveats
- Once per question. After the first answer
isAnsweredistrueand every lateranswerresolves'not-allowed'. - It is a message. An answer is sent like any other message and needs
canSend. The person sees it as their own answer in the UNaIVERSE view of the world too. - It works on a message from an older node. The call identifies the message by its
id. You can therefore answer a message that yoursubscribelistener received in an earlier call. - Pass a value of the right type for at least one field of the form. Keys that name no field of the form are dropped. The receiver sees a field as not answered in two cases: (1) its value has the wrong type or breaks a limit of the field (
min,max,maxLength,format) and is dropped or (2)valuesleaves it out (leaving a field out is allowed). - The questions of the person (sent with
send({ text, form })) haveanswertoo. They are meant for the receiver to answer.
Troubleshooting
| Code | Why | What to do |
|---|---|---|
'failed' | The webapp could not run the call (rare). | Render the newest messages and let the person try again. |
See also
GuiMessageandFormSpec: the fields of a question.- The recipe Answer a question with a form and the component QuestionForm.