zephyr.bus
Send JSON-like messages between installed modules. Bus operations are not permission-gated.
4 functions
emit
zephyr.bus.emit(target, topic, payload)Asynchronously send a message to another module.
If target is not installed, the host logs a warning and drops the message.
Parameters
targetstringModule id to deliver the message to.
topicstringMessage topic the target subscribes to.
payloadanyJSON-like payload value.
Returns
Nothing.
Example
zephyr.bus.emit("tickets", "ticket.closed", { ticket_id = "abc" })on
zephyr.bus.on(topic, handler)Register a handler for messages delivered to this module on a topic.
Parameters
topicstringTopic to subscribe to.
handlerfunctionCalled as function(from, topic, payload) when a message arrives.
Returns
Nothing.
Example
zephyr.bus.on("ticket.closed", function(from, topic, payload)
zephyr.log("info", "ticket closed by " .. from)
end)request
zephyr.bus.request(target, topic, payload)Send a request to another module and await its reply.
Suspends until the target module's bus.respond handler for topic returns. Returns nil if the target has no responder for that topic. Raises if the target is not installed, or if a module requests itself.
Parameters
targetstringModule id to send the request to.
topicstringRequest topic the target responds to.
payloadanyJSON-like payload value.
Returns
The value returned by the target's responder, or nil.
Example
-- Ask the Embed Workshop to render a saved embed, then post it with role buttons.
local embed = zephyr.bus.request("workshop", "workshop.get_embed", { embed_id = id })respond
zephyr.bus.respond(topic, handler)Register a responder for bus.request calls to this module on a topic.
Parameters
topicstringRequest topic to answer.
handlerfunctionCalled as function(from, payload); its return value is sent back to the requester.
Returns
Nothing.
Example
zephyr.bus.respond("workshop.get_embed", function(from, payload)
return build_embed(load_embed(payload.embed_id))
end)