跳到正文
cccskills
免费在 GitHub 公开

telnyx-fax-ruby

Send and receive faxes programmatically. Manage fax applications and media. This skill provides Ruby SDK examples.

中文简介正在准备中。当前显示原文说明。

查看安装方法

包含的文件(1)

  • SKILL.md19.4 KB

SKILL.md(原文)

安装前可以查看交给 AI 代理的指令内容。

<!-- Auto-generated from Telnyx OpenAPI specs. Do not edit. -->

Telnyx Fax - Ruby

Installation

gem install telnyx

Setup

require "telnyx"

client = Telnyx::Client.new(
  api_key: ENV["TELNYX_API_KEY"], # This is the default and can be omitted
  public_key: ENV["TELNYX_PUBLIC_KEY"], # Required for client.webhooks.unwrap (webhook verification)
)

All examples below assume client is already initialized as shown above.

Error Handling

All API calls can fail with network errors, rate limits (429), validation errors (422), or authentication errors (401). Always handle errors in production code:

begin
  result = client.messages.send_(to: "+13125550001", from: "+13125550002", text: "Hello")
rescue Telnyx::Errors::APIConnectionError
  puts "Network error — check connectivity and retry"
  raise
rescue Telnyx::Errors::RateLimitError
  # 429: rate limited — wait, then retry the request (bounded exponential backoff)
  sleep(1) # Check Retry-After header for actual delay
  # ...retry the call here (give up after a few attempts); otherwise re-raise:
  raise
rescue Telnyx::Errors::APIStatusError => e
  puts "API error #{e.status}: #{e.message}"
  if e.status == 422
    puts "Validation error — check required fields and formats"
  end
  raise # A failed request must never look like success to the caller
end

Common error codes: 401 invalid API key, 403 insufficient permissions, 404 resource not found, 422 validation error (check field formats), 429 rate limited (retry with exponential backoff).

Important Notes

  • Phone numbers must be in E.164 format (e.g., +13125550001). Include the + prefix and country code. No spaces, dashes, or parentheses.
  • Pagination: Use .auto_paging_each for automatic iteration: page.auto_paging_each { |item| puts item.id }.

List all Fax Applications

This endpoint returns a list of your Fax Applications inside the 'data' attribute of the response. You can adjust which applications are listed by using filters. Fax Applications are used to configure how you send and receive faxes using the Programmable Fax API with Telnyx.

GET /fax_applications

page = client.fax_applications.list

puts(page)

Returns: active (boolean), anchorsite_override (enum: Latency, Chicago, IL, Ashburn, VA, San Jose, CA, Sydney, Australia, Amsterdam, Netherlands, London, UK, Toronto, Canada, Vancouver, Canada, Frankfurt, Germany), application_name (string), created_at (string), id (string), inbound (object), outbound (object), record_type (string), tags (array[string]), updated_at (string), webhook_event_failover_url (uri), webhook_event_url (uri), webhook_timeout_secs (integer | null)

Creates a Fax Application

Creates a new Fax Application based on the parameters sent in the request. The application name and webhook URL are required. Once created, you can assign phone numbers to your application using the /phone_numbers endpoint.

POST /fax_applications — Required: application_name, webhook_event_url

Optional: active (boolean), anchorsite_override (enum: Latency, Chicago, IL, Ashburn, VA, San Jose, CA, Sydney, Australia, Amsterdam, Netherlands, London, UK, Toronto, Canada, Vancouver, Canada, Frankfurt, Germany), inbound (object), outbound (object), tags (array[string]), webhook_event_failover_url (uri), webhook_timeout_secs (integer | null)

fax_application = client.fax_applications.create(application_name: "fax-router", webhook_event_url: "https://example.com")

puts(fax_application)

Returns: active (boolean), anchorsite_override (enum: Latency, Chicago, IL, Ashburn, VA, San Jose, CA, Sydney, Australia, Amsterdam, Netherlands, London, UK, Toronto, Canada, Vancouver, Canada, Frankfurt, Germany), application_name (string), created_at (string), id (string), inbound (object), outbound (object), record_type (string), tags (array[string]), updated_at (string), webhook_event_failover_url (uri), webhook_event_url (uri), webhook_timeout_secs (integer | null)

Retrieve a Fax Application

Return the details of an existing Fax Application inside the 'data' attribute of the response.

GET /fax_applications/{id}

fax_application = client.fax_applications.retrieve("1293384261075731499")

puts(fax_application)

Returns: active (boolean), anchorsite_override (enum: Latency, Chicago, IL, Ashburn, VA, San Jose, CA, Sydney, Australia, Amsterdam, Netherlands, London, UK, Toronto, Canada, Vancouver, Canada, Frankfurt, Germany), application_name (string), created_at (string), id (string), inbound (object), outbound (object), record_type (string), tags (array[string]), updated_at (string), webhook_event_failover_url (uri), webhook_event_url (uri), webhook_timeout_secs (integer | null)

