Skip to main content

Messenger

Headless messenger and visual-novel transcript engine for React Text Game.

A chat's transcript is an append-only log that lives in an engine entity, so it survives saves, loads, and remounts, and knows exactly what the player has and has not seen. The same primitive powers a messenger simulator (chat list, unread badges, scheduled delivery) and a Ren'Py-style visual novel (backlog, skip-already-read).

This release is headless: state, delivery, and selectors, with no components.

Example

import {
defineChat, defineContact, defineMessenger, defineScript, m,
} from '@react-text-game/messenger';
import { MINUTE } from '@react-text-game/core/clock';

const anna = defineContact('anna', { name: m.t('contacts.anna') });
const chat = defineChat('anna', { peer: anna });

const opener = defineScript('anna/opener', (m) => [
m.from(anna).text(m.t('anna.opener')),
m.typing(anna, 1200),
m.from(anna).media([m.image('/park.webp')], { caption: m.t('anna.park') }),
m.wait(30 * MINUTE),
m.choice('anna/opener/reply', [
{ content: m.t('reply.yes') },
{ content: m.t('reply.no') },
]),
]);

export const messenger = defineMessenger({ chats: [chat] });

// From an action handler, never while rendering:
chat.play(opener);
chat.advance();

Classes

Type Aliases

Variables

Functions