Class: Telnyx::Resources::Webhooks

Inherits:
Object
  • Object
show all
Includes:
Lib::WebhookVerification
Defined in:
lib/telnyx/lib/webhooks_ed25519.rb,
lib/telnyx/resources/webhooks.rb

Overview

Extends the generated Webhooks class with ED25519 signature verification.

This reopens the Webhooks class to include the WebhookVerification module, which adds ED25519 signature verification matching Python, Node, Go, and Java SDKs.

Usage:

require "telnyx"
# ED25519 verification is now loaded by default — no extra require needed

client = Telnyx::Client.new(
  api_key: ENV["TELNYX_API_KEY"],
  public_key: ENV["TELNYX_PUBLIC_KEY"]  # Base64 from Mission Control
)

# Verify signature only (raises WebhookVerificationError on failure)
client.webhooks.verify!(payload, headers)

# Verify and parse (ED25519 verification, then parse)
event = client.webhooks.unwrap(payload, headers: headers)

Constant Summary

Constants included from Lib::WebhookVerification

Lib::WebhookVerification::SIGNATURE_HEADER, Lib::WebhookVerification::TIMESTAMP_HEADER, Lib::WebhookVerification::TIMESTAMP_TOLERANCE_SECONDS

Instance Method Summary collapse

Methods included from Lib::WebhookVerification

#verify!

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: nil) ⇒ Telnyx::Models::UnwrapWebhookEvent

Override unwrap to use ED25519 verification instead of StandardWebhooks.

Parameters:

  • payload (String)

    The raw webhook payload as a string

  • headers (Hash{String=>String})

    The raw HTTP headers

  • key (String, nil) (defaults to: nil)

    Optional public key override (base64-encoded ED25519)

Returns:

Raises:



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

  ::StandardWebhooks::Webhook.new(key).verify(payload, headers)

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