mirror of
https://github.com/discourse/discourse.git
synced 2024-12-25 02:13:45 +08:00
3d4faf3272
Automation (previously known as discourse-automation) is now a core plugin.
25 lines
770 B
Ruby
25 lines
770 B
Ruby
# frozen_string_literal: true
|
|
|
|
DiscourseAutomation::Scriptable.add(DiscourseAutomation::Scripts::ZAPIER_WEBHOOK) do
|
|
field :webhook_url, component: :text, required: true
|
|
|
|
version 1
|
|
|
|
triggerables %i[user_promoted user_added_to_group user_badge_granted user_removed_from_group]
|
|
|
|
script do |context, fields|
|
|
webhook_url = fields.dig("webhook_url", "value")
|
|
|
|
unless webhook_url&.start_with?("https://hooks.zapier.com/hooks/catch/")
|
|
Rails.logger.warn "[discourse-automation] #{webhook_url} is not a valid Zapier webhook URL, expecting an URL starting with https://hooks.zapier.com/hooks/catch/"
|
|
next
|
|
end
|
|
|
|
Jobs.enqueue(
|
|
:discourse_automation_call_zapier_webhook,
|
|
webhook_url: webhook_url,
|
|
context: context,
|
|
)
|
|
end
|
|
end
|