Skip to content

Chat

There are two ways to put messages into the room chat: from your extension (to narrate an action) and as a chat bot. In the snippets, ext is your createExtHelper() instance.

Announce an action in chat

v1.chat.message.send injects a message locally on one client, so "everyone" means broadcast first, then send locally on each client.

ts
// paying client broadcasts (the model omits paymentHash)
ext.subscribe('v1.payment.tokens.spend.succeeded', ({ paymentHash, isAnonymous }) => {
  ext.makeRequest('v1.ext.whisper', {
    paymentHash,
    data: { type: 'CHAT', text: 'won {#accent}1000 tk{/accent} in', isAnonymous },
  });
});

// every client renders it into its own chat feed
ext.subscribe('v1.ext.whispered', ({ type, text, isAnonymous }) => {
  if (type !== 'CHAT') return;
  ext.makeRequest('v1.chat.message.send', { message: text, isAnonymous, user: null });
});

TIP

Every message from v1.chat.message.send gets a clickable link to the extension appended automatically. Supported markup: {username}, {#accent}…{/accent}, {#fade}…{/fade}.

Send a message as a chat bot

Chat Bots have no visual slots — everything runs in the background slot.

ts
ext.subscribe('v1.ext.context.updated', ({ context }) => {
  if (context.user && !context.user.isGuest) {
    ext.makeRequest('v1.chatbot.message.send', {
      from: 'bot',
      message: 'Hello, {username}! Welcome to the room!', // platform fills {username}
    });
  }
});

Recommendations: don't reply on every incoming message

Do not reply on every v1.chat.message.received — a busy room emits hundreds of messages per second. Trigger on context changes, timers, or tips instead.