Class: Email::V3

Inherits:
Integration
  • Object
show all
Extended by:
PagerTree::Integrations::Env
Defined in:
app/models/pager_tree/integrations/email/v3.rb

Constant Summary collapse

OPTIONS =
[
  {key: :allow_spam, type: :boolean, default: false},
  {key: :dedup_threads, type: :boolean, default: true},
  {key: :sanitize_level, type: :string, default: "relaxed"},
  {key: :custom_definition, type: :string, default: nil},
  {key: :custom_definition_enabled, type: :boolean, default: false}
]
SANITIZE_LEVELS =
["basic", "default", "relaxed", "relaxed_2", "restricted"]

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.custom_webhook_v3_service_urlObject



25
26
27
28
# File 'app/models/pager_tree/integrations/email/v3.rb', line 25

def self.custom_webhook_v3_service_url
  ::PagerTree::Integrations.integration_custom_webhook_v3_service_url.presence ||
    find_value_by_name("integration_custom_webhook_v3", "service_url")
end

Instance Method Details

#adapter_actionObject



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'app/models/pager_tree/integrations/email/v3.rb', line 86

def adapter_action
  if custom_definition?
    case custom_response_result.dig("type")&.downcase
    when "create"
      :create
    when "acknowledge"
      :acknowledge
    when "resolve"
      :resolve
    else
      :other
    end
  else
    :create
  end
end

#adapter_process_createObject



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'app/models/pager_tree/integrations/email/v3.rb', line 103

def adapter_process_create
  if custom_definition?
    Alert.new(
      title: _title,
      description: _description,
      urgency: _urgency,
      thirdparty_id: _thirdparty_id,
      dedup_keys: _dedup_keys,
      incident: _incident,
      incident_severity: _incident_severity,
      incident_message: _incident_message,
      tags: _tags,
      meta: _meta,
      additional_data: _additional_datums,
      attachments: _attachments
    )
  else
    Alert.new(
      title: _title,
      description: _description,
      urgency: urgency,
      thirdparty_id: _thirdparty_id,
      dedup_keys: _dedup_keys,
      additional_data: _additional_datums,
      attachments: _attachments
    )
  end
end

#adapter_should_block?Boolean

Returns:

  • (Boolean)


66
67
68
69
70
71
72
73
74
75
76
# File 'app/models/pager_tree/integrations/email/v3.rb', line 66

def adapter_should_block?
  return false if option_allow_spam == true

  ses_spam_verdict = _get_header("X-SES-Spam-Verdict")&.value

  if ses_spam_verdict.present?
    return ses_spam_verdict != "PASS"
  end

  false
end

#adapter_supports_incoming?Boolean

Returns:

  • (Boolean)


78
79
80
# File 'app/models/pager_tree/integrations/email/v3.rb', line 78

def adapter_supports_incoming?
  true
end

#adapter_thirdparty_idObject



82
83
84
# File 'app/models/pager_tree/integrations/email/v3.rb', line 82

def adapter_thirdparty_id
  _thirdparty_id
end

#custom_definition?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'app/models/pager_tree/integrations/email/v3.rb', line 62

def custom_definition?
  option_custom_definition_enabled && option_custom_definition.present?
end

#endpointObject

SPECIAL: override integration endpoint



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'app/models/pager_tree/integrations/email/v3.rb', line 38

def endpoint
  domain = ::PagerTree::Integrations.integration_email_v3_domain
  inbox = ::PagerTree::Integrations.integration_email_v3_inbox
  postfix = ""
  postfix = "_stg" if Rails.env.staging?
  postfix = "_tst" if Rails.env.test?
  postfix = "_dev" if Rails.env.development?

  if Rails.env.production?
    if created_at&.after?(DateTime.parse("2023-09-01"))
      # new emails
      # int_abc123@domain.com
      "#{(v == 3) ? prefix_id : id}@#{domain}"
    else
      # legacy emails
      # a+int_abc123@domain.com
      "#{inbox}#{postfix}+#{(v == 3) ? prefix_id : id}@#{domain}"
    end
  else
    # staging, test, development
    "#{inbox}#{postfix}+#{(v == 3) ? prefix_id : id}@#{domain}"
  end
end