pager_tree-integrations 1.1.1 → 1.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/pager_tree/integrations/live_call_routing/twilio/v3_controller.rb +11 -0
  3. data/app/mailers/pager_tree/integrations/live_call_routing/twilio/v3_mailer.rb +17 -0
  4. data/app/models/pager_tree/integrations/apex_ping/v3.rb +1 -1
  5. data/app/models/pager_tree/integrations/app_dynamics/v3.rb +1 -1
  6. data/app/models/pager_tree/integrations/auvik/v3.rb +1 -1
  7. data/app/models/pager_tree/integrations/aws_cloudwatch/v3.rb +1 -1
  8. data/app/models/pager_tree/integrations/azure_monitor/v3.rb +5 -6
  9. data/app/models/pager_tree/integrations/channel/hangouts/v3.rb +1 -1
  10. data/app/models/pager_tree/integrations/channel/microsoft_teams/v3.rb +1 -1
  11. data/app/models/pager_tree/integrations/channel/slack/v3.rb +1 -1
  12. data/app/models/pager_tree/integrations/cronitor/v3.rb +1 -1
  13. data/app/models/pager_tree/integrations/datadog/v3.rb +1 -1
  14. data/app/models/pager_tree/integrations/dead_mans_snitch/v3.rb +1 -1
  15. data/app/models/pager_tree/integrations/elast_alert/v3.rb +1 -1
  16. data/app/models/pager_tree/integrations/form/v3.rb +1 -1
  17. data/app/models/pager_tree/integrations/freshdesk/v3.rb +1 -1
  18. data/app/models/pager_tree/integrations/freshservice/v3.rb +1 -1
  19. data/app/models/pager_tree/integrations/grafana/v3.rb +1 -1
  20. data/app/models/pager_tree/integrations/healthchecks/v3.rb +1 -1
  21. data/app/models/pager_tree/integrations/honeybadger/v3.rb +1 -1
  22. data/app/models/pager_tree/integrations/hyperping/v3.rb +1 -1
  23. data/app/models/pager_tree/integrations/integration.rb +6 -2
  24. data/app/models/pager_tree/integrations/jira_server/v3.rb +1 -1
  25. data/app/models/pager_tree/integrations/jotform/v3.rb +1 -1
  26. data/app/models/pager_tree/integrations/kapacitor/v3.rb +1 -1
  27. data/app/models/pager_tree/integrations/live_call_routing/twilio/v3.rb +83 -40
  28. data/app/models/pager_tree/integrations/logic_monitor/v3.rb +1 -3
  29. data/app/models/pager_tree/integrations/mattermost/outgoing_webhook/v3.rb +1 -1
  30. data/app/models/pager_tree/integrations/new_relic/v3.rb +1 -3
  31. data/app/models/pager_tree/integrations/outgoing_event.rb +9 -0
  32. data/app/models/pager_tree/integrations/outgoing_webhook/v3.rb +2 -2
  33. data/app/models/pager_tree/integrations/pingdom/v3.rb +1 -1
  34. data/app/models/pager_tree/integrations/prometheus/v3.rb +1 -1
  35. data/app/models/pager_tree/integrations/prtg/v3.rb +1 -1
  36. data/app/models/pager_tree/integrations/server_guard24/v3.rb +1 -1
  37. data/app/models/pager_tree/integrations/site24x7/v3.rb +1 -1
  38. data/app/models/pager_tree/integrations/solar_winds/v3.rb +1 -1
  39. data/app/models/pager_tree/integrations/stackdriver/v3.rb +1 -1
  40. data/app/models/pager_tree/integrations/status_cake/v3.rb +1 -1
  41. data/app/models/pager_tree/integrations/twilio/incoming_sms/v3.rb +1 -1
  42. data/app/models/pager_tree/integrations/typeform/v3.rb +1 -1
  43. data/app/models/pager_tree/integrations/uptime/v3.rb +1 -1
  44. data/app/models/pager_tree/integrations/uptime_robot/v3.rb +1 -1
  45. data/app/models/pager_tree/integrations/webhook/v3.rb +21 -15
  46. data/app/models/pager_tree/integrations/zendesk/v3.rb +1 -3
  47. data/app/views/layouts/pager_tree/integrations/live_call_routing/twilio/mailer.html.erb +13 -0
  48. data/app/views/layouts/pager_tree/integrations/live_call_routing/twilio/mailer.text.erb +1 -0
  49. data/app/views/pager_tree/integrations/channel/hangouts/v3/_form_options.html.erb +4 -4
  50. data/app/views/pager_tree/integrations/channel/microsoft_teams/v3/_form_options.html.erb +5 -5
  51. data/app/views/pager_tree/integrations/channel/slack/v3/_form_options.html.erb +5 -5
  52. data/app/views/pager_tree/integrations/email/v3/_form_options.html.erb +5 -5
  53. data/app/views/pager_tree/integrations/form/v3/_form_options.html.erb +18 -18
  54. data/app/views/pager_tree/integrations/honeybadger/v3/_form_options.html.erb +1 -1
  55. data/app/views/pager_tree/integrations/jira_server/v3/_form_options.html.erb +4 -4
  56. data/app/views/pager_tree/integrations/live_call_routing/twilio/v3/_form_options.html.erb +16 -16
  57. data/app/views/pager_tree/integrations/live_call_routing/twilio/v3_mailer/call_recording.html.erb +1 -0
  58. data/app/views/pager_tree/integrations/live_call_routing/twilio/v3_mailer/call_recording.text.erb +1 -0
  59. data/app/views/pager_tree/integrations/mattermost/outgoing_webhook/v3/_form_options.html.erb +1 -1
  60. data/app/views/pager_tree/integrations/outgoing_webhook/v3/_form_options.html.erb +8 -8
  61. data/app/views/pager_tree/integrations/server_guard24/v3/_form_options.html.erb +3 -3
  62. data/app/views/pager_tree/integrations/webhook/v3/_form_options.html.erb +5 -5
  63. data/config/locales/en.yml +6 -2
  64. data/config/routes.rb +1 -0
  65. data/lib/generators/integration/templates/model.rb.tt +1 -1
  66. data/lib/pager_tree/integrations/version.rb +1 -1
  67. metadata +7 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7dea02eb35788e7f79b0a01a4104202e970efec6747e0cae9c03a968750f21aa
