Plugin API

Everything a plugin gets in start(ctx). The same contract is published as TypeScript types in @whatszori/plugin-sdk.

ctx

Member
pluginId The plugin's folder name
React The app's React. Use it, never a bundled copy.
ui Stock components: Button, IconButton, Input, MenuItem, Toggle
registerSlot(name, Component) Put a component into a slot. Returns a function that removes it.
onEvent(name, handler) Listen to an event. Returns a function that stops listening.
actions Things the plugin can do
data Read-only access to chats and messages
settings Small strings for the plugin's settings
storage The plugin's own key-value store
log.info, log.warn, log.error The console, prefixed with the plugin id

Slots

Slot Props Where
sidebar.header none Next to the title above the chat list
sidebar.footer none Under the chat list
chat.header.actions { chat } In the open chat's header, next to search and mute
message.accessories { message } Under a message bubble
message.contextMenu { message, close } In the menu a message opens on right-click. Use ctx.ui.MenuItem, and call close() when done.
composer.actions { chatJid, insertText } Next to the emoji button
settings.sections none Settings → Plugins → Plugin settings
notification.card { notification, controls } Replaces the whole notification card (Windows). The first plugin to register wins; a crashing card falls back to the stock one.
notification.accessories { notification } Inside the stock notification card, under the text

What the props contain

interface PluginChat {
  jid: string;      // "4915112345678@s.whatsapp.net", or "...@g.us" for groups
  name: string;
  isGroup: boolean;
  muted: boolean;
}

interface PluginMessage {
  pk: string;       // WhatsZori's own id for the message
  chatJid: string;
  senderJid: string;
  senderName: string;
  fromMe: boolean;
  timestamp: number; // milliseconds
  kind: string;      // text, image, video, document, voice, sticker, poll
  text: string;      // the text, or the caption of a photo or file
  editedAt?: number;
  deleted?: { byName: string; at: number };
}

interface PluginNotification {
  id: string;
  chatJid: string;   // empty for summaries like "12 new messages"
  title: string;
  body: string;
  avatarUrl: string;
  isGroup: boolean;
  at: number;
  hasActions: boolean;
}

interface NotificationControls {
  open(): void;
  markRead(): void;
  reply(text: string): void;
  dismiss(): void;
}

Actions

actions.openChat(jid) Opens a chat
actions.insertIntoComposer(text) Adds text to the open chat's message box. The user still presses send.
actions.toast(text) Shows a short notice at the bottom of the window

Data

data.chats() Every chat in the list, as PluginChat[]
data.activeChat() The open chat's jid, or null
data.messages(jid, limit?) The latest messages of a chat, oldest first. At most 200.

Settings and storage

Both are kept per plugin in WhatsZori's database and survive restarts and updates.

settings.all() All settings as Record<string, string>
settings.set(key, value) Up to 64 KB per value
settings.delete(key)
storage.get(key) The value, or null
storage.set(key, value) Up to 1 MB per value
storage.delete(key)
storage.keys() Every key, sorted

Keys are 1 to 256 characters. Values are strings: use JSON.stringify for anything else. The difference between the two is intent. Settings are what the user chose in your settings block, and storage is whatever your plugin needs to remember.

Events

ctx.onEvent(name, handler) receives the same events the interface does. The payloads are richer than PluginMessage and PluginChat; the SDK types them all.

Event Payload
msg:batch { messages }: new messages, and messages that changed (poll votes arrive this way too)
msg:edited { chatJid, pk, text, editedAt, editCount }
msg:deleted { chatJid, pk, deleted: { byJid, byName, at }, purged }. purged is true when the content wasn't kept.
msg:removed { chatJid, pks }: deleted on this computer only
msg:reaction { chatJid, pk, reactions: [{ emoji, count, mine }] }
msg:status { chatJid, pk, status }: pending, sent, delivered, read or failed
chat:update { chat }: name, flags, unread count, last message
chat:typing { chatJid, senderJid, senderName, typing }
chat:removed, chat:cleared { jid }
presence { jid, online, lastSeen }
conn:state { state }: connected, connecting, reconnecting or offline
status:update { jid }: a status arrived, changed or was deleted

UI components

The props of ctx.ui, in short:

Component Props
Button variant: primary, secondary, ghost, danger; size: sm, md; icon; plus any <button> attribute
IconButton label (required, also the tooltip), icon (required), hint (a shortcut shown in the tooltip), size, active, tooltipPlacement: top, bottom
Input icon, trailing, plus any <input> attribute
MenuItem label, onSelect, icon, shortcut, danger, disabled
Toggle checked, onChange(checked), label, description, disabled