Plugins
A plugin is a folder with a manifest.json and a JavaScript module. WhatsZori finds it in the plugins folder, lists it in Settings → Plugins, and runs it once the user turns it on.
Plugins can:
- put components into fixed places in the interface, called slots;
- react to events: new messages, edits, deletions, typing;
- read the chat list and recent messages;
- fill in the message box, open a chat, show a short notice;
- keep settings and their own data.
Plugins can't send messages. They can put text into the message box, but sending is always the user's click. This is deliberate: WhatsZori doesn't do bulk sending or automatic replies, which are what gets WhatsApp accounts banned.
A plugin in two files
plugins/
hello/
manifest.json
index.js{
"id": "hello",
"name": "Hello",
"version": "1.0.0",
"description": "Says hello in the sidebar.",
"author": "You",
"main": "index.js"
}export default {
start(ctx) {
const h = ctx.React.createElement;
ctx.registerSlot('sidebar.footer', () => h('p', { style: { padding: '8px 16px' } }, 'Hello from ' + ctx.pluginId));
},
};Put the folder into Settings → Plugins → Open plugins folder, click Look again, and turn it on.
For anything bigger than this, use the plugin SDK. It gives you TypeScript types, JSX, React hooks and a command that rebuilds your plugin into the app's folder on every save.
The manifest
| Field | |
|---|---|
id |
Required. Must be the folder name: letters, digits, ., -, _, at most 128 characters. |
name |
Required. Shown in the settings. |
version |
Required. A version like 1.0.0. |
description, author |
Optional, shown in the settings. |
main |
The module to load, relative to the folder. A .js or .mjs file; index.js when left out. |
A plugin with a broken manifest still shows in the list, with the reason, and can't be turned on.
The module
The module is loaded with import() from /wz-plugins/<id>/<main>, so it can import its own other files with relative paths. Its default export has a start(ctx) function. export default function start(ctx) and a named export function start work too.
export default {
async start(ctx) {
const saved = await ctx.storage.get('count');
// ...
return () => {
// optional: anything else to clean up
};
},
};startmay be async.- Everything registered through
ctx(slots, event handlers) is removed automatically when the plugin is turned off. - If
startreturns a function, it's called on top of that.
Lifecycle
| When | What happens |
|---|---|
| The app starts | Every turned-on plugin's start runs |
| The user turns a plugin on | Its start runs, with the code freshly loaded from disk |
| The user turns it off | Its slots and handlers go away, then its cleanup function runs |
start throws |
The error shows next to the plugin in the settings; nothing it registered stays |
| A slot component throws | That component is hidden and logged; the rest of the app keeps working |
| Safe mode | No plugin loads at all |
Turning a plugin off and on again reloads its code, so you don't need to restart the app while developing.
React
Slots take React components. Use the app's own React, which you get as ctx.React. A plugin that bundles its own copy of React breaks hooks inside the app's tree. The SDK handles this for you: you write ordinary import { useState } from 'react' and JSX, and it ends up using ctx.React.
For controls that match the user's theme, use ctx.ui: Button, IconButton, Input, MenuItem and Toggle.
Trust
A plugin runs in the same page as WhatsZori's interface, with the same rights. It can read what the interface shows and make network requests. That's why plugins are off until the user turns them on, why safe mode skips them all, and why the API has no way to send messages. Still, tell your users what your plugin does, and don't collect their data.
Next
The plugin API lists everything on ctx, every slot and every event.