Developer

Actions

Fire-and-forget events broadcast to all listeners.

Actions (Fire-and-Forget)

Actions broadcast a payload to all listeners. The sender doesn’t wait for a response.

Capability required: hooks:provide (to fire actions) and/or hooks:consume (to listen for actions)

Firing an action

// Applet A (capability: hooks:provide)
await rp.hooks.doAction("weather:data_updated", { temp: 72, city: "Seoul" });

Listening for an action

// Applet B (capability: hooks:consume)
const unsubscribe = rp.hooks.onAction("weather:data_updated", (payload) => {
  console.log("Weather changed:", payload);
  // { temp: 72, city: "Seoul" }
});

// Later: stop listening
unsubscribe();

API Reference

rp.hooks.doAction(hookName, payload?)

Fire an action to all registered listeners.

ParameterTypeDescription
hookNamestringHook name (e.g., "weather:data_updated")
payloadunknown (optional)Data to broadcast

rp.hooks.onAction(hookName, callback)

Listen for an action. Returns an unsubscribe function.

ParameterTypeDescription
hookNamestringHook name to listen for
callback(payload: unknown) => voidCalled when the action fires
Returns() => voidCall to unsubscribe

Manifest Configuration

Declare which hooks your applet provides and consumes:

{
  "capabilities": [
    "hooks:provide",
    "hooks:consume"
  ]
}

Use hooks:provide if your applet fires actions. Use hooks:consume if your applet listens for actions. Most applets that use hooks will need both.

Naming Convention

Hook names use a namespace prefix followed by a colon:

{namespace}:{event_name}

Examples:

  • weather:data_updated - weather applet fires when data changes
  • analytics:page_view - analytics applet fires on page views
  • cms:post_published - CMS applet fires when content is published

Use your applet’s name or ID as the namespace to avoid collisions.

Example: Plugin System

// Analytics applet listens for page views from any applet
const unsubscribe = rp.hooks.onAction("cms:post_published", (payload) => {
  trackEvent("post_published", { id: payload.id, title: payload.title });
});

Backend Limitations

From the Node.js backend, doAction works normally. However, onAction is not yet available from backends - use the frontend SDK for receiving actions.