4
- data.tar.gz: 38ccd8bc1d1b3241c5a3e59ee6d6696f845c7ee7323c566ef34bc192657f528b
3
+ metadata.gz: 1232e60d15e2dce895e6cc02e391cb1ec4f0230bcb3642c65f7d2eebaf499666
4
+ data.tar.gz: 2b1b7bd0787d7d001127b0391ce02a25bb258e74f86609b128e488e90c9efae4
5
5
  SHA512:
6
- metadata.gz: 023af4b2365f721b74240c24e6479a1404a94b0b017b2e9b6c211b222c5be94ec74636fc4251aa82026eafb579e9284bd0fd53eadb2c3a49184e488b9d41c209
7
- data.tar.gz: caa769fdde3885d1d7d751a895bec16bf30d25bd691a882a2c0bc86c2dbd8804b232e992f51b28f94c0cd34dc57805edcaacf68714ca293d07470e1713da1032
6
+ metadata.gz: 1d1efc213cc97634b6530653d5f06f14f79f80cf7df72c8f7130e890d968bfe74282cd95142dfc1fa4fbddd70c8634a538354049093f1b1617f9e6cd7f840df1
7
+ data.tar.gz: b2c8fea7246e9c3e00671b9fde25d0214fe254a28902056b4393e3623ee416113eb984e1b8d9f8b511c2e0b6f747513c1b3ed6c66f09ac416524c986005cb5ba
@@ -7,9 +7,20 @@ module PagerTree::Integrations
7
7
 
8
8
  @integration.adapter_source_log = @integration.logs.create!(level: :info, format: :json, message: params.to_unsafe_h) if @integration.try(:log_incoming_requests?)
9
9
  @integration.adapter_controller = self
10
+ @integration.adapter_incoming_request_params = params
10
11
  @integration.adapter_response_music
11
12
  end
12
13
 
14
+ def dropped
15
+ set_integration
16
+
17
+ @integration.adapter_source_log = @integration.logs.create!(level: :info, format: :json, message: params.to_unsafe_h) if @integration.try(:log_incoming_requests?)
18
+ @integration.adapter_controller = self
19
+ @integration.adapter_alert = @integration.alerts.find_by(thirdparty_id: params[:CallSid])
20
+ @integration.adapter_incoming_request_params = params
21
+ @integration.adapter_response_dropped
22
+ end
23
+
13
24
  def queue_status
14
25
  ::PagerTree::Integrations.deferred_request_class.constantize.perform_later_from_request!(request)
15
26
 
