team-telnyx/ai

telnyx-fax-go

- Send and receive faxes programmatically.

Vedi sorgente

Come usare

  1. Copia il comando e controlla il pacchetto prima di installarlo nel tuo ambiente agente.
  2. Controlla strumenti, credenziali e ambienti richiesti nel documento originale.
  3. Descrivi input e risultato desiderato; confronta l’output con le fonti.
npx skills add https://github.com/team-telnyx/ai --skill telnyx-fax-go

Prima di iniziare

  • L’installazione non include abbonamenti, quote API o accesso ai file.
  • Stelle e installazioni indicano attività, non un test indipendente di qualità o sicurezza.
Documento Skill originale

Contenuto dal repository con titoli, esempi, codice, tabelle, link e immagini preservati.

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

Telnyx Fax - Go

Installation

bash
go get github.com/team-telnyx/telnyx-go

Setup

go
import (
  "context"
  "fmt"
  "os"

  "github.com/team-telnyx/telnyx-go"
  "github.com/team-telnyx/telnyx-go/option"
)

client := telnyx.NewClient(
  option.WithAPIKey(os.Getenv("TELNYX_API_KEY")),
)

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:

go
import "errors"

result, err := client.Messages.Send(ctx, params)
if err != nil {
  var apiErr *telnyx.Error
  if errors.As(err, &apiErr) {
    switch apiErr.StatusCode {
    case 422:
      fmt.Println("Validation error — check required fields and formats")
    case 429:
      // Rate limited — wait and retry with exponential backoff
      fmt.Println("Rate limited, retrying...")
    default:
      fmt.Printf("API error %d: %s\n", apiErr.StatusCode, apiErr.Error())
    }
  } else {
    fmt.Println("Network error — check connectivity and retry")
  }
}

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 ListAutoPaging() for automatic iteration: iter := client.Resource.ListAutoPaging(ctx, params); for iter.Next() { item := iter.Current() }.

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

go
	page, err := client.FaxApplications.List(context.Background(), telnyx.FaxApplicationListParams{})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%+v\n", 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)

go
	faxApplication, err := client.FaxApplications.New(context.Background(), telnyx.FaxApplicationNewParams{
		ApplicationName: "fax-router",
		WebhookEventURL: "https://example.com",
	})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%+v\n", faxApplication.Data)

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}

go
	faxApplication, err := client.FaxApplications.Get(context.Background(), "1293384261075731499")
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%+v\n", faxApplication.Data)

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)

go
	faxApplication, err := client.FaxApplications.Update(
		context.Background(),
		"1293384261075731499",
		telnyx.FaxApplicationUpdateParams{
			ApplicationName: "fax-router",
			WebhookEventURL: "https://example.com",
		},
	)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%+v\n", faxApplication.Data)

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}

go
	faxApplication, err := client.FaxApplications.Delete(context.Background(), "1293384261075731499")
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%+v\n", faxApplication.Data)

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

GET /faxes

go
	page, err := client.Faxes.List(context.Background(), telnyx.FaxListParams{})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%+v\n", page)

Returns: client_state (string), connection_id (string), created_at (date-time), direction (enum: inbound, outbound), from (string), from_display_name (string), id (uuid), media_name (string), media_url (string), preview_url (string), quality (enum: normal, high, veryhigh, ultralight, ultradark), `recordtype (enum: fax), status (enum: queued, media.processed, originated, sending, delivered, failed, initiated, receiving, media.processing, received), storemedia` (boolean), `storedmediaurl` (string), `to` (string), `updatedat (date-time), webhookfailoverurl (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, veryhigh, ultralight, ultradark), `storemedia (boolean), storepreview` (boolean), `t38enabled (boolean), webhook_url` (string)

go
	fax, err := client.Faxes.New(context.Background(), telnyx.FaxNewParams{
		ConnectionID: "234423",
		From:         "+13125790015",
		To:           "+13127367276",
		MediaURL: "https://example.com/document.pdf",
	})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%+v\n", fax.Data)

Returns: client_state (string), connection_id (string), created_at (date-time), direction (enum: inbound, outbound), from (string), from_display_name (string), id (uuid), media_name (string), media_url (string), preview_url (string), quality (enum: normal, high, veryhigh, ultralight, ultradark), `recordtype (enum: fax), status (enum: queued, media.processed, originated, sending, delivered, failed, initiated, receiving, media.processing, received), storemedia` (boolean), `storedmediaurl` (string), `to` (string), `updatedat (date-time), webhookfailoverurl (string), webhook_url` (string)

View a fax

GET /faxes/{id}

go
	fax, err := client.Faxes.Get(context.Background(), "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e")
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%+v\n", fax.Data)

Returns: client_state (string), connection_id (string), created_at (date-time), direction (enum: inbound, outbound), from (string), from_display_name (string), id (uuid), media_name (string), media_url (string), preview_url (string), quality (enum: normal, high, veryhigh, ultralight, ultradark), `recordtype (enum: fax), status (enum: queued, media.processed, originated, sending, delivered, failed, initiated, receiving, media.processing, received), storemedia` (boolean), `storedmediaurl` (string), `to` (string), `updatedat (date-time), webhookfailoverurl (string), webhook_url` (string)

Delete a fax

DELETE /faxes/{id}

go
	err := client.Faxes.Delete(context.Background(), "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e")
	if err != nil {
		log.Fatal(err)
	}

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

go
	response, err := client.Faxes.Actions.Cancel(context.Background(), "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e")
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%+v\n", response.Data)

Returns: result (string)

Refresh a fax

Refreshes the inbound fax's media_url when it has expired

POST /faxes/{id}/actions/refresh

go
	response, err := client.Faxes.Actions.Refresh(context.Background(), "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e")
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%+v\n", response.Data)

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:

go
// In your webhook handler:
func handleWebhook(w http.ResponseWriter, r *http.Request) {
  body, _ := io.ReadAll(r.Body)
  event, err := client.Webhooks.Unwrap(body, r.Header)
  if err != nil {
    http.Error(w, "Invalid signature", http.StatusBadRequest)
    return
  }
  // Signature valid — event is the parsed webhook payload
  fmt.Println("Received event:", event.Data.EventType)
  w.WriteHeader(http.StatusOK)
}

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_reasonenum: rejectedCause of the sending 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.

Correlati per attività

dallo stesso repository

Altri Skills

Tutti gli Skills