message.retry()
Resends a failed message of the person (status: 'failed').
retry(): Promise<SendResult>
js
const result = await message.retry();retry is a method of the message (not of the world). Every message of the person (fromMe: true) has it but it works only on a message whose status is 'failed'.
Parameters
None.
Returns
A Promise that resolves to a SendResult:
| Result | What it means |
|---|---|
'sent' | Delivered this time. The status of the message is now 'sent'. |
'failed' | The message is still undelivered and stays 'failed' for another retry. |
'not-allowed' | Nothing was sent because the message has not failed, was not sent by your view or belongs to a world (or agent) that cannot be reached now. |
Usage
A "Try again" button on failed messages
js
world.subscribe((node) => {
list.replaceChildren(...node.messages.map((message) => {
const item = document.createElement('li');
item.textContent = message.text ?? '';
if (message.fromMe && message.status === 'failed') {
const again = document.createElement('button');
again.textContent = 'Try again';
again.onclick = () => message.retry();
item.append(again);
}
return item;
}));
});Try it with a fake world
failNext: true makes the next message of the person fail. The kit then resets the flag to false and the retry goes through:
js
const world = await connectToHost({ fake: { world: { name: 'Arena', failNext: true } } });
await world.send('hello'); // 'failed'
const failed = world.get().messages.find((message) => message.status === 'failed');
await failed.retry(); // 'sent'Caveats
- It resends the same message and not a copy. The message keeps its
idand its place inmessages. Only itsstatuschanges from'sending'to'sent'or'failed'. - No turn needed.
retrydoes not checkcanSendbecause the message was allowed when it was first sent. - Only what your view sent.
retryresolves'not-allowed'for a message the person sent from the UNaIVERSE view of the world or before the webapp reloaded your view. - It sends on behalf of the person. Each call sends the message again in their name. Call it only when the person asks and never in a loop.
Troubleshooting
| Code | Why | What to do |
|---|---|---|
'failed' | The webapp could not run the call (rare). | Render the newest messages. |
See also
world.send(value): how a message is sent and its results.- The recipes Retry a failed message and Test failures with a fake world.