Class: Telnyx::Resources::Webhooks
- Inherits:
-
Object
- Object
- Telnyx::Resources::Webhooks
- 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
-
#initialize(client:) ⇒ Webhooks
constructor
private
A new instance of Webhooks.
- #unsafe_unwrap(payload) ⇒ Telnyx::Models::CallAIGatherEndedWebhookEvent, ...
-
#unwrap(payload, headers:, key: nil) ⇒ Telnyx::Models::UnwrapWebhookEvent
Override unwrap to use ED25519 verification instead of StandardWebhooks.
Methods included from Lib::WebhookVerification
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.
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, ...
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.
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 |