diff --git a/app/models/pager_tree/integrations/channel/hangouts/v3.rb b/app/models/pager_tree/integrations/channel/hangouts/v3.rb index ab0fca5..f840bbd 100644 --- a/app/models/pager_tree/integrations/channel/hangouts/v3.rb +++ b/app/models/pager_tree/integrations/channel/hangouts/v3.rb @@ -7,6 +7,7 @@ class Channel::Hangouts::V3 < Integration {key: :alert_acknowledged, type: :boolean, default: false}, {key: :alert_resolved, type: :boolean, default: false}, {key: :alert_dropped, type: :boolean, default: false}, + {key: :thread_same_alert, type: :boolean, default: false}, {key: :outgoing_rules, type: :string, default: nil} ] store_accessor :options, *OPTIONS.map { |x| x[:key] }.map(&:to_s), prefix: "option" @@ -20,6 +21,7 @@ class Channel::Hangouts::V3 < Integration self.option_alert_acknowledged ||= false self.option_alert_resolved ||= false self.option_alert_dropped ||= false + self.option_thread_same_alert ||= false self.option_outgoing_rules ||= "" end @@ -59,6 +61,15 @@ def adapter_process_outgoing url = adapter_outgoing_event.outgoing_rules_data.dig("webhook_url") || self.option_incoming_webhook_url body = _blocks.merge(adapter_outgoing_event.outgoing_rules_data.except("webhook_url")) + if option_thread_same_alert == true + body[:thread] = {threadKey: _alert.id} + + uri = URI(url) + uri_params = URI.decode_www_form(uri.query || "").to_h.merge({messageReplyOption: "REPLY_MESSAGE_FALLBACK_TO_NEW_THREAD"}) + uri.query = URI.encode_www_form(uri_params) + url = uri.to_s + end + outgoing_webhook_delivery = OutgoingWebhookDelivery.factory( resource: self, url: url, diff --git a/app/models/pager_tree/integrations/channel/slack/v3.rb b/app/models/pager_tree/integrations/channel/slack/v3.rb index 81a965d..d4d6d1a 100644 --- a/app/models/pager_tree/integrations/channel/slack/v3.rb +++ b/app/models/pager_tree/integrations/channel/slack/v3.rb @@ -111,6 +111,16 @@ def _blocks title: "Destinations", value: _alert.alert_destinations&.map { |d| d.destination.name }&.join(", "), short: "false" + }, + { + title: "Actions", + value: [ + "<#{Rails.application.routes.url_helpers.try(:alert_url, _alert, script_name: "/#{_alert.account_id}")}|View>", + ["open", "dropped"].include?(_alert.status) ? "<#{Rails.application.routes.url_helpers.try(:acknowledge_alert_url, _alert, script_name: "/#{_alert.account_id}")}|Acknowledge>" : nil, + ["open"].include?(_alert.status) ? "<#{Rails.application.routes.url_helpers.try(:reject_alert_url, _alert, script_name: "/#{_alert.account_id}")}|Reject>" : nil, + ["acknowledged"].include?(_alert.status) ? "<#{Rails.application.routes.url_helpers.try(:resolve_alert_url, _alert, script_name: "/#{_alert.account_id}")}|Resolve>" : nil + ].compact.join(" | "), + short: "false" } ] } diff --git a/app/views/pager_tree/integrations/channel/hangouts/v3/_form_options.html.erb b/app/views/pager_tree/integrations/channel/hangouts/v3/_form_options.html.erb index ffe4d17..39dafc2 100644 --- a/app/views/pager_tree/integrations/channel/hangouts/v3/_form_options.html.erb +++ b/app/views/pager_tree/integrations/channel/hangouts/v3/_form_options.html.erb @@ -5,6 +5,12 @@

<%== t("pager_tree.integrations.common.option_incoming_webhook_url_hint_html") %>

+
+ <%= form.check_box :option_thread_same_alert, class: "form-checkbox mr-1" %> + <%= form.label :option_thread_same_alert, class: "inline-block" %> +

<%== t(".option_thread_same_alert_hint_html") %>

+
+ <% opts = [ :alert_open, diff --git a/app/views/pager_tree/integrations/channel/hangouts/v3/_show_options.html.erb b/app/views/pager_tree/integrations/channel/hangouts/v3/_show_options.html.erb index f4a0f5e..6c548e3 100644 --- a/app/views/pager_tree/integrations/channel/hangouts/v3/_show_options.html.erb +++ b/app/views/pager_tree/integrations/channel/hangouts/v3/_show_options.html.erb @@ -11,6 +11,15 @@ +
+
+ <%= t("activerecord.attributes.pager_tree/integrations/channel/hangouts/v3.option_thread_same_alert") %> +
+
+ <%= render partial: "shared/components/badge_enabled", locals: { enabled: integration.option_thread_same_alert } %> +
+
+ <% opts = [ :alert_open, diff --git a/config/locales/en.yml b/config/locales/en.yml index c3af7d0..b43b997 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -21,6 +21,10 @@ en: option_template_hint_html: "A handlebars template describing the body that should be posted. See docs for details." option_send_linked_hint_html: "Send linked data (source, source_log, user, team)" channel: + hangouts: + v3: + form_options: + option_thread_same_alert_hint_html: "Send all messages for the same alert to the same thread" microsoft_teams: v3: form_options: @@ -158,6 +162,8 @@ en: option_outgoing_rules: "Outgoing Rules" "pager_tree/integrations/apex_ping/v3": option_api_key: "API Key" + "pager_tree/integrations/channel/hangouts/v3": + option_thread_same_alert: "Thread Same Alert" "pager_tree/integrations/channel/microsoft_teams/v3": option_time_zone: "Display Time Zone" "pager_tree/integrations/cloudflare/v3": diff --git a/test/models/pager_tree/integrations/channel/mattermost/v3_test.rb b/test/models/pager_tree/integrations/channel/mattermost/v3_test.rb index 74d65c0..7bbcfbe 100644 --- a/test/models/pager_tree/integrations/channel/mattermost/v3_test.rb +++ b/test/models/pager_tree/integrations/channel/mattermost/v3_test.rb @@ -88,6 +88,14 @@ class Channel::Mattermost::V3Test < ActiveSupport::TestCase title: "Destinations", value: @alert.alert_destinations&.map { |d| d.destination.name }&.join(", "), short: "false" + }, + { + title: "Actions", + value: [ + "<|View>", + "<|Resolve>" + ].join(" | "), + short: "false" } ] } diff --git a/test/models/pager_tree/integrations/channel/slack/v3_test.rb b/test/models/pager_tree/integrations/channel/slack/v3_test.rb index b66f3c6..5e079a0 100644 --- a/test/models/pager_tree/integrations/channel/slack/v3_test.rb +++ b/test/models/pager_tree/integrations/channel/slack/v3_test.rb @@ -88,6 +88,14 @@ class Channel::Slack::V3Test < ActiveSupport::TestCase title: "Destinations", value: @alert.alert_destinations&.map { |d| d.destination.name }&.join(", "), short: "false" + }, + { + title: "Actions", + value: [ + "<|View>", + "<|Resolve>" + ].join(" | "), + short: "false" } ] }