Class: Telnyx::Resources::Webhooks

Inherits:
Object
  • Object
show all
Defined in:
lib/telnyx/resources/webhooks.rb,
sig/telnyx/resources/webhooks.rbs

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Webhooks

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Webhooks.

Parameters:



35
36
37
# File 'lib/telnyx/resources/webhooks.rb', line 35

def initialize(client:)
  @client = client
end

Instance Method Details

#unsafe_unwrap(payload) ⇒ Telnyx::Models::CallAIGatherEndedWebhookEvent, ...

Parameters:

  • payload (String)

    The raw webhook payload as a string

Returns:



9
10
11
12
# File 'lib/telnyx/resources/webhooks.rb', line 9

def unsafe_unwrap(payload)
  parsed = JSON.parse(payload, symbolize_names: true)
  Telnyx::Internal::Type::Converter.coerce(Telnyx::Models::UnsafeUnwrapWebhookEvent, parsed)
end

#unwrap(payload, headers:, key: @client.public_key) ⇒ Telnyx::Models::CallAIGatherEndedWebhookEvent, ...

Parameters:

  • payload (String)

    The raw webhook payload as a string

  • headers (Hash{String=>String})

    The raw HTTP headers that came with the payload

  • key (String, nil) (defaults to: @client.public_key)

    The webhook signing key

Returns:



21
22
23
24
25
26
27
28
29
30
# File 'lib/telnyx/resources/webhooks.rb', line 21

def unwrap(payload, headers:, key: @client.public_key)
  if key.nil?
    raise ArgumentError.new("Cannot verify a webhook without a key on either the client's public_key or passed in as an argument")
  end

  Telnyx::Lib::WebhookVerification.verify_signature!(payload, headers, key)

  parsed = JSON.parse(payload, symbolize_names: true)
  Telnyx::Internal::Type::Converter.coerce(Telnyx::Models::UnwrapWebhookEvent, parsed)
end