mirror of
https://github.com/discourse/discourse.git
synced 2025-05-25 00:32:52 +08:00
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:
@ -452,32 +452,29 @@ 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
|
||||
field :sender, component: :user
|
||||
add_automation_scriptable("send_chat_message") do
|
||||
field :chat_channel_id, component: :text, required: true
|
||||
field :message, component: :message, required: true, accepts_placeholders: true
|
||||
field :sender, component: :user
|
||||
|
||||
placeholder :channel_name
|
||||
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"))
|
||||
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"] || {})
|
||||
|
||||
placeholders = { channel_name: channel.title(sender) }.merge(context["placeholders"] || {})
|
||||
creator =
|
||||
::Chat::CreateMessage.call(
|
||||
chat_channel_id: channel.id,
|
||||
guardian: sender.guardian,
|
||||
message: utils.apply_placeholders(fields.dig("message", "value"), placeholders),
|
||||
)
|
||||
|
||||
creator =
|
||||
::Chat::CreateMessage.call(
|
||||
chat_channel_id: channel.id,
|
||||
guardian: sender.guardian,
|
||||
message: utils.apply_placeholders(fields.dig("message", "value"), placeholders),
|
||||
)
|
||||
|
||||
if creator.failure?
|
||||
Rails.logger.warn "[discourse-automation] Chat message failed to send:\n#{creator.inspect_steps.inspect}\n#{creator.inspect_steps.error}"
|
||||
end
|
||||
if creator.failure?
|
||||
Rails.logger.warn "[discourse-automation] Chat message failed to send:\n#{creator.inspect_steps.inspect}\n#{creator.inspect_steps.error}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user