Update a Fax Application

Updates settings of an existing Fax Application based on the parameters of the request.

PATCH /fax_applications/{id} — Required: application_name, webhook_event_url

Optional: active (boolean), anchorsite_override (enum: Latency, Chicago, IL, Ashburn, VA, San Jose, CA, Sydney, Australia, Amsterdam, Netherlands, London, UK, Toronto, Canada, Vancouver, Canada, Frankfurt, Germany), fax_email_recipient (string | null), inbound (object), outbound (object), tags (array[string]), webhook_event_failover_url (uri), webhook_timeout_secs (integer | null)

fax_application = client.fax_applications.update(
  "1293384261075731499",
  application_name: "fax-router",
  webhook_event_url: "https://example.com"
)

puts(fax_application)

Returns: active (boolean), anchorsite_override (enum: Latency, Chicago, IL, Ashburn, VA, San Jose, CA, Sydney, Australia, Amsterdam, Netherlands, London, UK, Toronto, Canada, Vancouver, Canada, Frankfurt, Germany), application_name (string), created_at (string), id (string), inbound (object), outbound (object), record_type (string), tags (array[string]), updated_at (string), webhook_event_failover_url (uri), webhook_event_url (uri), webhook_timeout_secs (integer | null)

Deletes a Fax Application

Permanently deletes a Fax Application. Deletion may be prevented if the application is in use by phone numbers.

DELETE /fax_applications/{id}

fax_application = client.fax_applications.delete("1293384261075731499")

puts(fax_application)

Returns: active (boolean), anchorsite_override (enum: Latency, Chicago, IL, Ashburn, VA, San Jose, CA, Sydney, Australia, Amsterdam, Netherlands, London, UK, Toronto, Canada, Vancouver, Canada, Frankfurt, Germany), application_name (string), created_at (string), id (string), inbound (object), outbound (object), record_type (string), tags (array[string]), updated_at (string), webhook_event_failover_url (uri), webhook_event_url (uri), webhook_timeout_secs (integer | null)

View a list of faxes

Retrieve a paginated list of faxes sent or received on your account.

GET /faxes

page = client.faxes.list

puts(page)

Returns: client_state (string), connection_id (string), created_at (date-time), direction (enum: inbound, outbound), failure_reason (string | null), from (string), from_display_name (string), id (uuid), internal_failure_reason (string | null), media_name (string), media_url (string), preview_url (string), quality (enum: normal, high, very_high, ultra_light, ultra_dark), record_type (enum: fax), status (enum: queued, media.processed, originated, sending, delivered, failed, initiated, receiving, media.processing, received), store_media (boolean), stored_media_url (string), to (string), updated_at (date-time), webhook_failover_url (string), webhook_url (string)

Send a fax

Send a fax. Files have size limits and page count limit validations. If a file is bigger than 50MB or has more than 350 pages it will fail with file_size_limit_exceeded and page_count_limit_exceeded respectively.

POST /faxes — Required: connection_id, from, to

Optional: black_threshold (integer), client_state (string), from_display_name (string), media_name (string), media_url (string), monochrome (boolean), preview_format (enum: pdf, tiff), quality (enum: normal, high, very_high, ultra_light, ultra_dark), store_media (boolean), store_preview (boolean), t38_enabled (boolean), webhook_url (string)

fax = client.faxes.create(connection_id: "234423", from: "+13125790015", to: "+13127367276", media_url: "https://example.com/document.pdf")
puts(fax)

Returns: client_state (string), connection_id (string), created_at (date-time), direction (enum: inbound, outbound), failure_reason (string | null), from (string), from_display_name (string), id (uuid), internal_failure_reason (string | null), media_name (string), media_url (string), preview_url (string), quality (enum: normal, high, very_high, ultra_light, ultra_dark), record_type (enum: fax), status (enum: queued, media.processed, originated, sending, delivered, failed, initiated, receiving, media.processing, received), store_media (boolean), stored_media_url (string), to (string), updated_at (date-time), webhook_failover_url (string), webhook_url (string)

View a fax

Returns the details of a single fax, including its current status.

GET /faxes/{id}

fax = client.faxes.retrieve("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e")

puts(fax)

Returns: client_state (string), connection_id (string), created_at (date-time), direction (enum: inbound, outbound), failure_reason (string | null), from (string), from_display_name (string), id (uuid), internal_failure_reason (string | null), media_name (string), media_url (string), preview_url (string), quality (enum: normal, high, very_high, ultra_light, ultra_dark), record_type (enum: fax), status (enum: queued, media.processed, originated, sending, delivered, failed, initiated, receiving, media.processing, received), store_media (boolean), stored_media_url (string), to (string), updated_at (date-time), webhook_failover_url (string), webhook_url (string)