@@ -0,0 +1,17 @@
1
+ module PagerTree::Integrations
2
+ class LiveCallRouting::Twilio::V3Mailer < ::ApplicationMailer
3
+ # Subject can be set in your I18n file at config/locales/en.yml
4
+ # with the following lookup:
5
+ #
6
+ # en.live_call_routing.twilio.v3_mailer.call_recording.subject
7
+ #
8
+ def call_recording
9
+ @recording_url = params[:recording_url]
10
+ @alert = params[:alert]
11
+ @email = params[:email]
12
+ @from = params[:from]
13
+
14
+ mail(to: @email, subject: I18n.t("pager_tree.integrations.live_call_routing.twilio.v3_mailer.call_recording.subject", tiny_id: @alert.tiny_id, from: @from))
15
+ end
16
+ end
17
+ end
@@ -27,7 +27,7 @@ module PagerTree::Integrations
27
27
  Alert.new(
28
28
  title: _title,
29
29
  thirdparty_id: _thirdparty_id,
30
- dedup_keys: [_thirdparty_id],
30
+ dedup_keys: [],
31
31
  additional_data: _additional_datums
32
32
  )
33
33
  end
@@ -26,7 +26,7 @@ module PagerTree::Integrations
26
26
  title: _title,
27
27
  description: _description,
28
28
  thirdparty_id: _thirdparty_id,
29
- dedup_keys: [_thirdparty_id],
29
+ dedup_keys: [],
30
30
  additional_data: _additional_datums
31
31
  )
32
32
  end
@@ -44,7 +44,7 @@ module PagerTree::Integrations
44
44
  description: _description,
45
45
  urgency: _urgency,
46
46
  thirdparty_id: adapter_thirdparty_id,
47
- dedup_keys: [adapter_thirdparty_id],
47
+ dedup_keys: [],
48
48
  additional_data: _additional_datums
49
49
  )
50
50
  end
@@ -34,7 +34,7 @@ module PagerTree::Integrations
34
34
  title: _title,
35
35
  description: _description,
36
36
  thirdparty_id: _thirdparty_id,
37
- dedup_keys: [_thirdparty_id],
37
+ dedup_keys: [],
38
38
  additional_data: _additional_datums
39
39
  )
40
40
  end
@@ -37,7 +37,7 @@ module PagerTree::Integrations
37
37
  description: _description,
38
38
  urgency: _urgency,
39
39
  thirdparty_id: adapter_thirdparty_id,
40
- dedup_keys: [adapter_thirdparty_id],
40
+ dedup_keys: [],
41
41
  additional_data: _additional_datums
42
42
  )
43
43
  end
@@ -58,11 +58,10 @@ module PagerTree::Integrations
58
58
 
59
59
  def _urgency
60
60
  case adapter_incoming_request_params.dig("data", "essentials", "severity")
61
- when "Sev0" then "low"
62
- when "Sev1" then "low"
63
- when "Sev2" then "medium"
64
- when "Sev3" then "high"
65
- when "Sev4" then "critical"
61
+ when "Sev0", "Sev1" then "critical"
62
+ when "Sev2" then "high"
63
+ when "Sev3" then "medium"
64
+ when "Sev4" then "low"
66
65
  end
67
66
  end
68
67
 
@@ -63,7 +63,7 @@ module PagerTree::Integrations
63
63
  private
64
64
 
65
65
  def _alert
66
- @_alert ||= adapter_outgoing_event.item
66
+ @_alert ||= adapter_outgoing_event.alert
67
67
  end
68
68
 
69
69
  def _blocks
@@ -63,7 +63,7 @@ module PagerTree::Integrations
63
63
  private
64
64
 
65
65
  def _alert
66
- @_alert ||= adapter_outgoing_event.item
66
+ @_alert ||= adapter_outgoing_event.alert
67
67
  end
68
68
 
69
69
  def _blocks
@@ -63,7 +63,7 @@ module PagerTree::Integrations
63
63
  private
64
64
 
65
65
  def _alert
66
- @_alert ||= adapter_outgoing_event.item
66
+ @_alert ||= adapter_outgoing_event.alert
67
67
  end
68
68
 
69
69
  def _blocks
@@ -36,7 +36,7 @@ module PagerTree::Integrations
36
36
  title: _title,
37
37
  description: _description,
38
38
  thirdparty_id: adapter_thirdparty_id,
39
- dedup_keys: [adapter_thirdparty_id],
39
+ dedup_keys: [],
40
40
  additional_data: _additional_datums
