Top Level Namespace

Defined Under Namespace

Modules: Attio Classes: OAuthApp

Instance Method Summary collapse

Instance Method Details

#process_list_entry_created(data) ⇒ Object

Process list_entry.created webhook events

Parameters:

  • data (Hash)

    Webhook event data



153
154
155
156
157
158
159
160
# File 'examples/webhook_server.rb', line 153

def process_list_entry_created(data)
  puts "Record added to list: #{data["list"]["name"]}"

  # Example: Trigger marketing automation
  if /leads|prospects/i.match?(data["list"]["name"])
    puts "  Would trigger marketing automation workflow"
  end
end

#process_note_created(data) ⇒ Object

Process note.created webhook events

Parameters:

  • data (Hash)

    Webhook event data



164
165
166
167
168
169
170
171
# File 'examples/webhook_server.rb', line 164

def process_note_created(data)
  puts "New note created on #{data["parent_object"]}"

  # Example: Notify team members
  if /urgent|important|asap/i.match?(data["content"])
    puts "  Would notify team members of urgent note"
  end
end

#process_record_created(data) ⇒ Object

Webhook event processors Process record.created webhook events

Parameters:

  • data (Hash)

    Webhook event data



115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'examples/webhook_server.rb', line 115

def process_record_created(data)
  puts "New #{data["object"]} created: #{data["record"]["id"]}"

  # Example: Send welcome email for new people
  if data["object"] == "people" && data["record"]["email_addresses"]
    puts "  Would send welcome email to: #{data["record"]["email_addresses"]}"
  end

  # Example: Enrich company data
  if data["object"] == "companies" && data["record"]["domains"]
    puts "  Would enrich company data for: #{data["record"]["domains"]}"
  end
end

#process_record_deleted(data) ⇒ Object

Process record.deleted webhook events

Parameters:

  • data (Hash)

    Webhook event data



144
145
146
147
148
149
# File 'examples/webhook_server.rb', line 144

def process_record_deleted(data)
  puts "#{data["object"]} deleted: #{data["record_id"]}"

  # Example: Clean up related data
  puts "  Would clean up related data in external systems"
end

#process_record_updated(data) ⇒ Object

Process record.updated webhook events

Parameters:

  • data (Hash)

    Webhook event data



131
132
133
134
135
136
137
138
139
140
# File 'examples/webhook_server.rb', line 131

def process_record_updated(data)
  puts "#{data["object"]} updated: #{data["record"]["id"]}"

  # Example: Sync changes to CRM
  changed_fields = data["changes"]&.keys || []
  if changed_fields.any?
    puts "  Changed fields: #{changed_fields.join(", ")}"
    puts "  Would sync to external CRM"
  end
end

#verify_webhook_signature(payload_body, signature_header) ⇒ Object

Webhook signature verification



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'examples/webhook_server.rb', line 22

def verify_webhook_signature(payload_body, signature_header)
  return false unless signature_header

  # Extract timestamp and signatures
  elements = signature_header.split(" ")
  timestamp = nil
  signatures = []

  elements.each do |element|
    key, value = element.split("=", 2)
    case key
    when "t"
      timestamp = value
    when "v1"
      signatures << value
    end
  end

  return false unless timestamp

  # Verify timestamp is recent (within 5 minutes)
  current_time = Time.now.to_i
  if (current_time - timestamp.to_i).abs > 300
    return false
  end

  # Compute expected signature
  signed_payload = "#{timestamp}.#{payload_body}"
  expected_signature = OpenSSL::HMAC.hexdigest(
    "SHA256",
    ENV["ATTIO_WEBHOOK_SECRET"] || "test_secret",
    signed_payload
  )

  # Check if computed signature matches any of the signatures
  signatures.any? { |sig| Rack::Utils.secure_compare(expected_signature, sig) }
end