Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chat upgrades #128

Merged
merged 4 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions app/models/pager_tree/integrations/channel/hangouts/v3.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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

Expand Down Expand Up @@ -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,
Expand Down
10 changes: 10 additions & 0 deletions app/models/pager_tree/integrations/channel/slack/v3.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
<p class="form-hint"><%== t("pager_tree.integrations.common.option_incoming_webhook_url_hint_html") %></p>
</div>

<div class="form-group group">
<%= form.check_box :option_thread_same_alert, class: "form-checkbox mr-1" %>
<%= form.label :option_thread_same_alert, class: "inline-block" %>
<p class="form-hint inline-block"><%== t(".option_thread_same_alert_hint_html") %></p>
</div>

<%
opts = [
:alert_open,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@
</dd>
</div>

<div class="sm:col-span-1">
<dt class="text-sm font-medium text-gray-500">
<%= t("activerecord.attributes.pager_tree/integrations/channel/hangouts/v3.option_thread_same_alert") %>
</dt>
<dd class="mt-1 text-sm text-gray-900">
<%= render partial: "shared/components/badge_enabled", locals: { enabled: integration.option_thread_same_alert } %>
</dd>
</div>

<%
opts = [
:alert_open,
Expand Down
6 changes: 6 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ en:
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."
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:
Expand Down Expand Up @@ -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":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
]
}
Expand Down
8 changes: 8 additions & 0 deletions test/models/pager_tree/integrations/channel/slack/v3_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
]
}
Expand Down
Loading