41
41
  )
42
42
  end
@@ -36,7 +36,7 @@ module PagerTree::Integrations
36
36
  title: _title,
37
37
  description: _description,
38
38
  thirdparty_id: adapter_thirdparty_id,
39
- dedup_keys: [adapter_thirdparty_id, adapter_incoming_request_params.dig("AGGREG_KEY")].compact,
39
+ dedup_keys: [adapter_incoming_request_params.dig("AGGREG_KEY")].compact,
40
40
  additional_data: _additional_datums,
41
41
  tags: _tags
42
42
  )
@@ -37,7 +37,7 @@ module PagerTree::Integrations
37
37
  title: _title,
38
38
  description: _description,
39
39
  thirdparty_id: adapter_thirdparty_id,
40
- dedup_keys: [adapter_thirdparty_id],
40
+ dedup_keys: [],
41
41
  additional_data: _additional_datums,
42
42
  tags: _tags
43
43
  )
@@ -36,7 +36,7 @@ module PagerTree::Integrations
36
36
  title: _title,
37
37
  description: _description,
38
38
  thirdparty_id: adapter_thirdparty_id,
39
- dedup_keys: [adapter_thirdparty_id],
39
+ dedup_keys: [],
40
40
  additional_data: _additional_datums
41
41
  )
42
42
  end
@@ -75,7 +75,7 @@ module PagerTree::Integrations
75
75
  description: _description,
76
76
  urgency: _urgency,
77
77
  thirdparty_id: adapter_thirdparty_id,
78
- dedup_keys: [adapter_thirdparty_id],
78
+ dedup_keys: [],
79
79
  additional_data: _additional_datums
80
80
  )
81
81
  end
@@ -54,7 +54,7 @@ module PagerTree::Integrations
54
54
  description: _description,
55
55
  urgency: _urgency,
56
56
  thirdparty_id: adapter_thirdparty_id,
57
- dedup_keys: [adapter_thirdparty_id],
57
+ dedup_keys: [],
58
58
  additional_data: _additional_datums
59
59
  )
60
60
  end
@@ -55,7 +55,7 @@ module PagerTree::Integrations
55
55
  description: _description,
56
56
  urgency: _urgency,
57
57
  thirdparty_id: adapter_thirdparty_id,
58
- dedup_keys: [adapter_thirdparty_id],
58
+ dedup_keys: [],
59
59
  additional_data: _additional_datums
60
60
  )
61
61
  end
@@ -38,7 +38,7 @@ module PagerTree::Integrations
38
38
  title: _title,
39
39
  description: _description,
40
40
  thirdparty_id: adapter_thirdparty_id,
41
- dedup_keys: [adapter_thirdparty_id],
41
+ dedup_keys: [],
42
42
  additional_data: _additional_datums
43
43
  )
44
44
  end
@@ -38,7 +38,7 @@ module PagerTree::Integrations
38
38
  title: _title,
39
39
  description: _description,
40
40
  thirdparty_id: adapter_thirdparty_id,
41
- dedup_keys: [adapter_thirdparty_id],
41
+ dedup_keys: [],
42
42
  additional_data: _additional_datums,
43
43
  tags: _tags
44
44
  )
@@ -46,7 +46,7 @@ module PagerTree::Integrations
46
46
  Alert.new(
47
47
  title: _title,
48
48
  thirdparty_id: adapter_thirdparty_id,
49
- dedup_keys: [adapter_thirdparty_id],
49
+ dedup_keys: [],
50
50
  additional_data: _additional_datums,
51
51
  tags: _tags
52
52
  )
@@ -38,7 +38,7 @@ module PagerTree::Integrations
38
38
  Alert.new(
39
39
  title: _title,
40
40
  thirdparty_id: adapter_thirdparty_id,
41
- dedup_keys: [adapter_thirdparty_id],
41
+ dedup_keys: [],
42
42
  additional_data: _additional_datums
43
43
  )
44
44
  end
@@ -48,7 +48,7 @@ module PagerTree::Integrations
48
48
  true
49
49
  end
50
50
 
51
- # Returns :create, :acknowledge, :resolve, or :other
51
+ # Returns :create, :resolve, or :other
52
52
  def adapter_action
53
53
  :other
54
54
  end
@@ -58,6 +58,10 @@ module PagerTree::Integrations
58
58
 
59
59
  def adapter_process_other
60
60
  end
