DEV: send_chat_message supports topic_tags_changed (#28755)
This will allow admins to use this script and trigger together.
This commit is contained in:
parent
e991574389
commit
81c5f1d75f
|
@ -452,7 +452,6 @@ after_initialize do
|
|||
}
|
||||
end
|
||||
|
||||
if defined?(DiscourseAutomation)
|
||||
add_automation_scriptable("send_chat_message") do
|
||||
field :chat_channel_id, component: :text, required: true
|
||||
field :message, component: :message, required: true, accepts_placeholders: true
|
||||
|
@ -460,12 +459,11 @@ after_initialize do
|
|||
|
||||
placeholder :channel_name
|
||||
|
||||
triggerables [:recurring]
|
||||
triggerables %i[recurring topic_tags_changed]
|
||||
|
||||
script do |context, fields, automation|
|
||||
sender = User.find_by(username: fields.dig("sender", "value")) || Discourse.system_user
|
||||
channel = Chat::Channel.find_by(id: fields.dig("chat_channel_id", "value"))
|
||||
|
||||
placeholders = { channel_name: channel.title(sender) }.merge(context["placeholders"] || {})
|
||||
|
||||
creator =
|
||||
|
@ -480,7 +478,6 @@ after_initialize do
|
|||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
add_api_key_scope(
|
||||
:chat,
|
||||
|
|
|
@ -339,4 +339,52 @@ describe Chat do
|
|||
).by(1)
|
||||
end
|
||||
end
|
||||
|
||||
describe "when using topic tags changed trigger automation" do
|
||||
describe "with the send message script" do
|
||||
fab!(:automation_1) do
|
||||
Fabricate(
|
||||
:automation,
|
||||
trigger: DiscourseAutomation::Triggers::TOPIC_TAGS_CHANGED,
|
||||
script: :send_chat_message,
|
||||
)
|
||||
end
|
||||
fab!(:tag_1) { Fabricate(:tag) }
|
||||
fab!(:user_1) { Fabricate(:admin) }
|
||||
fab!(:topic_1) { Fabricate(:topic) }
|
||||
fab!(:channel_1) { Fabricate(:chat_channel) }
|
||||
|
||||
before do
|
||||
SiteSetting.discourse_automation_enabled = true
|
||||
SiteSetting.tagging_enabled = true
|
||||
|
||||
automation_1.upsert_field!(
|
||||
"watching_tags",
|
||||
"tags",
|
||||
{ value: [tag_1.name] },
|
||||
target: "trigger",
|
||||
)
|
||||
automation_1.upsert_field!(
|
||||
"chat_channel_id",
|
||||
"text",
|
||||
{ value: channel_1.id },
|
||||
target: "script",
|
||||
)
|
||||
automation_1.upsert_field!(
|
||||
"message",
|
||||
"message",
|
||||
{ value: "[{{topic_title}}]({{topic_url}})" },
|
||||
target: "script",
|
||||
)
|
||||
end
|
||||
|
||||
it "sends the message" do
|
||||
DiscourseTagging.tag_topic_by_names(topic_1, Guardian.new(user_1), [tag_1.name])
|
||||
|
||||
expect(channel_1.chat_messages.last.message).to eq(
|
||||
"[#{topic_1.title}](#{topic_1.relative_url})",
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue