From 053c3286f75ead6ffb9288a2514b402db74d3cb9 Mon Sep 17 00:00:00 2001 From: nestordavalos Date: Sat, 30 Mar 2024 17:48:08 -0400 Subject: [PATCH] feat: webhook support in macros --- .../dashboard/routes/dashboard/settings/macros/constants.js | 5 +++++ app/models/macro.rb | 2 +- app/services/macros/execution_service.rb | 5 +++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/javascript/dashboard/routes/dashboard/settings/macros/constants.js b/app/javascript/dashboard/routes/dashboard/settings/macros/constants.js index 111a3632d9ccb..e0bad4cb6a5ec 100644 --- a/app/javascript/dashboard/routes/dashboard/settings/macros/constants.js +++ b/app/javascript/dashboard/routes/dashboard/settings/macros/constants.js @@ -44,6 +44,11 @@ export const MACRO_ACTION_TYPES = [ label: 'Resolve conversation', inputType: null, }, + { + key: 'send_webhook_event', + label: 'Send Webhook Event', + inputType: 'url', + }, { key: 'send_attachment', label: 'Send Attachment', diff --git a/app/models/macro.rb b/app/models/macro.rb index 64065a3421dd7..a27f758f85701 100644 --- a/app/models/macro.rb +++ b/app/models/macro.rb @@ -30,7 +30,7 @@ class Macro < ApplicationRecord validate :json_actions_format - ACTIONS_ATTRS = %w[send_message add_label assign_team assign_agent mute_conversation change_status remove_label remove_assigned_team + ACTIONS_ATTRS = %w[send_message add_label assign_team assign_agent mute_conversation change_status remove_label remove_assigned_team send_webhook_event resolve_conversation snooze_conversation change_priority send_email_transcript send_attachment add_private_note].freeze def set_visibility(user, params) diff --git a/app/services/macros/execution_service.rb b/app/services/macros/execution_service.rb index 81da53fca1802..30ac9a3b4a28d 100644 --- a/app/services/macros/execution_service.rb +++ b/app/services/macros/execution_service.rb @@ -22,6 +22,11 @@ def perform private + def send_webhook_event(webhook_url) + payload = @conversation.webhook_data.merge(event: "macro_event.#{@macro.name}") + WebhookJob.perform_later(webhook_url[0], payload) + end + def assign_agent(agent_ids) agent_ids = agent_ids.map { |id| id == 'self' ? @user.id : id } super(agent_ids)