61
+
62
+ def adapter_will_route_alert?
63
+ false
64
+ end
61
65
  # END basic incoming functions
62
66
 
63
67
  # START basic outgoing functions
@@ -102,7 +106,7 @@ module PagerTree::Integrations
102
106
  # END basic show functions
103
107
 
104
108
  def adapter_response_rate_limit
105
- adapter_controller&.head(:not_found)
109
+ adapter_controller&.head(:too_many_requests)
106
110
  end
107
111
 
108
112
  def adapter_response_disabled
@@ -37,7 +37,7 @@ module PagerTree::Integrations
37
37
  title: _title,
38
38
  description: _description,
39
39
  thirdparty_id: adapter_thirdparty_id,
40
- dedup_keys: [adapter_thirdparty_id],
40
+ dedup_keys: [],
41
41
  additional_data: _additional_datums
42
42
  )
43
43
  end
@@ -30,7 +30,7 @@ module PagerTree::Integrations
30
30
  Alert.new(
31
31
  title: _title,
32
32
  thirdparty_id: adapter_thirdparty_id,
33
- dedup_keys: [adapter_thirdparty_id],
33
+ dedup_keys: [],
34
34
  additional_data: _additional_datums
35
35
  )
36
36
  end
@@ -32,7 +32,7 @@ module PagerTree::Integrations
32
32
  description: _description,
33
33
  urgency: _urgency,
34
34
  thirdparty_id: adapter_thirdparty_id,
35
- dedup_keys: [adapter_thirdparty_id],
35
+ dedup_keys: [],
36
36
  additional_data: _additional_datums
37
37
  )
38
38
  end
@@ -38,20 +38,24 @@ module PagerTree::Integrations
38
38
  voice: "man"
39
39
  }
40
40
 
41
- TWILIO_LIVECALL_CONNECT_NOW = "https://app.pagertree.com/assets/sounds/you-are-now-being-connected.mp3"
42
- TWILIO_LIVECALL_MUSIC = "http://com.twilio.sounds.music.s3.amazonaws.com/oldDog_-_endless_goodbye_%28instr.%29.mp3"
43
- TWILIO_LIVECALL_PLEASE_WAIT = "https://app.pagertree.com/assets/sounds/please-wait.mp3"
44
-
45
41
  def option_connect_now_media_url
46
- option_connect_now_media&.url || TWILIO_LIVECALL_CONNECT_NOW
42
+ option_connect_now_media.present? ? option_connect_now_media.url : URI.join(Rails.application.routes.url_helpers.root_url, "audios/you-are-now-being-connected.mp3").to_s
47
43
  end
48
44
 
49
45
  def option_music_media_url
50
- option_music_media&.url || TWILIO_LIVECALL_MUSIC
46
+ option_music_media.present? ? option_music_media.url : "http://com.twilio.sounds.music.s3.amazonaws.com/oldDog_-_endless_goodbye_%28instr.%29.mp3"
51
47
  end
52
48
 
53
49
  def option_please_wait_media_url
54
- option_please_wait_media&.url || TWILIO_LIVECALL_PLEASE_WAIT
50
+ option_please_wait_media.present? ? option_please_wait_media.url : URI.join(Rails.application.routes.url_helpers.root_url, "audios/please-wait.mp3").to_s
51
+ end
52
+
53
+ def option_no_answer_media_url
54
+ option_no_answer_media.present? ? option_no_answer_media.url : URI.join(Rails.application.routes.url_helpers.root_url, "audios/no-answer.mp3").to_s
55
+ end
56
+
57
+ def option_no_answer_thank_you_media_url
58
+ option_no_answer_thank_you_media.present? ? option_no_answer_thank_you_media.url : URI.join(Rails.application.routes.url_helpers.root_url, "audios/thanks-for-message.mp3").to_s
55
59
  end
56
60
 
57
61
  def option_record_emails=(x)
@@ -90,10 +94,18 @@ module PagerTree::Integrations
90
94
  true
91
95
  end
92
96
 
97
+ def adapter_outgoing_interest?(event_name)
98
+ ["alert_acknowledged", "alert_dropped"].include?(event_name) && adapter_alert.source_id == id
99
+ end
100
+
93
101
  def adapter_incoming_can_defer?
94
102
  false
95
103
  end
96
104
 
105
+ def adapter_will_route_alert?
106
+ true
107
+ end
108
+
97
109
  def adapter_action
98
110
  :create
99
111
  end
@@ -108,7 +120,7 @@ module PagerTree::Integrations
108
120
  urgency: urgency,
109
121
 
110
122
  thirdparty_id: _thirdparty_id,
111
- dedup_keys: [_thirdparty_id],
123
+ dedup_keys: [],
112
124
  additional_data: _additional_datums
113
125
  )
114
126
  end
@@ -128,13 +140,19 @@ module PagerTree::Integrations
128
140
  end
129
141
 
130
142
  if selected_team
131
- adapter_alert.logs.create!(message: "Caller selected team '#{selected_team.name}'. Playing please wait media.")
132
- _twiml.play(url: option_please_wait_media&.url || TWILIO_LIVECALL_PLEASE_WAIT)
143
+ adapter_alert.logs.create!(message: "Caller selected team '#{selected_team.name}'.") if _teams_size > 1 || option_force_input
144
+
145
+ adapter_alert.logs.create!(message: "Play please wait media to caller.")
146
+ _twiml.play(url: option_please_wait_media_url)
133
147
  friendly_name = adapter_alert.id
134
148
 
135
149
  # create the queue and save it off
136
150
  queue = _client.queues.create(friendly_name: friendly_name)
137
151
  adapter_alert.meta["live_call_queue_sid"] = queue.sid
152
+
153
+ adapter_alert.destination_teams = [selected_team]
154
+
155
+ # save the alert
138
156
  adapter_alert.save!
139
157
 
140
158
  _twiml.enqueue(
@@ -144,6 +162,11 @@ module PagerTree::Integrations
144
162
  wait_url: PagerTree::Integrations::Engine.routes.url_helpers.music_live_call_routing_twilio_v3_path(id, thirdparty_id: _thirdparty_id),
145
163
  wait_url_method: "GET"
146
164
  )
165
+ adapter_alert.logs.create!(message: "Enqueue caller in Twilio queue '#{friendly_name}'.")
166
+
167
+ # kick off the alert workflow
168
+ adapter_alert.route_later
169
+ adapter_alert.logs.create!(message: "Successfully enqueued alert team workflow.")
147
170
  else
148
171
  adapter_alert.meta["live_call_repeat_count"] ||= 0
149
172
  adapter_alert.meta["live_call_repeat_count"] += 1
@@ -159,6 +182,7 @@ module PagerTree::Integrations
159
182
  end
160
183
  else
161
184
  adapter_alert.logs.create!(message: "Caller input bad input (too many times). Hangup.")
185
+ adapter_alert.resolve!(self)
162
186
  _twiml.say(message: "Too much invalid input. Goodbye.", **SPEAK_OPTIONS)
163
187
  _twiml.hangup
164
188
  end
@@ -193,15 +217,11 @@ module PagerTree::Integrations
193
217
  adapter_controller&.render(xml: _twiml.to_xml)
194
218
  end
195
219
 
196
- def response_dropped
220
+ def adapter_response_dropped
197
221
  recording_url = adapter_incoming_request_params.dig("RecordingUrl")
198
222
 
199
223
  if recording_url
200
- if option_no_answer_thank_you_media.present?
201
- _twiml.play(url: option_no_answer_thank_you_media.url)
202
- else
203
- _twiml.say(message: "Thank you for your message. Goodbye.")
204
- end
224
+ _twiml.play(url: option_no_answer_thank_you_media_url)
205
225
  _twiml.hangup
206
226
 
207
227
  adapter_alert.additional_data.push(AdditionalDatum.new(format: "link", label: "Voicemail", value: recording_url).to_h)
@@ -209,18 +229,18 @@ module PagerTree::Integrations
209
229
 
210
230
  adapter_alert.logs.create!(message: "Caller left a <a href='#{recording_url}' target='_blank'>voicemail</a>.")
211
231
 
212
- adapter_record_emails.each do |email|
213
- TwilioLiveCallRouting::V3Mailer.with(email: email, alert: alert).call_recording.deliver_later
232
+ option_record_emails.each do |email|
233
+ LiveCallRouting::Twilio::V3Mailer.with(email: email, alert: adapter_alert, from: adapter_incoming_request_params.dig("From"), recording_url: recording_url).call_recording.deliver_later
214
234
  end
215
- elsif record
235
+ elsif option_record
216
236
  _twiml.play(url: option_no_answer_media_url)
217
237
  _twiml.record(max_length: 60)
218
238
  else
219
- _twiml.say(message: "No one is available to answer this call. Goodbye.")
239
+ _twiml.say(message: "No one is available to answer this call. Goodbye.", **SPEAK_OPTIONS)
220
240
  _twiml.hangup
221
241
  end
222
242
 
223
- controller.render(xml: _twiml.to_xml)
243
+ adapter_controller.render(xml: _twiml.to_xml)
224
244
  end
225
245
 
226
246
  def adapter_process_queue_status_deferred
@@ -229,18 +249,20 @@ module PagerTree::Integrations
229
249
 
230
250
  if queue_result == "hangup"
231
251
  self.adapter_alert = alerts.find_by(thirdparty_id: _thirdparty_id)
252
+ adapter_alert.logs.create!(message: "Caller hungup while waiting in queue.")
253
+ adapter_alert.resolve!(self)
232
254
  queue_destroy
233
255
  end
234
256
 
235
257
  adapter_source_log&.save!
236
258
  end
237
259
 
238
- def perform_outgoing(**params)
239
- event = params[:event]
240
- if event == "alert.acknowledged"
241
- on_acknowledge
242
- elsif event == "alert.dropped"
243
- on_drop
260
+ def adapter_process_outgoing
261
+ event = adapter_outgoing_event.event_name.to_s
262
+ if event == "alert_acknowledged"
263
+ _on_acknowledge
264
+ elsif event == "alert_dropped"
265
+ _on_drop
244
266
  end
245
267
  end
246
268
 
@@ -269,7 +291,7 @@ module PagerTree::Integrations
269
291
  end
270
292
 
271
293
  def _call
272
- @_call ||= _client.calls(call_sid).fetch
294
+ @_call ||= _client.calls(adapter_alert.thirdparty_id).fetch
273
295
  end
274
296
 
275
297
  def _twiml
@@ -299,23 +321,44 @@ module PagerTree::Integrations
299
321
  nil
300
322
  end
301
323
 
302
- def on_acknowledge
324
+ def _on_acknowledge
303
325
  # log that we are going to transfer
304
- adapter_alert.logs.create!(message: "Attempting to transfer the call...")
326
+ adapter_alert.logs.create!(message: "The alert was acknowledged. Attempting to transfer the call...")
305
327
 
306
328
  # try to transfer the caller
307
- number = "+19402733696"
308
- _twiml.play(url: option_connect_now_media_url)
309
- _twiml.pause(length: 1)
310
- _twiml.dial(number: number, caller_id: _call.to, answer_on_bridge: true)
311
- _call.update(twiml: _twiml.to_xml)
312
-
313
- # log if we successfully transfered or failed
314
- adapter_alert.logs.create!(message: "Tranferring the call succeeded.")
329
+ account_user = adapter_outgoing_event.account_user
330
+ number = account_user.user.phone&.phone
331
+
332
+ adapter_alert.logs.create!(message: "Attempting to transfer the call to #{account_user.user.name} at #{number}...")
333
+
334
+ if number.present?
335
+ _twiml.play(url: option_connect_now_media_url)
336
+ _twiml.pause(length: 1)
337
+ _twiml.dial(number: number, caller_id: _call.to, answer_on_bridge: true)
338
+ _call.update(twiml: _twiml.to_xml)
339
+ # log if we successfully transfered or failed
340
+ adapter_alert.logs.create!(message: "Tranferring the call succeeded.")
341
+ else
342
+ _twiml.say(message: "Someone has acknowledged this call, but they do not have a phone number on file. Goodbye.")
343
+ _twiml.hangup
344
+ _call.update(twiml: _twiml.to_xml)
345
+ adapter_alert.logs.create!(message: "Tranferring the call failed. #{account_user.user.name} has no phone number on file.")
346
+ end
347
+ rescue ::Twilio::REST::RestError => e
348
+ # 21220 - Unable to update record. Call is not in-progress. Cannot redirect.
349
+ if e.code != 21220
350
+ adapter_alert.logs.create!(message: "Tranferring the call failed. #{e.message}")
351
+ end
315
352
  end
316
353
 
317
- def on_drop
318
- _call.update(url: PagerTree::Integrations::Engine.routes.url_helpers.dropped_twilio_live_call_routing_v3_url(id, thirdparty_id: thirdparty_id))
354
+ def _on_drop
355
+ # log that we are going to transer
356
+ adapter_alert.logs.create!(message: "The alert was dropped. Attempting to transfer the call...")
357
+ _call.update(url: PagerTree::Integrations::Engine.routes.url_helpers.dropped_live_call_routing_twilio_v3_url(id, thirdparty_id: adapter_alert.thirdparty_id))
358
+ music_live_call_routing_twilio_v3_path
359
+ adapter_alert.logs.create!(message: "Tranferring the call succeeded.")
360
+ rescue ::Twilio::REST::RestError => e
361
+ adapter_alert.logs.create!(message: "Tranferring the call failed. #{e.message}")
319
362
  end