Delete a fax

Delete a fax resource from your account.

DELETE /faxes/{id}

result = client.faxes.delete("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e")

puts(result)

Cancel a fax

Cancel the outbound fax that is in one of the following states: queued, media.processed, originated or sending

POST /faxes/{id}/actions/cancel

response = client.faxes.actions.cancel("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e")

puts(response)

Returns: result (string)

Refresh a fax

Refreshes the inbound fax's media_url when it has expired

POST /faxes/{id}/actions/refresh

response = client.faxes.actions.refresh("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e")

puts(response)

Returns: result (string)


Webhooks

Webhook Verification

Telnyx signs webhooks with Ed25519. Each request includes telnyx-signature-ed25519 and telnyx-timestamp headers. Always verify signatures in production:

Verification needs your account's public key (Mission Control Portal → API Keys → Public Key). The SDK reads it from TELNYX_PUBLIC_KEY (the ## Setup block above passes it explicitly); without it every valid webhook fails verification and the handler below returns 400.

# In your webhook handler (e.g., Sinatra — use raw body):
post "/webhooks" do
  payload = request.body.read
  headers = {
    "telnyx-signature-ed25519" => request.env["HTTP_TELNYX_SIGNATURE_ED25519"],
    "telnyx-timestamp" => request.env["HTTP_TELNYX_TIMESTAMP"],
  }
  begin
    event = client.webhooks.unwrap(payload, headers)
  rescue => e
    halt 400, "Invalid signature: #{e.message}"
  end
  # Signature valid — event is the parsed webhook payload
  puts "Received event: #{event.data.event_type}"
  status 200
end

The following webhook events are sent to your configured webhook URL. All webhooks include telnyx-timestamp and telnyx-signature-ed25519 headers for Ed25519 signature verification. Use client.webhooks.unwrap() to verify.

EventDescription
fax.deliveredFax Delivered
fax.failedFax Failed
fax.media.processedFax Media Processed
fax.queuedFax Queued
fax.sending.startedFax Sending Started

Webhook payload fields

fax.delivered

FieldTypeDescription
data.record_typeenum: eventIdentifies the type of the resource.
data.iduuidIdentifies the type of resource.
data.occurred_atdate-timeISO 8601 datetime of when the event occurred.
data.event_typeenum: fax.deliveredThe type of event being delivered.
data.payload.call_duration_secsintegerThe duration of the call in seconds.
data.payload.connection_idstringThe ID of the connection used to send the fax.
data.payload.directionenum: inbound, outboundThe direction of the fax.
data.payload.fax_iduuidIdentifies the fax.
data.payload.original_media_urlstringThe original URL to the PDF used for the fax's media.
data.payload.media_namestringThe media_name used for the fax's media.
data.payload.tostringThe phone number, in E.164 format, the fax will be sent to or SIP URI
data.payload.fromstringThe phone number, in E.164 format, the fax will be sent from.
data.payload.user_iduuidIdentifier of the user to whom the fax belongs
data.payload.page_countintegerNumber of transferred pages
data.payload.statusenum: deliveredThe status of the fax.
data.payload.client_statestringState received from a command.
meta.attemptintegerThe delivery attempt number.
meta.delivered_touriThe URL the webhook was delivered to.

fax.failed

FieldTypeDescription
data.record_typeenum: eventIdentifies the type of the resource.
data.iduuidIdentifies the type of resource.
data.occurred_atdate-timeISO 8601 datetime of when the event occurred.
data.event_typeenum: fax.failedThe type of event being delivered.
data.payload.connection_idstringThe ID of the connection used to send the fax.
data.payload.directionenum: inbound, outboundThe direction of the fax.
data.payload.fax_iduuidIdentifies the fax.
data.payload.original_media_urlstringThe original URL to the PDF used for the fax's media.
data.payload.media_namestringThe media_name used for the fax's media.
data.payload.tostringThe phone number, in E.164 format, the fax will be sent to or SIP URI
data.payload.fromstringThe phone number, in E.164 format, the fax will be sent from.
data.payload.user_iduuidIdentifier of the user to whom the fax belongs
data.payload.failure_reasonstringCustomer-facing cause of the fax failure.
data.payload.internal_failure_reasonstringInternal, more granular cause of the fax failure.
data.payload.statusenum: failedThe status of the fax.
data.payload.client_statestringState received from a command.
meta.attemptintegerThe delivery attempt number.
meta.delivered_touriThe URL the webhook was delivered to.

fax.media.processed

