FEATURE: add `trigger_with_pms` option to automation
This commit is contained in:
parent
e906290311
commit
74e5cc6695
|
@ -290,3 +290,5 @@ en:
|
||||||
description: "You can find the channel name in the Chat Integration settings"
|
description: "You can find the channel name in the Chat Integration settings"
|
||||||
provider:
|
provider:
|
||||||
label: Provider
|
label: Provider
|
||||||
|
trigger_with_pms:
|
||||||
|
label: Trigger with PMs
|
|
@ -97,13 +97,16 @@ after_initialize do
|
||||||
},
|
},
|
||||||
required: true
|
required: true
|
||||||
field :channel_name, component: :text, required: true
|
field :channel_name, component: :text, required: true
|
||||||
|
field :trigger_with_pms, component: :boolean
|
||||||
|
|
||||||
version 1
|
version 1
|
||||||
|
|
||||||
triggerables %i[topic_tags_changed]
|
triggerables %i[topic_tags_changed]
|
||||||
|
|
||||||
script do |context, fields, automation|
|
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
|
# DiscourseTagging.tag_topic_by_names runs on topic creation and on tags change
|
||||||
# we only want to send a message when tags change
|
# we only want to send a message when tags change
|
||||||
|
|
|
@ -87,7 +87,7 @@ RSpec.describe "Triggering notifications" do
|
||||||
expect(validated_provider.sent_messages.length).to eq(0)
|
expect(validated_provider.sent_messages.length).to eq(0)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should not trigger notifications for PMs" do
|
it "should not trigger notifications for PMs by default" do
|
||||||
automation.upsert_field!(
|
automation.upsert_field!(
|
||||||
"watching_categories",
|
"watching_categories",
|
||||||
"categories",
|
"categories",
|
||||||
|
@ -95,15 +95,25 @@ RSpec.describe "Triggering notifications" do
|
||||||
target: "trigger",
|
target: "trigger",
|
||||||
)
|
)
|
||||||
|
|
||||||
topic =
|
pm = Fabricate(:private_message_topic)
|
||||||
TopicCreator.create(
|
DiscourseTagging.tag_topic_by_names(pm, Guardian.new(admin), [tag.name])
|
||||||
admin,
|
|
||||||
Guardian.new(admin),
|
|
||||||
valid_attrs.merge(archetype: Archetype.private_message, target_usernames: admin.username),
|
|
||||||
)
|
|
||||||
|
|
||||||
DiscourseTagging.tag_topic_by_names(topic, Guardian.new(admin), [tag.name])
|
|
||||||
expect(validated_provider.sent_messages.length).to eq(0)
|
expect(validated_provider.sent_messages.length).to eq(0)
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue