diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index af8440c..a1a4a48 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -290,3 +290,5 @@ en: description: "You can find the channel name in the Chat Integration settings" provider: label: Provider + trigger_with_pms: + label: Trigger with PMs \ No newline at end of file diff --git a/plugin.rb b/plugin.rb index 0f76787..14bf610 100644 --- a/plugin.rb +++ b/plugin.rb @@ -97,13 +97,16 @@ after_initialize do }, required: true field :channel_name, component: :text, required: true + field :trigger_with_pms, component: :boolean version 1 triggerables %i[topic_tags_changed] script do |context, fields, automation| - next if context["topic"].private_message? + if context["topic"].private_message? + next unless fields.dig("trigger_with_pms", "value") + end # DiscourseTagging.tag_topic_by_names runs on topic creation and on tags change # we only want to send a message when tags change diff --git a/spec/integration/automation_spec.rb b/spec/integration/automation_spec.rb index 788a8be..5a341c6 100644 --- a/spec/integration/automation_spec.rb +++ b/spec/integration/automation_spec.rb @@ -87,7 +87,7 @@ RSpec.describe "Triggering notifications" do expect(validated_provider.sent_messages.length).to eq(0) end - it "should not trigger notifications for PMs" do + it "should not trigger notifications for PMs by default" do automation.upsert_field!( "watching_categories", "categories", @@ -95,15 +95,25 @@ RSpec.describe "Triggering notifications" do target: "trigger", ) - topic = - TopicCreator.create( - admin, - Guardian.new(admin), - valid_attrs.merge(archetype: Archetype.private_message, target_usernames: admin.username), - ) + pm = Fabricate(:private_message_topic) + DiscourseTagging.tag_topic_by_names(pm, Guardian.new(admin), [tag.name]) - DiscourseTagging.tag_topic_by_names(topic, Guardian.new(admin), [tag.name]) expect(validated_provider.sent_messages.length).to eq(0) end + + it "should trigger notifications for PMs when trigger_with_pms is set" do + automation.upsert_field!( + "watching_categories", + "categories", + { "value" => [nil] }, + target: "trigger", + ) + automation.upsert_field!("trigger_with_pms", "boolean", { "value" => true }, target: "script") + + pm = Fabricate(:private_message_topic) + DiscourseTagging.tag_topic_by_names(pm, Guardian.new(admin), [tag.name]) + + expect(validated_provider.sent_messages.length).to eq(1) + end end end