FieldTypeDescription
data.record_typeenum: eventIdentifies the type of the resource.
data.iduuidIdentifies the type of resource.
data.occurred_atdate-timeISO 8601 datetime of when the event occurred.
data.event_typeenum: fax.media.processedThe type of event being delivered.
data.payload.connection_idstringThe ID of the connection used to send the fax.
data.payload.directionenum: inbound, outboundThe direction of the fax.
data.payload.fax_iduuidIdentifies the fax.
data.payload.original_media_urlstringThe original URL to the PDF used for the fax's media.
data.payload.media_namestringThe media_name used for the fax's media.
data.payload.tostringThe phone number, in E.164 format, the fax will be sent to or SIP URI
data.payload.fromstringThe phone number, in E.164 format, the fax will be sent from.
data.payload.user_iduuidIdentifier of the user to whom the fax belongs
data.payload.statusenum: media.processedThe status of the fax.
data.payload.client_statestringState received from a command.
meta.attemptintegerThe delivery attempt number.
meta.delivered_touriThe URL the webhook was delivered to.

fax.queued

FieldTypeDescription
data.record_typeenum: eventIdentifies the type of the resource.
data.iduuidIdentifies the type of resource.
data.occurred_atdate-timeISO 8601 datetime of when the event occurred.
data.event_typeenum: fax.queuedThe type of event being delivered.
data.payload.connection_idstringThe ID of the connection used to send the fax.
data.payload.directionenum: inbound, outboundThe direction of the fax.
data.payload.fax_iduuidIdentifies the fax.
data.payload.original_media_urlstringThe original URL to the PDF used for the fax's media.
data.payload.media_namestringThe media_name used for the fax's media.
data.payload.tostringThe phone number, in E.164 format, the fax will be sent to or SIP URI
data.payload.fromstringThe phone number, in E.164 format, the fax will be sent from.
data.payload.user_iduuidIdentifier of the user to whom the fax belongs
data.payload.statusenum: queuedThe status of the fax.
data.payload.client_statestringState received from a command.
meta.attemptintegerThe delivery attempt number.
meta.delivered_touriThe URL the webhook was delivered to.

fax.sending.started

FieldTypeDescription
data.record_typeenum: eventIdentifies the type of the resource.
data.iduuidIdentifies the type of resource.
data.occurred_atdate-timeISO 8601 datetime of when the event occurred.
data.event_typeenum: fax.sending.startedThe type of event being delivered.
data.payload.connection_idstringThe ID of the connection used to send the fax.
data.payload.directionenum: inbound, outboundThe direction of the fax.
data.payload.fax_iduuidIdentifies the fax.
data.payload.original_media_urlstringThe original URL to the PDF used for the fax's media.
data.payload.media_namestringThe media_name used for the fax's media.
data.payload.tostringThe phone number, in E.164 format, the fax will be sent to or SIP URI
data.payload.fromstringThe phone number, in E.164 format, the fax will be sent from.
data.payload.user_iduuidIdentifier of the user to whom the fax belongs
data.payload.statusenum: sendingThe status of the fax.
data.payload.client_statestringState received from a command.
meta.attemptintegerThe delivery attempt number.
meta.delivered_touriThe URL the webhook was delivered to.

评价

还没有评价。欢迎分享你的使用感受。

评论

无需登录即可发表。欢迎分享使用感受、提问,或说明在哪些环境下无法运行。

还没有评论。来写第一条吧。

提交后会立即公开。请勿填写邮箱、电话等个人信息。URL 最多 2 个。

0 / 1000 字

此表单受 reCAPTCHA 保护,适用 Google 的隐私权政策和服务条款。

同一仓库的技能

Test VoIP push notifications for Telnyx WebRTC iOS (APNs) and Android (FCM) apps. Use when debugging push notification delivery, validating certificate/credential setup, or testing that a device receives VoIP pushes correctly.

中文简介正在准备中。当前显示原文说明。

team-telnyx/ai2222026年10月22日 更新

10DLC brand and campaign registration for US A2P messaging compliance. Assign phone numbers to campaigns.

中文简介正在准备中。当前显示原文说明。

team-telnyx/ai2222026年10月22日 更新

10DLC brand and campaign registration for US A2P messaging compliance. Assign phone numbers to campaigns.

中文简介正在准备中。当前显示原文说明。

team-telnyx/ai2222026年10月22日 更新

10DLC brand and campaign registration for US A2P messaging compliance. Assign phone numbers to campaigns.

中文简介正在准备中。当前显示原文说明。

team-telnyx/ai2222026年10月22日 更新

10DLC brand and campaign registration for US A2P messaging compliance. Assign phone numbers to campaigns.

中文简介正在准备中。当前显示原文说明。

team-telnyx/ai2222026年10月22日 更新

10DLC brand and campaign registration for US A2P messaging compliance. Assign phone numbers to campaigns.

中文简介正在准备中。当前显示原文说明。

team-telnyx/ai2222026年10月22日 更新

查看 team-telnyx 的全部技能

报告此技能的问题