Skip to content

A platform for community discussion. Free, open, simple.

FEATURE: Expose the topic URL in workflow topic payloads

Régis Hanol05ed381c066a
diff --git a/plugins/discourse-workflows/app/serializers/discourse_workflows/topic_list_item_serializer.rb b/plugins/discourse-workflows/app/serializers/discourse_workflows/topic_list_item_serializer.rb
index c0e5e8a433c..b486d303bab 100644
--- a/plugins/discourse-workflows/app/serializers/discourse_workflows/topic_list_item_serializer.rb
+++ b/plugins/discourse-workflows/app/serializers/discourse_workflows/topic_list_item_serializer.rb
@@ -2,6 +2,6 @@
module DiscourseWorkflows
class TopicListItemSerializer < ::TopicListItemSerializer
- attributes :user_id
+ attributes :user_id, :url
end
end
diff --git a/plugins/discourse-workflows/app/serializers/discourse_workflows/topic_serializer.rb b/plugins/discourse-workflows/app/serializers/discourse_workflows/topic_serializer.rb
index e2d037fb900..820726f1766 100644
--- a/plugins/discourse-workflows/app/serializers/discourse_workflows/topic_serializer.rb
+++ b/plugins/discourse-workflows/app/serializers/discourse_workflows/topic_serializer.rb
@@ -8,6 +8,7 @@ module DiscourseWorkflows
attributes :id,
:title,
:slug,
+ :url,
:posts_count,
:reply_count,
:highest_post_number,
diff --git a/plugins/discourse-workflows/lib/discourse_workflows/ai_workflow_author.rb b/plugins/discourse-workflows/lib/discourse_workflows/ai_workflow_author.rb
index 2348b579281..dd5ef8ea14b 100644
--- a/plugins/discourse-workflows/lib/discourse_workflows/ai_workflow_author.rb
+++ b/plugins/discourse-workflows/lib/discourse_workflows/ai_workflow_author.rb
@@ -97,9 +97,9 @@ module DiscourseWorkflows
- For tag group membership changes, resolve the named tag group with workflow_resolve_entity(kind: "tag_group", ...), then use action:tag_group with operation "add" or "remove", tag_group_id set to the resolved tag group id, and tag_names set to the tag names to change.
- For personal messages, private messages, DMs, direct messages, or PM-style notifications, use action:send_personal_message. Resolve named user recipients with workflow_resolve_entity(kind: "user") and set recipient_usernames to an array containing the resolved username. Resolve named group recipients with workflow_resolve_entity(kind: "group") and set recipient_group_names to an array containing the resolved group name, not the group id. Use leading-= template strings for title/raw when including dynamic post or topic links.
- When using an output_contracts schema, use the exact documented path (for example $json.user.trust_level, $json.user.username, $json.post.raw, or $json.post.post_url). Do not generate fallback chains for undocumented aliases such as $json.user.trustLevel or $json.trust_level.
- - Dynamic parameter values must start with =. Use ={{ $json.topic.id }} for a whole-field expression, and use template strings such as =Archived topic: {{ $json.topic.title }} (/t/{{ $json.topic.slug }}/{{ $json.topic.id }}) when mixing text and expressions.
+ - Dynamic parameter values must start with =. Use ={{ $json.topic.id }} for a whole-field expression, and use template strings such as =Archived topic: {{ $json.topic.title }} ({{ $json.topic.url }}) when mixing text and expressions.
- Do not write bare {{ $json.field }} templates without the leading =; without = they are treated as literal text.
- - For topic links from topic payloads, prefer /t/{{ $json.topic.slug }}/{{ $json.topic.id }} in a leading-= template string. Only use $json.post.post_url when the current node input_fields includes $json.post.post_url.
+ - For topic links use $json.topic.url, which is already absolute. Only use $json.post.post_url (relative) when the current node input_fields includes it.
- Discourse trust levels are automatic groups named trust_level_0 through trust_level_4. Membership is cumulative: the trust_level_N group contains every user whose trust level is N or higher. When a workflow needs a trust-level check but the current input_fields has no trust_level field (for example after trigger:topic_closed or action:topic get, which expose post.username but not the author trust level), resolve the relevant trust_level_N group with workflow_resolve_entity and use action:group with operation "check_membership", the resolved group_id, and the available username field (such as $json.post.username) instead of asking for clarification or adding a Code node. For "TL1 or lower", check membership in trust_level_2 and branch on $json.group_membership.in_group being false; for "TL2 or higher", branch on it being true.
- Do not assume $json.post.trust_level exists. The post payload never includes trust level; trust level is only available as $json.user.trust_level on triggers that expose a user object (such as trigger:post_created). For topic-only payloads, use the trust_level_N group membership approach above.
- Do not ask whether the first post or topic author trust level is available until you have checked the current node schemas with workflow_validate_patch.
diff --git a/plugins/discourse-workflows/lib/discourse_workflows/schema.rb b/plugins/discourse-workflows/lib/discourse_workflows/schema.rb
index d35efd3d80b..bc64d778761 100644
--- a/plugins/discourse-workflows/lib/discourse_workflows/schema.rb
+++ b/plugins/discourse-workflows/lib/discourse_workflows/schema.rb
@@ -45,6 +45,7 @@ module DiscourseWorkflows
"title": { "type": "string" },
"fancy_title": { "type": "string" },
"slug": { "type": "string" },
+ "url": { "type": "string", "description": "Absolute URL of the topic" },
"archetype": { "type": "string", "description": "regular for topics, private_message for PMs" },
"posts_count": { "type": "integer" },
"category_id": { "type": ["integer", "null"] },
@@ -86,7 +87,7 @@ module DiscourseWorkflows
"topic_id": { "type": "integer" },
"topic_slug": { "type": "string" },
"topic_title": { "type": "string" },
- "post_url": { "type": "string" },
+ "post_url": { "type": "string", "description": "Relative URL of the post" },
"category_id": { "type": ["integer", "null"] },
"category_name": { "type": ["string", "null"] },
"user_id": { "type": "integer" },
diff --git a/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/topic_created_spec.rb b/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/topic_created_spec.rb
index b6e1e9ac8ed..978cbf41712 100644
--- a/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/topic_created_spec.rb
+++ b/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/topic_created_spec.rb
@@ -48,6 +48,7 @@ RSpec.describe DiscourseWorkflows::Nodes::TopicCreated::V1 do
expect(output[:post][:username]).to eq(user.username)
expect(output[:topic][:id]).to eq(topic.id)
expect(output[:topic][:title]).to eq(topic.title)
+ expect(output[:topic][:url]).to eq(topic.url)
expect(output[:topic][:tags].map { |topic_tag| topic_tag[:name] }).to eq(["test-tag"])
expect(output[:topic][:category_id]).to eq(topic.category_id)
expect(output[:topic][:posters].map { |poster| poster[:user_id] }).to include(topic.user_id)
diff --git a/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/topic_spec.rb b/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/topic_spec.rb
index 8d939b1e3b2..73cd51a27c8 100644
--- a/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/topic_spec.rb
+++ b/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/topic_spec.rb
@@ -206,6 +206,7 @@ RSpec.describe DiscourseWorkflows::Nodes::Topic::V1 do
expect(result["topic"]["id"]).to eq(topic.id)
expect(result["topic"]["title"]).to eq(topic.title)
+ expect(result["topic"]["url"]).to eq(topic.url)
expect(result["topic"]["category_id"]).to eq(category.id)
expect(result["topic"]["tags"]).to eq([])
expect(result["post"]).to include(