2020-06-12 17:42:47 +00:00
|
|
|
class HookJob < ApplicationJob
|
|
|
|
queue_as :integrations
|
|
|
|
|
2021-05-05 15:36:11 +00:00
|
|
|
def perform(hook, event_name, event_data = {})
|
|
|
|
case hook.app_id
|
|
|
|
when 'slack'
|
|
|
|
process_slack_integration(hook, event_name, event_data)
|
|
|
|
when 'dialogflow'
|
|
|
|
process_dialogflow_integration(hook, event_name, event_data)
|
|
|
|
end
|
2020-06-12 17:42:47 +00:00
|
|
|
rescue StandardError => e
|
2022-05-06 09:20:55 +00:00
|
|
|
Rails.logger.error e
|
2020-06-12 17:42:47 +00:00
|
|
|
end
|
2021-05-05 15:36:11 +00:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def process_slack_integration(hook, event_name, event_data)
|
|
|
|
return unless ['message.created'].include?(event_name)
|
|
|
|
|
|
|
|
message = event_data[:message]
|
|
|
|
Integrations::Slack::SendOnSlackService.new(message: message, hook: hook).perform
|
|
|
|
end
|
|
|
|
|
|
|
|
def process_dialogflow_integration(hook, event_name, event_data)
|
|
|
|
return unless ['message.created', 'message.updated'].include?(event_name)
|
|
|
|
|
|
|
|
Integrations::Dialogflow::ProcessorService.new(event_name: event_name, hook: hook, event_data: event_data).perform
|
|
|
|
end
|
2020-06-12 17:42:47 +00:00
|
|
|
end
|