diff --git a/plugin.rb b/plugin.rb index d7a0e37..c8a466e 100644 --- a/plugin.rb +++ b/plugin.rb @@ -103,6 +103,10 @@ after_initialize do triggerables %i[topic_tags_changed] script do |context, fields, automation| + # DiscourseTagging.tag_topic_by_names runs on topic creation and on tags change + # we only want to send a message when tags change + next if context["topic"].new_record? + provider = fields.dig("provider", "value") channel_name = fields.dig("channel_name", "value") diff --git a/spec/integration/automation_spec.rb b/spec/integration/automation_spec.rb index 8ba4c75..081de47 100644 --- a/spec/integration/automation_spec.rb +++ b/spec/integration/automation_spec.rb @@ -7,6 +7,7 @@ RSpec.describe "Triggering notifications" do fab!(:admin) fab!(:category) fab!(:tag) + let(:valid_attrs) { Fabricate.attributes_for(:topic) } fab!(:automation) do Fabricate( @@ -74,5 +75,14 @@ RSpec.describe "Triggering notifications" do expect(validated_provider.sent_messages.length).to eq(0) end + + it "should not trigger a provider notification on topic creation for topic_tags_changed script" do + TopicCreator.create( + admin, + Guardian.new(admin), + valid_attrs.merge(tags: [tag.name], category: category.id), + ) + expect(validated_provider.sent_messages.length).to eq(0) + end end end