Skip to content

Commit 18c1a39

Browse files
authored
Chat upgrades (#128)
1 parent e1e07d6 commit 18c1a39

File tree

7 files changed

+58
-0
lines changed

7 files changed

+58
-0
lines changed

app/models/pager_tree/integrations/channel/hangouts/v3.rb

+11
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class Channel::Hangouts::V3 < Integration
77
{key: :alert_acknowledged, type: :boolean, default: false},
88
{key: :alert_resolved, type: :boolean, default: false},
99
{key: :alert_dropped, type: :boolean, default: false},
10+
{key: :thread_same_alert, type: :boolean, default: false},
1011
{key: :outgoing_rules, type: :string, default: nil}
1112
]
1213
store_accessor :options, *OPTIONS.map { |x| x[:key] }.map(&:to_s), prefix: "option"
@@ -20,6 +21,7 @@ class Channel::Hangouts::V3 < Integration
2021
self.option_alert_acknowledged ||= false
2122
self.option_alert_resolved ||= false
2223
self.option_alert_dropped ||= false
24+
self.option_thread_same_alert ||= false
2325
self.option_outgoing_rules ||= ""
2426
end
2527

@@ -59,6 +61,15 @@ def adapter_process_outgoing
5961
url = adapter_outgoing_event.outgoing_rules_data.dig("webhook_url") || self.option_incoming_webhook_url
6062
body = _blocks.merge(adapter_outgoing_event.outgoing_rules_data.except("webhook_url"))
6163

64+
if option_thread_same_alert == true
65+
body[:thread] = {threadKey: _alert.id}
66+
67+
uri = URI(url)
68+
uri_params = URI.decode_www_form(uri.query || "").to_h.merge({messageReplyOption: "REPLY_MESSAGE_FALLBACK_TO_NEW_THREAD"})
69+
uri.query = URI.encode_www_form(uri_params)
70+
url = uri.to_s
71+
end
72+
6273
outgoing_webhook_delivery = OutgoingWebhookDelivery.factory(
6374
resource: self,
6475
url: url,

app/models/pager_tree/integrations/channel/slack/v3.rb

+10
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,16 @@ def _blocks
111111
title: "Destinations",
112112
value: _alert.alert_destinations&.map { |d| d.destination.name }&.join(", "),
113113
short: "false"
114+
},
115+
{
116+
title: "Actions",
117+
value: [
118+
"<#{Rails.application.routes.url_helpers.try(:alert_url, _alert, script_name: "/#{_alert.account_id}")}|View>",
119+
["open", "dropped"].include?(_alert.status) ? "<#{Rails.application.routes.url_helpers.try(:acknowledge_alert_url, _alert, script_name: "/#{_alert.account_id}")}|Acknowledge>" : nil,
120+
["open"].include?(_alert.status) ? "<#{Rails.application.routes.url_helpers.try(:reject_alert_url, _alert, script_name: "/#{_alert.account_id}")}|Reject>" : nil,
121+
["acknowledged"].include?(_alert.status) ? "<#{Rails.application.routes.url_helpers.try(:resolve_alert_url, _alert, script_name: "/#{_alert.account_id}")}|Resolve>" : nil
122+
].compact.join(" | "),
123+
short: "false"
114124
}
115125
]
116126
}

app/views/pager_tree/integrations/channel/hangouts/v3/_form_options.html.erb

+6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
<p class="form-hint"><%== t("pager_tree.integrations.common.option_incoming_webhook_url_hint_html") %></p>
66
</div>
77

8+
<div class="form-group group">
9+
<%= form.check_box :option_thread_same_alert, class: "form-checkbox mr-1" %>
10+
<%= form.label :option_thread_same_alert, class: "inline-block" %>
11+
<p class="form-hint inline-block"><%== t(".option_thread_same_alert_hint_html") %></p>
12+
</div>
13+
814
<%
915
opts = [
1016
:alert_open,

app/views/pager_tree/integrations/channel/hangouts/v3/_show_options.html.erb

+9
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@
1111
</dd>
1212
</div>
1313

14+
<div class="sm:col-span-1">
15+
<dt class="text-sm font-medium text-gray-500">
16+
<%= t("activerecord.attributes.pager_tree/integrations/channel/hangouts/v3.option_thread_same_alert") %>
17+
</dt>
18+
<dd class="mt-1 text-sm text-gray-900">
19+
<%= render partial: "shared/components/badge_enabled", locals: { enabled: integration.option_thread_same_alert } %>
20+
</dd>
21+
</div>
22+
1423
<%
1524
opts = [
1625
:alert_open,

config/locales/en.yml

+6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ en:
2121
option_template_hint_html: "A handlebars template describing the body that should be posted. See <a href='https://pagertree.com/docs/integration-guides/outgoing-webhook#custom-format' target='_blank'>docs</a> for details."
2222
option_send_linked_hint_html: "Send linked data (source, source_log, user, team)"
2323
channel:
24+
hangouts:
25+
v3:
26+
form_options:
27+
option_thread_same_alert_hint_html: "Send all messages for the same alert to the same thread"
2428
microsoft_teams:
2529
v3:
2630
form_options:
@@ -158,6 +162,8 @@ en:
158162
option_outgoing_rules: "Outgoing Rules"
159163
"pager_tree/integrations/apex_ping/v3":
160164
option_api_key: "API Key"
165+
"pager_tree/integrations/channel/hangouts/v3":
166+
option_thread_same_alert: "Thread Same Alert"
161167
"pager_tree/integrations/channel/microsoft_teams/v3":
162168
option_time_zone: "Display Time Zone"
163169
"pager_tree/integrations/cloudflare/v3":

test/models/pager_tree/integrations/channel/mattermost/v3_test.rb

+8
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,14 @@ class Channel::Mattermost::V3Test < ActiveSupport::TestCase
8888
title: "Destinations",
8989
value: @alert.alert_destinations&.map { |d| d.destination.name }&.join(", "),
9090
short: "false"
91+
},
92+
{
93+
title: "Actions",
94+
value: [
95+
"<|View>",
96+
"<|Resolve>"
97+
].join(" | "),
98+
short: "false"
9199
}
92100
]
93101
}

test/models/pager_tree/integrations/channel/slack/v3_test.rb

+8
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,14 @@ class Channel::Slack::V3Test < ActiveSupport::TestCase
8888
title: "Destinations",
8989
value: @alert.alert_destinations&.map { |d| d.destination.name }&.join(", "),
9090
short: "false"
91+
},
92+
{
93+
title: "Actions",
94+
value: [
95+
"<|View>",
96+
"<|Resolve>"
97+
].join(" | "),
98+
short: "false"
9199
}
92100
]
93101
}

0 commit comments

Comments
 (0)