320
363
 
321
364
  def queue_destroy
@@ -27,8 +27,6 @@ module PagerTree::Integrations
27
27
  case alert_status
28
28
  when "active", "test"
29
29
  :create
30
- # when "ack"
31
- # :acknowledge
32
30
  when "clear"
33
31
  :resolve
34
32
  else
@@ -42,7 +40,7 @@ module PagerTree::Integrations
42
40
  description: _description,
43
41
  urgency: _urgency,
44
42
  thirdparty_id: adapter_thirdparty_id,
45
- dedup_keys: [adapter_thirdparty_id],
43
+ dedup_keys: [],
46
44
  additional_data: _additional_datums
47
45
  )
48
46
  end
@@ -38,7 +38,7 @@ module PagerTree::Integrations
38
38
  title: _title,
39
39
  urgency: _urgency,
40
40
  thirdparty_id: adapter_thirdparty_id,
41
- dedup_keys: [adapter_thirdparty_id],
41
+ dedup_keys: [],
42
42
  additional_data: _additional_datums
43
43
  )
44
44
  end
@@ -28,8 +28,6 @@ module PagerTree::Integrations
28
28
 
29
29
  if event_type == "INCIDENT_OPEN" || (event_type == "INCIDENT" && current_state == "open")
30
30
  :create
31
- # elsif event_type == "INCIDENT_ACKNOWLEDGED" || (event_type == "INCIDENT" && current_state == "acknowledged")
32
- # :acknowledge
33
31
  elsif event_type == "INCIDENT_RESOLVED" || (event_type == "INCIDENT" && current_state == "closed")
34
32
  :resolve
35
33
  else
@@ -42,7 +40,7 @@ module PagerTree::Integrations
42
40
  title: _title,
43
41
  description: _description,
44
42
  thirdparty_id: adapter_thirdparty_id,
45
- dedup_keys: [adapter_thirdparty_id],
43
+ dedup_keys: [],
46
44
  additional_data: _additional_datums
47
45
  )
48
46
  end
@@ -8,6 +8,10 @@ module PagerTree::Integrations
8
8
  attr_accessor :item
9
9
  attr_accessor :changes
10
10
  attr_accessor :outgoing_rules_data
11
+ attr_accessor :alert
12
+ attr_accessor :handoff
13
+ attr_accessor :team
14
+ attr_accessor :account_user
11
15
 
12
16
  define_model_callbacks :initialize
13
17
 
@@ -22,6 +26,11 @@ module PagerTree::Integrations
22
26
  self.item ||= nil
23
27
  self.changes ||= nil
24
28
  self.outgoing_rules_data ||= {}
29
+
30
+ self.alert ||= nil
31
+ self.handoff ||= nil
32
+ self.team ||= nil
33
+ self.account_user ||= nil
25
34
  end
26
35
  end
27
36
  end
@@ -71,7 +71,7 @@ module PagerTree::Integrations
71
71
  if self.option_template.present?
72
72
  begin
73
73
  body = JSON.parse(handlebars(self.option_template, {
74
- alert: adapter_outgoing_event.item.try(:v3_format) || adapter_outgoing_event.item,
74
+ alert: adapter_outgoing_event.alert.try(:v3_format) || adapter_outgoing_event.alert,
75
75
  event: {
76
76
  type: event_type
77
77
  }
@@ -84,7 +84,7 @@ module PagerTree::Integrations
84
84
  end
85
85
 
86
86
  body ||= {
87
- data: adapter_outgoing_event.item.try(:v3_format) || adapter_outgoing_event.item,
87
+ data: adapter_outgoing_event.alert.try(:v3_format) || adapter_outgoing_event.alert,
88
88
  type: event_type
89
89
  }
90
90
 
@@ -40,7 +40,7 @@ module PagerTree::Integrations
40
40
  title: _title,
41
41
  description: _description,
42
42
  thirdparty_id: adapter_thirdparty_id,
43
- dedup_keys: [adapter_thirdparty_id],
43
+ dedup_keys: [],
44
44
  additional_data: _additional_datums,
45
45
  tags: _tags
46
46
  )