A platform for community discussion. Free, open, simple.
name: discourse-workflow-nodes description: Use when creating, changing, or reviewing Discourse Workflows nodes (triggers, actions, conditions) in plugins/discourse-workflows or plugins/*/lib/discourse_workflows, including their output schemas and specs
Discourse Workflow Nodes
Entities in output
Shape entities only with DiscourseWorkflows::EntitySerializers (lib/discourse_workflows/entity_serializers.rb), available in NodeType instance and class methods:
| Entity | Builder | Schema |
|---|---|---|
| User | serialize_user(user, guardian:) (nil for nil user) |
Schema::USER_SCHEMA / USER_PROPERTIES / Schema.nullable_user(description) |
| Topic (triggers) | serialize_topic_list_item(topic, scope:) |
Schema::TOPIC_LIST_ITEM_SCHEMA / TOPIC_PROPERTIES |
| Topic (actions) | serialize_topic(topic, guardian:, custom_field_names:) |
TOPIC_LIST_ITEM_SCHEMA |
| Post | serialize_post(post, guardian:, include_raw:, include_cooked:) (nil for nil post) |
Schema::POST_SCHEMA / POST_PROPERTIES |
| Reviewable | serialize_reviewable(reviewable) |
Schema::REVIEWABLE_EVENT_SCHEMA |
| Assignee (user or group) | serialize_assignee(assignee, guardian:) |
Schema::ASSIGNEE_PROPERTIES |
| Group (basic) | serialize_basic_group(group) |
BASIC_GROUP_PROPERTIES |
| Any serializer | serialize_record(record, SerializerClass, scope:) |
- Name every helper that shapes an entity for output
serialize_<entity>(serialize_badge,serialize_group,serialize_timer,serialize_assignee,serialize_channel,serialize_event...), never<entity>_data;node_entity_builders_specfails ondef <entity>_data. - Don't wrap a shared builder in a node-private helper; call it directly.
serialize_topic_list_item(DiscourseWorkflows::TopicListItemSerializer) carries plugin-added list fields (assignassigned_to_*, solvedhas_accepted_answer, votingcan_vote/vote_count...);serialize_topic(DiscourseWorkflows::TopicSerializer) adds posters, participants and custom fields. Both emit everyTOPIC_PROPERTIESkey.- Outside a
NodeType, call them on the module:DiscourseWorkflows::EntitySerializers.serialize_user(...). - Never use
BasicUserSerializerorTopicListItemSerializerin node files;node_entity_builders_specfails if you do. - Groups:
BasicGroupSerializer(BASIC_GROUP_PROPERTIES) orWebHookGroupSerializer(GROUP_SCHEMA).
user vs actor
useris the subject: the post/topic author, or the affected account.actoris whoever performed the action, built withserialize_userand declared withSchema::ACTOR_SCHEMA(nullable).- Emit both, even when they are the same person (liker, voter, participant).
- Output never uses
acting_user; events never useactor:.
Events pass the acting user
Fire events with the actor as a trailing acting_user: kwarg:
DiscourseEvent.trigger(:topic_status_updated, topic, status, enabled, acting_user: user)
Trigger nodes receive it as a trailing hash: def initialize(topic, status, enabled, payload = {}) and read payload[:acting_user]. Specs that assert exact event params must include { acting_user: ... }.
Breaking output changes
Renaming or removing an output key, or changing its meaning, breaks saved workflows. Ship a new version instead; additive keys can go in the existing version.
- Freeze V1 and mark it, after
description(...):deprecated(superseded_by: "2.0", changes: { "editor" => "actor" }). - The shared
node_descriptions.<identifier>locale describes the latest version. If it no longer fits V1, adddescription_key: "discourse_workflows.node_descriptions.<identifier>_v1"todeprecated(...)with V1's text; V2 does not inherit it. class V2 < V1inv2.rb, callingdescription(superclass.description.merge(version: "2.0", output_contracts: [{ schema: V2_OUTPUT_SCHEMA }])), then overrideoutput/executeor a privateserialize_*helper.- Core nodes self-register; plugin nodes need
register_discourse_workflows_node(...::V2)next to V1. - Services resolve the saved version with
NodeData.node_type(node), never a hard-codedV1. - Deprecated versions keep running for saved workflows, are hidden from the palette and AI catalog, and show an editor notice with an Upgrade action. Remove them after a deprecation window.
- Spec both:
match_node_output_schema(Foo::V1)pins the old keys,match_node_output_schema(Foo::V2)the new ones.node_deprecation_speccheckssuperseded_by. - Bump the node in
config/templates/*.json, migrate its parameters, and check downstream expressions;workflow_templates_specenforces the version and parameter names.
Output conventions
- URLs are absolute (
Discourse.base_url + ...,full_url). Keep existing relative keys such aspost_url. - Actions that may no-op output
changed(boolean), computed by comparing state before and after (see badge, group, post_like). - Actions that mutate a topic also return
topic. - Cap user lists with a named constant (e.g.
PostEventScoping::MAX_GOING_USERNAMES).
Secrets
- Never put credential values in output. Password credential fields serialize as
Credential::REDACTED_VALUE. WebhookRequestmasksFILTERED_HEADERS(authorization,cookie,proxy-authorization) withFILTERED_VALUE;AuthenticateNodemasks the matchedheader_authheader.- http_request logs headers through
redact_headers.
Output contracts
Every node declares its output with output_contracts in description, or derives it from config by overriding self.output_schemas (see summarize, data_table, trigger:form, action:form). The editor fetches resolved schemas from the server (POST /output-schemas), so there is no JS counterpart.
node_output_contracts_spec has a user_defined_output opt-out list. A node belongs there only if the user writes its output shape (code, sql, set_fields, workflow_call, manual). If the shape can be derived from config, override self.output_schemas instead.
- Use
"type": [..., "null"]for keys that are always emitted but may be nil. - Use
"x-optional": truefor keys that are only emitted on some paths, such as DM-onlyusernames, ortagswhen the guardian can't see them. Optional objects may be{}. schema_serializer_sync_specfails when a declared serializer key is never emitted.
Specs
Every node spec asserts the real output against the declared contract:
expect(output).to match_node_output_schema(DiscourseWorkflows::Nodes::Foo::V1, configuration: config)
The matcher is strict: every declared property is required unless x-optional, and types must match. Run plugin specs with LOAD_PLUGINS=1 bin/rspec.