Skip to content

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

FEATURE: Add reaction actions and triggers to workflows

Régis Hanol95e38c7367fe
diff --git a/plugins/discourse-reactions/app/services/discourse_reactions/reaction_manager.rb b/plugins/discourse-reactions/app/services/discourse_reactions/reaction_manager.rb
index ad7a88c54df..52a8c1d7792 100644
--- a/plugins/discourse-reactions/app/services/discourse_reactions/reaction_manager.rb
+++ b/plugins/discourse-reactions/app/services/discourse_reactions/reaction_manager.rb
@@ -4,6 +4,10 @@ module DiscourseReactions
class ReactionManager
attr_reader :reaction_value, :previous_reaction_value
+ def self.reaction_value_for(user:, post:)
+ new(reaction_value: nil, user:, post:).previous_reaction_value
+ end
+
def initialize(reaction_value:, user:, post:)
@reaction_value = reaction_value
@user = user
@@ -29,15 +33,19 @@ module DiscourseReactions
raise Discourse::InvalidAccess
end
- ActiveRecord::Base.transaction do
- @reaction = reaction_scope&.first_or_create
- @reaction_user = reaction_user_scope
- if @reaction_value == DiscourseReactions::Reaction.main_reaction_id
- toggle_like
- else
- toggle_reaction
+ ActiveRecord::Base
+ .transaction do
+ @reaction = reaction_scope&.first_or_create
+ @reaction_user = reaction_user_scope
+ if @reaction_value == DiscourseReactions::Reaction.main_reaction_id
+ toggle_like
+ else
+ toggle_reaction
+ end
+ end
+ .tap do
+ DiscourseEvent.trigger(:post_reaction_toggled, @post, @user, @previous_reaction_value)
end
- end
end
private
diff --git a/plugins/discourse-reactions/config/locales/client.en.yml b/plugins/discourse-reactions/config/locales/client.en.yml
index cfd6e80d440..e3e1327163a 100644
--- a/plugins/discourse-reactions/config/locales/client.en.yml
+++ b/plugins/discourse-reactions/config/locales/client.en.yml
@@ -27,6 +27,30 @@ en:
remove: "Remove this like"
cant_remove: "You can no longer remove your like"
unauthenticated: "Please sign up or log in to like this post"
+ discourse_workflows:
+ node_unavailable:
+ requires_reactions: "Requires the Reactions plugin to be enabled"
+ nodes:
+ "action:post_reaction": "React to post"
+ "trigger:post_reaction_changed": "Post reaction changed"
+ node_descriptions:
+ "action:post_reaction": "Add or remove a reaction on a post"
+ "trigger:post_reaction_changed": "Fires when a reaction on a post is added, replaced or removed. The user is whoever reacted, not the author."
+ post_reaction:
+ operations:
+ add: "Add reaction"
+ remove: "Remove reaction"
+ reaction: "Reaction"
+ if_exists: "If the user already reacted"
+ if_exists_description: "Users can only have one reaction per post"
+ if_exists_keep: "Keep their reaction"
+ if_exists_replace: "Replace their reaction"
+ post_reaction_changed:
+ changes_added: "Added"
+ changes_replaced: "Replaced"
+ changes_removed: "Removed"
+ reaction: "Reaction"
+ reaction_description: "Only trigger when this reaction is added, replaced or removed. Leave empty to match any reaction."
notifications:
reaction_1_user_multiple_posts:
one: "reacted to %{count} of your post"
diff --git a/plugins/discourse-reactions/config/locales/server.en.yml b/plugins/discourse-reactions/config/locales/server.en.yml
index f69eca4f4eb..0a66d16f946 100644
--- a/plugins/discourse-reactions/config/locales/server.en.yml
+++ b/plugins/discourse-reactions/config/locales/server.en.yml
@@ -2,6 +2,9 @@ en:
discourse_reactions:
errors:
reaction_unavailable: "Reaction is not available"
+ discourse_workflows:
+ post_reaction:
+ cannot_react: "%{username} can't react to this post."
site_settings:
discourse_reactions_like_icon: "Defines the icon used for the main reaction button. This should be a <a href='https://fontawesome.com/v6/search?o=r&m=free' target='_blank'>Font Awesome</a> icon name, not an emoji name."
discourse_reactions_reaction_for_like: "Defines the reaction associated to the Like action. Historical Like records will not be changed if this setting changes, it is <strong>strongly recommended</strong> that this setting is never changed."
diff --git a/plugins/discourse-reactions/lib/discourse_reactions/mcp_tools.rb b/plugins/discourse-reactions/lib/discourse_reactions/mcp_tools.rb
index f4add8ed36b..b0551ce88e1 100644
--- a/plugins/discourse-reactions/lib/discourse_reactions/mcp_tools.rb
+++ b/plugins/discourse-reactions/lib/discourse_reactions/mcp_tools.rb
@@ -11,20 +11,26 @@ module DiscourseReactions
)
def self.call(arguments:, request_context:)
- post = Post.find_by(id: arguments.fetch("post_id"))
- if post.blank? || !request_context.guardian.can_see?(post)
- raise DiscourseMcp::ToolError, "Post not found"
- end
reaction = arguments.fetch("reaction")
- if !DiscourseReactions::Reaction.valid?(reaction)
- raise DiscourseMcp::ToolError, I18n.t("discourse_reactions.errors.reaction_unavailable")
+
+ DiscourseReactions::PostReaction::Toggle.call(
+ params: {
+ post_id: arguments.fetch("post_id"),
+ reaction:,
+ },
+ guardian: request_context.guardian,
+ ) do |result|
+ on_success do |post:|
+ DiscourseMcp::ToolHelpers.text_and_structured(post_id: post.id, reaction:)
+ end
+ on_model_not_found(:post) { raise DiscourseMcp::ToolError, "Post not found" }
+ on_failed_policy(:can_see_post) { raise DiscourseMcp::ToolError, "Post not found" }
+ on_failed_policy(:reaction_is_valid) do
+ raise DiscourseMcp::ToolError, I18n.t("discourse_reactions.errors.reaction_unavailable")
+ end
+ on_exceptions(Discourse::InvalidAccess) { |exception| raise exception }
+ on_failure { raise DiscourseMcp::ToolError, result.inspect_steps }
end
- DiscourseReactions::ReactionManager.new(
- reaction_value: reaction,
- user: request_context.user,
- post: post,
- ).toggle!
- DiscourseMcp::ToolHelpers.text_and_structured(post_id: post.id, reaction: reaction)
end
end
end
diff --git a/plugins/discourse-reactions/lib/discourse_workflows/nodes/post_reaction/v1.rb b/plugins/discourse-reactions/lib/discourse_workflows/nodes/post_reaction/v1.rb
new file mode 100644
index 00000000000..70d74968572
--- /dev/null
+++ b/plugins/discourse-reactions/lib/discourse_workflows/nodes/post_reaction/v1.rb
@@ -0,0 +1,145 @@
+# frozen_string_literal: true
+
+if defined?(DiscourseWorkflows)
+ module DiscourseWorkflows
+ module Nodes
+ module PostReaction
+ class V1 < DiscourseWorkflows::NodeType
+ OPERATIONS = %w[add remove].freeze
+ IF_EXISTS_OPTIONS = %w[keep replace].freeze
+ OUTPUT_SCHEMA = {
+ "$schema" => Schema::DRAFT_URI,
+ "type" => "object",
+ "properties" => {
+ "post_id" => {
+ "type" => "integer",
+ },
+ "username" => {
+ "type" => "string",
+ },
+ "reaction" => {
+ "type" => %w[string null],
+ },
+ "previous_reaction" => {
+ "type" => %w[string null],
+ },
+ "changed" => {
+ "type" => "boolean",
+ },
+ },
+ }.freeze
+
+ description(
+ name: "action:post_reaction",
+ version: "1.0",
+ defaults: {
+ icon: "far-face-smile",
+ color: "yellow",
+ },
+ group: "discourse_actions",
+ available: -> { SiteSetting.discourse_reactions_enabled },
+ unavailable_reason_key: "discourse_workflows.node_unavailable.requires_reactions",
+ capabilities: {
+ run_scope: "per_item",
+ },
+ output_contracts: [{ schema: OUTPUT_SCHEMA }],
+ properties: {
+ operation: {
+ type: :options,
+ required: true,
+ options: OPERATIONS,
+ default: "add",
+ },
+ post_id: {
+ type: :string,
+ required: true,
+ },
+ reaction: {
+ type: :emoji,
+ required: true,
+ },
+ if_exists: {
+ type: :options,
+ required: true,
+ options: IF_EXISTS_OPTIONS,
+ default: "keep",
+ display_options: {
+ show: {
+ operation: ["add"],
+ },
+ },
+ },
+ **actor_property(allow_anonymous: false),
+ },
+ )
+
+ def execute(exec_ctx)
+ items =
+ exec_ctx.input_items.map.with_index do |_item, item_index|
+ wrap(process(exec_ctx, item_index))
+ end
+
+ [items]
+ end
+
+ private
+
+ def process(exec_ctx, item_index)
+ post = ::Post.find(exec_ctx.get_node_parameter("post_id", item_index))
+ actor = exec_ctx.actor_from_parameter("actor_username", item_index)
+ reaction = exec_ctx.get_node_parameter("reaction", item_index).to_s.delete(":")
+ previous_reaction =
+ ::DiscourseReactions::ReactionManager.reaction_value_for(user: actor, post:)
+
+ add = exec_ctx.get_node_parameter("operation", item_index, default: "add") == "add"
+
+ if add
+ replace = exec_ctx.get_node_parameter("if_exists", item_index) == "replace"
+ changed = previous_reaction != reaction && (previous_reaction.nil? || replace)
+ else
+ changed = previous_reaction == reaction
+ end
+
+ toggle_reaction(post, actor, reaction, item_index) if changed
+
+ {
+ post_id: post.id,
+ username: actor.username,
+ reaction: changed ? (reaction if add) : previous_reaction,
+ previous_reaction:,
+ changed:,
+ }
+ end
+
+ def toggle_reaction(post, actor, reaction, item_index)
+ ::DiscourseReactions::PostReaction::Toggle.call(
+ params: {
+ post_id: post.id,
+ reaction:,
+ },
+ guardian: actor.guardian,
+ ) do
+ on_success {}
+ on_failed_policy(:reaction_is_valid) do
+ raise_node_error!(
+ I18n.t("discourse_reactions.errors.reaction_unavailable"),
+ description: reaction,
+ item_index:,
+ )
+ end
+ on_failure do
+ raise_node_error!(
+ I18n.t(
+ "discourse_reactions.discourse_workflows.post_reaction.cannot_react",
+ username: actor.username,
+ ),
+ item_index:,
+ )
+ end
+ end
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/plugins/discourse-reactions/lib/discourse_workflows/nodes/post_reaction_changed/v1.rb b/plugins/discourse-reactions/lib/discourse_workflows/nodes/post_reaction_changed/v1.rb
new file mode 100644
index 00000000000..065f0d9d37c
--- /dev/null
+++ b/plugins/discourse-reactions/lib/discourse_workflows/nodes/post_reaction_changed/v1.rb
@@ -0,0 +1,115 @@
+# frozen_string_literal: true
+
+if defined?(DiscourseWorkflows)
+ module DiscourseWorkflows
+ module Nodes
+ module PostReactionChanged
+ class V1 < DiscourseWorkflows::NodeType
+ CHANGES = %w[added replaced removed].freeze
+
+ OUTPUT_SCHEMA =
+ Schema.merge(
+ Schema::POST_SCHEMA,
+ Schema::TOPIC_LIST_ITEM_SCHEMA,
+ Schema::USER_SCHEMA,
+ Schema.document(
+ "change" => {
+ "type" => "string",
+ "enum" => CHANGES,
+ },
+ "reaction" => {
+ "type" => %w[string null],
+ },
+ "previous_reaction" => {
+ "type" => %w[string null],
+ },
+ ),
+ ).freeze
+
+ description(
+ name: "trigger:post_reaction_changed",
+ version: "1.0",
+ defaults: {
+ icon: "far-face-smile",
+ color: "yellow",
+ },
+ group: "discourse_triggers",
+ event: :post_reaction_toggled,
+ available: -> { SiteSetting.discourse_reactions_enabled },
+ unavailable_reason_key: "discourse_workflows.node_unavailable.requires_reactions",
+ output_contracts: [{ schema: OUTPUT_SCHEMA }],
+ properties: {
+ changes: {
+ type: :multi_options,
+ required: false,
+ default: [],
+ options: CHANGES,
+ },
+ reaction: {
+ type: :emoji,
+ required: false,
+ no_data_expression: true,
+ },
+ **CATEGORY_FILTER_PROPERTIES,
+ **TAG_FILTER_PROPERTIES,
+ },
+ )
+
+ def initialize(post, user, previous_reaction)
+ super(parameters: {})
+ @post = post
+ @user = user
+ @previous_reaction = previous_reaction
+ end
+
+ def valid?
+ @post.topic.present? && reaction != @previous_reaction
+ end
+
+ def user_id
+ @user.id
+ end
+
+ def output
+ {
+ change:,
+ reaction:,
+ previous_reaction: @previous_reaction,
+ post: serialize_post(@post),
+ topic: topic_data(@post.topic),
+ user: serialize_user(@user),
+ }
+ end
+
+ def matches?(trigger_ctx)
+ filter = trigger_ctx.get_node_parameter("reaction").to_s.delete(":").presence
+
+ matches_changes?(trigger_ctx, change) &&
+ (filter.nil? || [reaction, @previous_reaction].include?(filter)) &&
+ matches_topic_filters?(@post.topic, trigger_ctx)
+ end
+
+ private
+
+ # Looked up lazily so toggles nobody listens to don't pay for the query.
+ def reaction
+ return @reaction if defined?(@reaction)
+
+ @reaction =
+ ::DiscourseReactions::ReactionManager.reaction_value_for(user: @user, post: @post)
+ end
+
+ def change
+ if @previous_reaction.nil?
+ "added"
+ elsif reaction.nil?
+ "removed"
+ else
+ "replaced"
+ end
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/plugins/discourse-reactions/plugin.rb b/plugins/discourse-reactions/plugin.rb
index 2b4452deb0e..71f91aecea5 100644
--- a/plugins/discourse-reactions/plugin.rb
+++ b/plugins/discourse-reactions/plugin.rb
@@ -28,6 +28,15 @@ require_relative "lib/discourse_reactions/engine"
after_initialize do
SeedFu.fixture_paths << Rails.root.join("plugins/discourse-reactions/db/fixtures").to_s
+ if respond_to?(:register_discourse_workflows_node)
+ register_discourse_workflows_node do
+ [
+ DiscourseWorkflows::Nodes::PostReaction::V1,
+ DiscourseWorkflows::Nodes::PostReactionChanged::V1,
+ ]
+ end
+ end
+
%w[
app/controllers/discourse_reactions/custom_reactions_controller.rb
app/models/discourse_reactions/reaction_user.rb
diff --git a/plugins/discourse-reactions/spec/lib/discourse_reactions/mcp_tools_spec.rb b/plugins/discourse-reactions/spec/lib/discourse_reactions/mcp_tools_spec.rb
index 2192a2d4b20..15e78e64c6e 100644
--- a/plugins/discourse-reactions/spec/lib/discourse_reactions/mcp_tools_spec.rb
+++ b/plugins/discourse-reactions/spec/lib/discourse_reactions/mcp_tools_spec.rb
@@ -4,25 +4,34 @@ describe DiscourseReactions::McpTools::SetReaction do
fab!(:user)
fab!(:post)
+ let(:request_context) { instance_double(DiscourseMcp::RequestContext, guardian: user.guardian) }
+
before do
SiteSetting.discourse_reactions_enabled = true
SiteSetting.discourse_reactions_enabled_reactions = "laughing"
end
- it "rejects a reaction that is not enabled" do
- request_context = instance_double(DiscourseMcp::RequestContext, user:, guardian: user.guardian)
+ def set_reaction(reaction)
+ described_class.call(
+ arguments: {
+ "post_id" => post.id,
+ "reaction" => reaction,
+ },
+ request_context:,
+ )
+ end
- expect do
- described_class.call(
- arguments: {
- "post_id" => post.id,
- "reaction" => "disabled-reaction",
- },
- request_context:,
- )
- end.to raise_error(DiscourseMcp::ToolError)
- expect(DiscourseReactions::Reaction.find_by(post:, reaction_value: "disabled-reaction")).to eq(
- nil,
+ it "reacts to the post" do
+ expect(set_reaction("laughing")).to include(
+ structuredContent: {
+ post_id: post.id,
+ reaction: "laughing",
+ },
)
+ expect(DiscourseReactions::ReactionManager.reaction_value_for(user:, post:)).to eq("laughing")
+ end
+
+ it "rejects a reaction that is not enabled" do
+ expect { set_reaction("disabled-reaction") }.to raise_error(DiscourseMcp::ToolError)
end
end
diff --git a/plugins/discourse-reactions/spec/lib/discourse_workflows/nodes/post_reaction_changed_spec.rb b/plugins/discourse-reactions/spec/lib/discourse_workflows/nodes/post_reaction_changed_spec.rb
new file mode 100644
index 00000000000..46bb5002155
--- /dev/null
+++ b/plugins/discourse-reactions/spec/lib/discourse_workflows/nodes/post_reaction_changed_spec.rb
@@ -0,0 +1,66 @@
+# frozen_string_literal: true
+
+RSpec.describe DiscourseWorkflows::Nodes::PostReactionChanged::V1, discourse_workflows: true do
+ fab!(:admin)
+ fab!(:category)
+ fab!(:other_category, :category)
+ fab!(:topic) { Fabricate(:topic, category:) }
+ fab!(:post) { Fabricate(:post, topic:) }
+ fab!(:reactor, :user)
+ fab!(:tag)
+
+ before do
+ SiteSetting.discourse_reactions_enabled = true
+ SiteSetting.discourse_reactions_enabled_reactions = "laughing|hugs"
+ end
+
+ def react(reaction)
+ DiscourseReactions::ReactionManager.new(reaction_value: reaction, user: reactor, post:).toggle!
+ end
+
+ describe "#matches?" do
+ it "filters changes, reactions, categories, and tags" do
+ SiteSetting.tagging_enabled = true
+ topic.tags << tag
+ react("hugs")
+ trigger = described_class.new(post, reactor, "laughing")
+
+ expect(trigger.matches?(trigger_context({}))).to eq(true)
+ expect(trigger.matches?(trigger_context(changes: ["removed"]))).to eq(false)
+ expect(trigger.matches?(trigger_context(reaction: "clap"))).to eq(false)
+ expect(trigger.matches?(trigger_context(category_ids: [other_category.id]))).to eq(false)
+ expect(trigger.matches?(trigger_context(tag_names: ["missing"]))).to eq(false)
+ expect(
+ trigger.matches?(
+ trigger_context(
+ changes: ["replaced"],
+ reaction: ":laughing:",
+ category_ids: [category.id],
+ tag_names: [tag.name],
+ ),
+ ),
+ ).to eq(true)
+ end
+ end
+
+ describe "event dispatch" do
+ it "runs workflows as the reacting user when reactions are added, replaced and removed" do
+ graph = build_workflow_graph { |builder| builder.node "reaction", described_class.identifier }
+ Fabricate(:discourse_workflows_workflow, created_by: admin, published: true, **graph)
+
+ %w[laughing hugs hugs].each { |reaction| react(reaction) }
+
+ jobs = Jobs::DiscourseWorkflows::ExecuteWorkflow.jobs.map { |job| job["args"].first }
+ data = jobs.pluck("trigger_data")
+ expect(data.map { |payload| payload.slice("change", "reaction", "previous_reaction") }).to eq(
+ [
+ { "change" => "added", "reaction" => "laughing", "previous_reaction" => nil },
+ { "change" => "replaced", "reaction" => "hugs", "previous_reaction" => "laughing" },
+ { "change" => "removed", "reaction" => nil, "previous_reaction" => "hugs" },
+ ],
+ )
+ expect(jobs.pluck("user_id").uniq).to eq([reactor.id])
+ expect(data).to all(match_node_output_schema(described_class))
+ end
+ end
+end
diff --git a/plugins/discourse-reactions/spec/lib/discourse_workflows/nodes/post_reaction_spec.rb b/plugins/discourse-reactions/spec/lib/discourse_workflows/nodes/post_reaction_spec.rb
new file mode 100644
index 00000000000..30f1bc69a4a
--- /dev/null
+++ b/plugins/discourse-reactions/spec/lib/discourse_workflows/nodes/post_reaction_spec.rb
@@ -0,0 +1,119 @@
+# frozen_string_literal: true
+
+RSpec.describe DiscourseWorkflows::Nodes::PostReaction::V1 do
+ fab!(:post)
+ fab!(:actor, :user)
+
+ before do
+ SiteSetting.discourse_reactions_enabled = true
+ SiteSetting.discourse_reactions_enabled_reactions = "laughing|hugs"
+ end
+
+ describe "#execute" do
+ let(:configuration) do
+ {
+ "operation" => operation,
+ "post_id" => post.id.to_s,
+ "reaction" => ":laughing:",
+ "if_exists" => if_exists,
+ "actor_username" => actor.username,
+ }
+ end
+ let(:if_exists) { "keep" }
+
+ def react(reaction)
+ DiscourseReactions::PostReaction::Toggle.call(
+ params: {
+ post_id: post.id,
+ reaction:,
+ },
+ guardian: actor.guardian,
+ )
+ end
+
+ def current_reaction
+ DiscourseReactions::ReactionManager.reaction_value_for(user: actor, post:)
+ end
+
+ context "with add operation" do
+ let(:operation) { "add" }
+
+ it "reacts to the post as the actor" do
+ result = execute_node(configuration:)
+
+ expect(result).to eq(
+ "post_id" => post.id,
+ "username" => actor.username,
+ "reaction" => "laughing",
+ "previous_reaction" => nil,
+ "changed" => true,
+ )
+ expect(result).to match_node_output_schema(described_class)
+ expect(current_reaction).to eq("laughing")
+ end
+
+ it "keeps a different existing reaction by default" do
+ react("hugs")
+
+ expect(execute_node(configuration:)).to include(
+ "reaction" => "hugs",
+ "previous_reaction" => "hugs",
+ "changed" => false,
+ )
+ expect(current_reaction).to eq("hugs")
+ end
+
+ context "when replacing existing reactions" do
+ let(:if_exists) { "replace" }
+
+ it "replaces a different existing reaction" do
+ react("hugs")
+
+ expect(execute_node(configuration:)).to include(
+ "reaction" => "laughing",
+ "previous_reaction" => "hugs",
+ "changed" => true,
+ )
+ expect(current_reaction).to eq("laughing")
+ end
+ end
+
+ it "fails when the reaction is not enabled" do
+ configuration["reaction"] = "rocket"
+
+ expect { execute_node(configuration:) }.to raise_error(
+ DiscourseWorkflows::NodeError,
+ /#{I18n.t("discourse_reactions.errors.reaction_unavailable")}/,
+ )
+ end
+
+ it "fails when the actor cannot react to the post" do
+ post.topic.update!(archived: true)
+
+ expect { execute_node(configuration:) }.to raise_error(DiscourseWorkflows::NodeError)
+ end
+ end
+
+ context "with remove operation" do
+ let(:operation) { "remove" }
+
+ it "removes the actor's matching reaction" do
+ react("laughing")
+
+ expect(execute_node(configuration:)).to include(
+ "reaction" => nil,
+ "previous_reaction" => "laughing",
+ "changed" => true,
+ )
+ expect(current_reaction).to be_nil
+ end
+
+ it "leaves a different reaction in place" do
+ react("hugs")
+
+ expect(execute_node(configuration:)).to include("reaction" => "hugs", "changed" => false)
+ expect(current_reaction).to eq("hugs")
+ end
+ end
+ end
+end
diff --git a/plugins/discourse-reactions/spec/services/post_reaction/toggle_spec.rb b/plugins/discourse-reactions/spec/services/post_reaction/toggle_spec.rb
index 3b1aaa1d3f8..27e1576c9f2 100644
--- a/plugins/discourse-reactions/spec/services/post_reaction/toggle_spec.rb
+++ b/plugins/discourse-reactions/spec/services/post_reaction/toggle_spec.rb
@@ -104,8 +104,9 @@ RSpec.describe DiscourseReactions::PostReaction::Toggle do
it { is_expected.to run_successfully }
it "creates the reaction" do
- expect { result }.to change { DiscourseReactions::ReactionUser.count }.by(1)
- expect(DiscourseReactions::ReactionUser.exists?(user: acting_user, post:)).to eq(true)
+ expect { result }.to change {
+ DiscourseReactions::ReactionUser.where(user: acting_user, post:).count
+ }.by(1)
end
it "publishes the changed reaction" do
diff --git a/plugins/discourse-reactions/spec/services/reaction_manager_spec.rb b/plugins/discourse-reactions/spec/services/reaction_manager_spec.rb
index fded1206122..7efdecef2dd 100644
--- a/plugins/discourse-reactions/spec/services/reaction_manager_spec.rb
+++ b/plugins/discourse-reactions/spec/services/reaction_manager_spec.rb
@@ -27,6 +27,16 @@ RSpec.describe DiscourseReactions::ReactionManager do
end
end
+ it "triggers an event with the reaction each toggle replaced" do
+ events =
+ DiscourseEvent.track_events(:post_reaction_toggled) do
+ described_class.new(reaction_value: "hugs", user:, post:).toggle!
+ described_class.new(reaction_value: "-1", user:, post:).toggle!
+ end
+
+ expect(events.pluck(:params)).to eq([[post, user, nil], [post, user, "hugs"]])
+ end
+
context "when switching to the default reaction" do
fab!(:topic)
fab!(:op_post) { Fabricate(:post, topic: topic) }
diff --git a/plugins/discourse-workflows/lib/discourse_workflows/ai/tools/workflow_node_catalog.rb b/plugins/discourse-workflows/lib/discourse_workflows/ai/tools/workflow_node_catalog.rb
index 397d1d3bd6f..f29ac2a068b 100644
--- a/plugins/discourse-workflows/lib/discourse_workflows/ai/tools/workflow_node_catalog.rb
+++ b/plugins/discourse-workflows/lib/discourse_workflows/ai/tools/workflow_node_catalog.rb
@@ -268,7 +268,11 @@ module DiscourseWorkflows
"action:flag_user" =>
"flag user report spammer spam suspect review queue moderation approve reject account signup",
"action:post_like" => "like unlike heart favorite upvote",
+ "action:post_reaction" => "react reaction emoji like heart",
+ "action:boost" => "boost micro reaction short note emoji",
"trigger:post_like_changed" => "liked unliked like heart favorite upvote",
+ "trigger:post_reaction_changed" => "reacted reaction emoji",
+ "trigger:post_boost_changed" => "boosted boost micro reaction",
"trigger:user_added_to_group" => "joined added to group membership member",
"trigger:user_removed_from_group" => "left removed from group membership member",
"trigger:user_created" => "signup sign up register registration new account joined site",