Skip to content

Commit dc1666a

Browse files
authored
Add support for comment events to the outgoing webhook (#146)
1 parent 0ae5bc8 commit dc1666a

6 files changed

Lines changed: 58 additions & 1 deletion

File tree

app/models/pager_tree/integrations/live_call_routing/twilio/v3.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def adapter_supports_auto_aggregate?
138138
end
139139

140140
def adapter_outgoing_interest?(event_name)
141-
["alert_acknowledged", "alert_dropped"].include?(event_name) && adapter_alert.source_id == id
141+
["alert_acknowledged", "alert_dropped"].include?(event_name)
142142
end
143143

144144
def adapter_incoming_can_defer?
@@ -391,6 +391,8 @@ def adapter_process_queue_status_deferred
391391
end
392392

393393
def adapter_process_outgoing
394+
return unless adapter_alert.source_id == id
395+
394396
event = adapter_outgoing_event.event_name.to_s
395397
if event == "alert_acknowledged"
396398
_on_acknowledge

app/models/pager_tree/integrations/outgoing_event.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ class OutgoingEvent
55
extend ActiveModel::Callbacks
66

77
attr_accessor :event_name
8+
attr_accessor :account_id
9+
attr_accessor :item_id
810
attr_accessor :item
911
attr_accessor :changes
1012
attr_accessor :outgoing_rules_data
@@ -25,6 +27,8 @@ def initialize(params = {})
2527

2628
after_initialize do
2729
self.event_name ||= nil
30+
self.account_id ||= nil
31+
self.item_id ||= nil
2832
self.item ||= nil
2933
self.changes ||= nil
3034
self.outgoing_rules_data ||= {}

app/models/pager_tree/integrations/outgoing_webhook/v3.rb

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ class OutgoingWebhook::V3 < Integration
1515
{key: :alert_handoff, type: :boolean, default: false},
1616
{key: :event_reminder_going_on_call, type: :boolean, default: false},
1717
{key: :event_reminder_going_off_call, type: :boolean, default: false},
18+
{key: :comment_created, type: :boolean, default: false},
19+
{key: :comment_updated, type: :boolean, default: false},
20+
{key: :comment_destroyed, type: :boolean, default: false},
1821
{key: :template, type: :string, default: nil},
1922
{key: :send_linked, type: :boolean, default: false},
2023
{key: :outgoing_rules, type: :string, default: nil}
@@ -33,6 +36,9 @@ class OutgoingWebhook::V3 < Integration
3336
validates :option_alert_handoff, inclusion: {in: [true, false]}
3437
validates :option_event_reminder_going_on_call, inclusion: {in: [true, false]}
3538
validates :option_event_reminder_going_off_call, inclusion: {in: [true, false]}
39+
validates :option_comment_created, inclusion: {in: [true, false]}
40+
validates :option_comment_updated, inclusion: {in: [true, false]}
41+
validates :option_comment_destroyed, inclusion: {in: [true, false]}
3642
validates :option_send_linked, inclusion: {in: [true, false]}
3743

3844
after_initialize do
@@ -46,6 +52,9 @@ class OutgoingWebhook::V3 < Integration
4652
self.option_alert_handoff ||= false
4753
self.option_event_reminder_going_on_call ||= false
4854
self.option_event_reminder_going_off_call ||= false
55+
self.option_comment_created ||= false
56+
self.option_comment_updated ||= false
57+
self.option_comment_destroyed ||= false
4958
self.option_send_linked ||= false
5059
self.option_template ||= ""
5160
self.option_outgoing_rules ||= ""
@@ -104,6 +113,36 @@ def adapter_process_outgoing
104113
body = {}
105114
body[:type] = event_type
106115
body[:data] = case event_type
116+
when "comment.destroyed"
117+
{
118+
account_id: adapter_outgoing_event.account_id,
119+
id: adapter_outgoing_event.item_id
120+
}
121+
when "comment.created", "comment.updated"
122+
{
123+
account_id: adapter_outgoing_event.comment.account_id,
124+
id: adapter_outgoing_event.comment.id,
125+
prefix_id: adapter_outgoing_event.comment.prefix_id,
126+
meta: adapter_outgoing_event.comment.meta,
127+
commentable_type: adapter_outgoing_event.comment.commentable_type,
128+
commentable_id: adapter_outgoing_event.comment.commentable_id,
129+
parent_id: adapter_outgoing_event.comment.parent_id,
130+
account_user_id: adapter_outgoing_event.comment.account_user_id,
131+
account_user: {
132+
id: adapter_outgoing_event.comment.account_user.id,
133+
prefix_id: adapter_outgoing_event.comment.account_user.prefix_id,
134+
user: {
135+
id: adapter_outgoing_event.comment.account_user.user.id,
136+
prefix_id: adapter_outgoing_event.comment.account_user.user.prefix_id,
137+
name: adapter_outgoing_event.comment.account_user.user.name,
138+
email: adapter_outgoing_event.comment.account_user.user.email
139+
}
140+
},
141+
created_by_name: adapter_outgoing_event.comment.created_by_name,
142+
updated_at: adapter_outgoing_event.comment.updated_at,
143+
created_at: adapter_outgoing_event.comment.created_at,
144+
body: adapter_outgoing_event.comment.body.to_plain_text
145+
}
107146
when "event_reminder.going_on_call", "event_reminder.going_off_call"
108147
{
109148
id: adapter_outgoing_event.event_reminder.id,

app/views/pager_tree/integrations/outgoing_webhook/v3/_form_options.html.erb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
:alert_resolved,
3737
:alert_dropped,
3838
:alert_handoff,
39+
:comment_created,
40+
:comment_updated,
41+
:comment_destroyed,
3942
:event_reminder_going_on_call,
4043
:event_reminder_going_off_call,
4144
:send_linked

app/views/pager_tree/integrations/outgoing_webhook/v3/_show_options.html.erb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@
6262
:alert_resolved,
6363
:alert_dropped,
6464
:alert_handoff,
65+
:comment_created,
66+
:comment_updated,
67+
:comment_destroyed,
6568
:event_reminder_going_on_call,
6669
:event_reminder_going_off_call,
6770
]

config/locales/en.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ en:
1616
option_alert_resolved_hint_html: "Send when the alert is marked resolved"
1717
option_alert_dropped_hint_html: "Send when the alert is dropped"
1818
option_alert_handoff_hint_html: "Send when the alert has been handed off"
19+
option_comment_created_hint_html: "Send when a comment is created"
20+
option_comment_updated_hint_html: "Send when a comment is updated"
21+
option_comment_destroyed_hint_html: "Send when a comment is deleted"
1922
option_event_reminder_going_on_call_hint_html: "Send when a user is going on call"
2023
option_event_reminder_going_off_call_hint_html: "Send when a user is going off call"
2124
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."
@@ -187,6 +190,9 @@ en:
187190
option_alert_resolved: "alert.resolved"
188191
option_alert_dropped: "alert.dropped"
189192
option_alert_handoff: "alert.handoff"
193+
option_comment_created: "comment.created"
194+
option_comment_updated: "comment.updated"
195+
option_comment_destroyed: "comment.destroyed"
190196
option_event_reminder_going_on_call: "event_reminder.going_on_call"
191197
option_event_reminder_going_off_call: "event_reminder.going_off_call"
192198
option_outgoing_rules: "Outgoing Rules"

0 commit comments

Comments
 (0)