2024-04-03 23:20:43 +08:00
# 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 (
2024-05-07 04:12:55 +08:00
Jobs :: DiscourseAutomation :: CallZapierWebhook ,
2024-04-03 23:20:43 +08:00
webhook_url : webhook_url ,
context : context ,
)
end
end