Loading...
Loading...
Compare original and translation side by side
<!-- Maven -->
<dependency>
<groupId>com.telnyx.sdk</groupId>
<artifactId>telnyx</artifactId>
<version>6.36.0</version>
</dependency>
// Gradle
implementation("com.telnyx.sdk:telnyx:6.36.0")<!-- Maven -->
<dependency>
<groupId>com.telnyx.sdk</groupId>
<artifactId>telnyx</artifactId>
<version>6.36.0</version>
</dependency>
// Gradle
implementation("com.telnyx.sdk:telnyx:6.36.0")import com.telnyx.sdk.client.TelnyxClient;
import com.telnyx.sdk.client.okhttp.TelnyxOkHttpClient;
TelnyxClient client = TelnyxOkHttpClient.fromEnv();clientimport com.telnyx.sdk.client.TelnyxClient;
import com.telnyx.sdk.client.okhttp.TelnyxOkHttpClient;
TelnyxClient client = TelnyxOkHttpClient.fromEnv();clientimport com.telnyx.sdk.errors.TelnyxServiceException;
try {
var result = client.messages().send(params);
} catch (TelnyxServiceException e) {
System.err.println("API error " + e.statusCode() + ": " + e.getMessage());
if (e.statusCode() == 422) {
System.err.println("Validation error — check required fields and formats");
} else if (e.statusCode() == 429) {
// Rate limited — wait and retry with exponential backoff
Thread.sleep(1000);
}
}401403404422429import com.telnyx.sdk.errors.TelnyxServiceException;
try {
var result = client.messages().send(params);
} catch (TelnyxServiceException e) {
System.err.println("API error " + e.statusCode() + ": " + e.getMessage());
if (e.statusCode() == 422) {
System.err.println("校验错误 — 请检查必填字段和格式是否正确");
} else if (e.statusCode() == 429) {
// 触发速率限制 — 等待后使用指数退避策略重试
Thread.sleep(1000);
}
}401403404422429+13125550001+.autoPager()for (var item : page.autoPager()) { ... }.hasNextPage().nextPage()+13125550001+.autoPager()for (var item : page.autoPager()) { ... }.hasNextPage().nextPage()GET /fax_applicationsimport com.telnyx.sdk.models.faxapplications.FaxApplicationListPage;
import com.telnyx.sdk.models.faxapplications.FaxApplicationListParams;
FaxApplicationListPage page = client.faxApplications().list();activeanchorsite_overrideapplication_namecreated_atidinboundoutboundrecord_typetagsupdated_atwebhook_event_failover_urlwebhook_event_urlwebhook_timeout_secsdataGET /fax_applicationsimport com.telnyx.sdk.models.faxapplications.FaxApplicationListPage;
import com.telnyx.sdk.models.faxapplications.FaxApplicationListParams;
FaxApplicationListPage page = client.faxApplications().list();activeanchorsite_overrideapplication_namecreated_atidinboundoutboundrecord_typetagsupdated_atwebhook_event_failover_urlwebhook_event_urlwebhook_timeout_secs/phone_numbersPOST /fax_applicationsapplication_namewebhook_event_urlactiveanchorsite_overrideinboundoutboundtagswebhook_event_failover_urlwebhook_timeout_secsimport com.telnyx.sdk.models.faxapplications.FaxApplicationCreateParams;
import com.telnyx.sdk.models.faxapplications.FaxApplicationCreateResponse;
FaxApplicationCreateParams params = FaxApplicationCreateParams.builder()
.applicationName("fax-router")
.webhookEventUrl("https://example.com")
.build();
FaxApplicationCreateResponse faxApplication = client.faxApplications().create(params);activeanchorsite_overrideapplication_namecreated_atidinboundoutboundrecord_typetagsupdated_atwebhook_event_failover_urlwebhook_event_urlwebhook_timeout_secs/phone_numbersPOST /fax_applicationsapplication_namewebhook_event_urlactiveanchorsite_overrideinboundoutboundtagswebhook_event_failover_urlwebhook_timeout_secsimport com.telnyx.sdk.models.faxapplications.FaxApplicationCreateParams;
import com.telnyx.sdk.models.faxapplications.FaxApplicationCreateResponse;
FaxApplicationCreateParams params = FaxApplicationCreateParams.builder()
.applicationName("fax-router")
.webhookEventUrl("https://example.com")
.build();
FaxApplicationCreateResponse faxApplication = client.faxApplications().create(params);activeanchorsite_overrideapplication_namecreated_atidinboundoutboundrecord_typetagsupdated_atwebhook_event_failover_urlwebhook_event_urlwebhook_timeout_secsGET /fax_applications/{id}import com.telnyx.sdk.models.faxapplications.FaxApplicationRetrieveParams;
import com.telnyx.sdk.models.faxapplications.FaxApplicationRetrieveResponse;
FaxApplicationRetrieveResponse faxApplication = client.faxApplications().retrieve("1293384261075731499");activeanchorsite_overrideapplication_namecreated_atidinboundoutboundrecord_typetagsupdated_atwebhook_event_failover_urlwebhook_event_urlwebhook_timeout_secsdataGET /fax_applications/{id}import com.telnyx.sdk.models.faxapplications.FaxApplicationRetrieveParams;
import com.telnyx.sdk.models.faxapplications.FaxApplicationRetrieveResponse;
FaxApplicationRetrieveResponse faxApplication = client.faxApplications().retrieve("1293384261075731499");activeanchorsite_overrideapplication_namecreated_atidinboundoutboundrecord_typetagsupdated_atwebhook_event_failover_urlwebhook_event_urlwebhook_timeout_secsPATCH /fax_applications/{id}application_namewebhook_event_urlactiveanchorsite_overridefax_email_recipientinboundoutboundtagswebhook_event_failover_urlwebhook_timeout_secsimport com.telnyx.sdk.models.faxapplications.FaxApplicationUpdateParams;
import com.telnyx.sdk.models.faxapplications.FaxApplicationUpdateResponse;
FaxApplicationUpdateParams params = FaxApplicationUpdateParams.builder()
.id("1293384261075731499")
.applicationName("fax-router")
.webhookEventUrl("https://example.com")
.build();
FaxApplicationUpdateResponse faxApplication = client.faxApplications().update(params);activeanchorsite_overrideapplication_namecreated_atidinboundoutboundrecord_typetagsupdated_atwebhook_event_failover_urlwebhook_event_urlwebhook_timeout_secsPATCH /fax_applications/{id}application_namewebhook_event_urlactiveanchorsite_overridefax_email_recipientinboundoutboundtagswebhook_event_failover_urlwebhook_timeout_secsimport com.telnyx.sdk.models.faxapplications.FaxApplicationUpdateParams;
import com.telnyx.sdk.models.faxapplications.FaxApplicationUpdateResponse;
FaxApplicationUpdateParams params = FaxApplicationUpdateParams.builder()
.id("1293384261075731499")
.applicationName("fax-router")
.webhookEventUrl("https://example.com")
.build();
FaxApplicationUpdateResponse faxApplication = client.faxApplications().update(params);activeanchorsite_overrideapplication_namecreated_atidinboundoutboundrecord_typetagsupdated_atwebhook_event_failover_urlwebhook_event_urlwebhook_timeout_secsDELETE /fax_applications/{id}import com.telnyx.sdk.models.faxapplications.FaxApplicationDeleteParams;
import com.telnyx.sdk.models.faxapplications.FaxApplicationDeleteResponse;
FaxApplicationDeleteResponse faxApplication = client.faxApplications().delete("1293384261075731499");activeanchorsite_overrideapplication_namecreated_atidinboundoutboundrecord_typetagsupdated_atwebhook_event_failover_urlwebhook_event_urlwebhook_timeout_secsDELETE /fax_applications/{id}import com.telnyx.sdk.models.faxapplications.FaxApplicationDeleteParams;
import com.telnyx.sdk.models.faxapplications.FaxApplicationDeleteResponse;
FaxApplicationDeleteResponse faxApplication = client.faxApplications().delete("1293384261075731499");activeanchorsite_overrideapplication_namecreated_atidinboundoutboundrecord_typetagsupdated_atwebhook_event_failover_urlwebhook_event_urlwebhook_timeout_secsGET /faxesimport com.telnyx.sdk.models.faxes.FaxListPage;
import com.telnyx.sdk.models.faxes.FaxListParams;
FaxListPage page = client.faxes().list();client_stateconnection_idcreated_atdirectionfromfrom_display_nameidmedia_namemedia_urlpreview_urlqualityrecord_typestatusstore_mediastored_media_urltoupdated_atwebhook_failover_urlwebhook_urlGET /faxesimport com.telnyx.sdk.models.faxes.FaxListPage;
import com.telnyx.sdk.models.faxes.FaxListParams;
FaxListPage page = client.faxes().list();client_stateconnection_idcreated_atdirectionfromfrom_display_nameidmedia_namemedia_urlpreview_urlqualityrecord_typestatusstore_mediastored_media_urltoupdated_atwebhook_failover_urlwebhook_urlfile_size_limit_exceededpage_count_limit_exceededPOST /faxesconnection_idfromtoblack_thresholdclient_statefrom_display_namemedia_namemedia_urlmonochromepreview_formatqualitystore_mediastore_previewt38_enabledwebhook_urlimport com.telnyx.sdk.models.faxes.FaxCreateParams;
import com.telnyx.sdk.models.faxes.FaxCreateResponse;
FaxCreateParams params = FaxCreateParams.builder()
.connectionId("234423")
.from("+13125790015")
.to("+13127367276")
.mediaUrl("https://example.com/document.pdf")
.build();
FaxCreateResponse fax = client.faxes().create(params);client_stateconnection_idcreated_atdirectionfromfrom_display_nameidmedia_namemedia_urlpreview_urlqualityrecord_typestatusstore_mediastored_media_urltoupdated_atwebhook_failover_urlwebhook_urlfile_size_limit_exceededpage_count_limit_exceededPOST /faxesconnection_idfromtoblack_thresholdclient_statefrom_display_namemedia_namemedia_urlmonochromepreview_formatqualitystore_mediastore_previewt38_enabledwebhook_urlimport com.telnyx.sdk.models.faxes.FaxCreateParams;
import com.telnyx.sdk.models.faxes.FaxCreateResponse;
FaxCreateParams params = FaxCreateParams.builder()
.connectionId("234423")
.from("+13125790015")
.to("+13127367276")
.mediaUrl("https://example.com/document.pdf")
.build();
FaxCreateResponse fax = client.faxes().create(params);client_stateconnection_idcreated_atdirectionfromfrom_display_nameidmedia_namemedia_urlpreview_urlqualityrecord_typestatusstore_mediastored_media_urltoupdated_atwebhook_failover_urlwebhook_urlGET /faxes/{id}import com.telnyx.sdk.models.faxes.FaxRetrieveParams;
import com.telnyx.sdk.models.faxes.FaxRetrieveResponse;
FaxRetrieveResponse fax = client.faxes().retrieve("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e");client_stateconnection_idcreated_atdirectionfromfrom_display_nameidmedia_namemedia_urlpreview_urlqualityrecord_typestatusstore_mediastored_media_urltoupdated_atwebhook_failover_urlwebhook_urlGET /faxes/{id}import com.telnyx.sdk.models.faxes.FaxRetrieveParams;
import com.telnyx.sdk.models.faxes.FaxRetrieveResponse;
FaxRetrieveResponse fax = client.faxes().retrieve("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e");client_stateconnection_idcreated_atdirectionfromfrom_display_nameidmedia_namemedia_urlpreview_urlqualityrecord_typestatusstore_mediastored_media_urltoupdated_atwebhook_failover_urlwebhook_urlDELETE /faxes/{id}import com.telnyx.sdk.models.faxes.FaxDeleteParams;
client.faxes().delete("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e");DELETE /faxes/{id}import com.telnyx.sdk.models.faxes.FaxDeleteParams;
client.faxes().delete("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e");queuedmedia.processedoriginatedsendingPOST /faxes/{id}/actions/cancelimport com.telnyx.sdk.models.faxes.actions.ActionCancelParams;
import com.telnyx.sdk.models.faxes.actions.ActionCancelResponse;
ActionCancelResponse response = client.faxes().actions().cancel("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e");resultqueuedmedia.processedoriginatedsendingPOST /faxes/{id}/actions/cancelimport com.telnyx.sdk.models.faxes.actions.ActionCancelParams;
import com.telnyx.sdk.models.faxes.actions.ActionCancelResponse;
ActionCancelResponse response = client.faxes().actions().cancel("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e");resultPOST /faxes/{id}/actions/refreshimport com.telnyx.sdk.models.faxes.actions.ActionRefreshParams;
import com.telnyx.sdk.models.faxes.actions.ActionRefreshResponse;
ActionRefreshResponse response = client.faxes().actions().refresh("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e");resultmedia_urlPOST /faxes/{id}/actions/refreshimport com.telnyx.sdk.models.faxes.actions.ActionRefreshParams;
import com.telnyx.sdk.models.faxes.actions.ActionRefreshResponse;
ActionRefreshResponse response = client.faxes().actions().refresh("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e");resulttelnyx-signature-ed25519telnyx-timestampimport com.telnyx.sdk.core.UnwrapWebhookParams;
import com.telnyx.sdk.core.http.Headers;
// In your webhook handler (e.g., Spring — use raw body):
@PostMapping("/webhooks")
public ResponseEntity<String> handleWebhook(
@RequestBody String payload,
HttpServletRequest request) {
try {
Headers headers = Headers.builder()
.put("telnyx-signature-ed25519", request.getHeader("telnyx-signature-ed25519"))
.put("telnyx-timestamp", request.getHeader("telnyx-timestamp"))
.build();
var event = client.webhooks().unwrap(
UnwrapWebhookParams.builder()
.body(payload)
.headers(headers)
.build());
// Signature valid — process the event
System.out.println("Received webhook event");
return ResponseEntity.ok("OK");
} catch (Exception e) {
System.err.println("Webhook verification failed: " + e.getMessage());
return ResponseEntity.badRequest().body("Invalid signature");
}
}telnyx-timestamptelnyx-signature-ed25519client.webhooks.unwrap()| Event | Description |
|---|---|
| Fax Delivered |
| Fax Failed |
| Fax Media Processed |
| Fax Queued |
| Fax Sending Started |
telnyx-signature-ed25519telnyx-timestampimport com.telnyx.sdk.core.UnwrapWebhookParams;
import com.telnyx.sdk.core.http.Headers;
// 在您的Webhook处理逻辑中(例如Spring — 使用原始请求体):
@PostMapping("/webhooks")
public ResponseEntity<String> handleWebhook(
@RequestBody String payload,
HttpServletRequest request) {
try {
Headers headers = Headers.builder()
.put("telnyx-signature-ed25519", request.getHeader("telnyx-signature-ed25519"))
.put("telnyx-timestamp", request.getHeader("telnyx-timestamp"))
.build();
var event = client.webhooks().unwrap(
UnwrapWebhookParams.builder()
.body(payload)
.headers(headers)
.build());
// 签名验证通过 — 处理事件
System.out.println("Received webhook event");
return ResponseEntity.ok("OK");
} catch (Exception e) {
System.err.println("Webhook verification failed: " + e.getMessage());
return ResponseEntity.badRequest().body("Invalid signature");
}
}telnyx-timestamptelnyx-signature-ed25519client.webhooks.unwrap()| 事件 | 描述 |
|---|---|
| 传真已送达 |
| 传真发送失败 |
| 传真媒体处理完成 |
| 传真已加入队列 |
| 传真开始发送 |
fax.delivered| Field | Type | Description |
|---|---|---|
| enum: event | Identifies the type of the resource. |
| uuid | Identifies the type of resource. |
| date-time | ISO 8601 datetime of when the event occurred. |
| enum: fax.delivered | The type of event being delivered. |
| integer | The duration of the call in seconds. |
| string | The ID of the connection used to send the fax. |
| enum: inbound, outbound | The direction of the fax. |
| uuid | Identifies the fax. |
| string | The original URL to the PDF used for the fax's media. |
| string | The media_name used for the fax's media. |
| string | The phone number, in E.164 format, the fax will be sent to or SIP URI |
| string | The phone number, in E.164 format, the fax will be sent from. |
| uuid | Identifier of the user to whom the fax belongs |
| integer | Number of transferred pages |
| enum: delivered | The status of the fax. |
| string | State received from a command. |
| integer | The delivery attempt number. |
| uri | The URL the webhook was delivered to. |
fax.failed| Field | Type | Description |
|---|---|---|
| enum: event | Identifies the type of the resource. |
| uuid | Identifies the type of resource. |
| date-time | ISO 8601 datetime of when the event occurred. |
| enum: fax.failed | The type of event being delivered. |
| string | The ID of the connection used to send the fax. |
| enum: inbound, outbound | The direction of the fax. |
| uuid | Identifies the fax. |
| string | The original URL to the PDF used for the fax's media. |
| string | The media_name used for the fax's media. |
| string | The phone number, in E.164 format, the fax will be sent to or SIP URI |
| string | The phone number, in E.164 format, the fax will be sent from. |
| uuid | Identifier of the user to whom the fax belongs |
| enum: rejected | Cause of the sending failure |
| enum: failed | The status of the fax. |
| string | State received from a command. |
| integer | The delivery attempt number. |
| uri | The URL the webhook was delivered to. |
fax.media.processed| Field | Type | Description |
|---|---|---|
| enum: event | Identifies the type of the resource. |
| uuid | Identifies the type of resource. |
| date-time | ISO 8601 datetime of when the event occurred. |
| enum: fax.media.processed | The type of event being delivered. |
| string | The ID of the connection used to send the fax. |
| enum: inbound, outbound | The direction of the fax. |
| uuid | Identifies the fax. |
| string | The original URL to the PDF used for the fax's media. |
| string | The media_name used for the fax's media. |
| string | The phone number, in E.164 format, the fax will be sent to or SIP URI |
| string | The phone number, in E.164 format, the fax will be sent from. |
| uuid | Identifier of the user to whom the fax belongs |
| enum: media.processed | The status of the fax. |
| string | State received from a command. |
| integer | The delivery attempt number. |
| uri | The URL the webhook was delivered to. |
fax.queued| Field | Type | Description |
|---|---|---|
| enum: event | Identifies the type of the resource. |
| uuid | Identifies the type of resource. |
| date-time | ISO 8601 datetime of when the event occurred. |
| enum: fax.queued | The type of event being delivered. |
| string | The ID of the connection used to send the fax. |
| enum: inbound, outbound | The direction of the fax. |
| uuid | Identifies the fax. |
| string | The original URL to the PDF used for the fax's media. |
| string | The media_name used for the fax's media. |
| string | The phone number, in E.164 format, the fax will be sent to or SIP URI |
| string | The phone number, in E.164 format, the fax will be sent from. |
| uuid | Identifier of the user to whom the fax belongs |
| enum: queued | The status of the fax. |
| string | State received from a command. |
| integer | The delivery attempt number. |
| uri | The URL the webhook was delivered to. |
fax.sending.started| Field | Type | Description |
|---|---|---|
| enum: event | Identifies the type of the resource. |
| uuid | Identifies the type of resource. |
| date-time | ISO 8601 datetime of when the event occurred. |
| enum: fax.sending.started | The type of event being delivered. |
| string | The ID of the connection used to send the fax. |
| enum: inbound, outbound | The direction of the fax. |
| uuid | Identifies the fax. |
| string | The original URL to the PDF used for the fax's media. |
| string | The media_name used for the fax's media. |
| string | The phone number, in E.164 format, the fax will be sent to or SIP URI |
| string | The phone number, in E.164 format, the fax will be sent from. |
| uuid | Identifier of the user to whom the fax belongs |
| enum: sending | The status of the fax. |
| string | State received from a command. |
| integer | The delivery attempt number. |
| uri | The URL the webhook was delivered to. |
fax.delivered| 字段 | 类型 | 描述 |
|---|---|---|
| 枚举值: event | 资源类型标识 |
| uuid | 资源ID |
| date-time | 事件发生的ISO 8601格式时间 |
| 枚举值: fax.delivered | 事件类型 |
| integer | 通话时长(单位:秒) |
| string | 发送传真使用的连接ID |
| 枚举值: inbound, outbound | 传真方向 |
| uuid | 传真ID |
| string | 传真媒体源PDF的URL |
| string | 传真媒体使用的media_name |
| string | 接收方的E.164格式电话号码或SIP URI |
| string | 发送方的E.164格式电话号码 |
| uuid | 传真所属用户的ID |
| integer | 已传输的页数 |
| 枚举值: delivered | 传真状态 |
| string | 从命令中获取的状态信息 |
| integer | 投递尝试次数 |
| uri | Webhook投递的目标URL |
fax.failed| 字段 | 类型 | 描述 |
|---|---|---|
| 枚举值: event | 资源类型标识 |
| uuid | 资源ID |
| date-time | 事件发生的ISO 8601格式时间 |
| 枚举值: fax.failed | 事件类型 |
| string | 发送传真使用的连接ID |
| 枚举值: inbound, outbound | 传真方向 |
| uuid | 传真ID |
| string | 传真媒体源PDF的URL |
| string | 传真媒体使用的media_name |
| string | 接收方的E.164格式电话号码或SIP URI |
| string | 发送方的E.164格式电话号码 |
| uuid | 传真所属用户的ID |
| 枚举值: rejected | 发送失败的原因 |
| 枚举值: failed | 传真状态 |
| string | 从命令中获取的状态信息 |
| integer | 投递尝试次数 |
| uri | Webhook投递的目标URL |
fax.media.processed| 字段 | 类型 | 描述 |
|---|---|---|
| 枚举值: event | 资源类型标识 |
| uuid | 资源ID |
| date-time | 事件发生的ISO 8601格式时间 |
| 枚举值: fax.media.processed | 事件类型 |
| string | 发送传真使用的连接ID |
| 枚举值: inbound, outbound | 传真方向 |
| uuid | 传真ID |
| string | 传真媒体源PDF的URL |
| string | 传真媒体使用的media_name |
| string | 接收方的E.164格式电话号码或SIP URI |
| string | 发送方的E.164格式电话号码 |
| uuid | 传真所属用户的ID |
| 枚举值: media.processed | 传真状态 |
| string | 从命令中获取的状态信息 |
| integer | 投递尝试次数 |
| uri | Webhook投递的目标URL |
fax.queued| 字段 | 类型 | 描述 |
|---|---|---|
| 枚举值: event | 资源类型标识 |
| uuid | 资源ID |
| date-time | 事件发生的ISO 8601格式时间 |
| 枚举值: fax.queued | 事件类型 |
| string | 发送传真使用的连接ID |
| 枚举值: inbound, outbound | 传真方向 |
| uuid | 传真ID |
| string | 传真媒体源PDF的URL |
| string | 传真媒体使用的media_name |
| string | 接收方的E.164格式电话号码或SIP URI |
| string | 发送方的E.164格式电话号码 |
| uuid | 传真所属用户的ID |
| 枚举值: queued | 传真状态 |
| string | 从命令中获取的状态信息 |
| integer | 投递尝试次数 |
| uri | Webhook投递的目标URL |
fax.sending.started| 字段 | 类型 | 描述 |
|---|---|---|
| 枚举值: event | 资源类型标识 |
| uuid | 资源ID |
| date-time | 事件发生的ISO 8601格式时间 |
| 枚举值: fax.sending.started | 事件类型 |
| string | 发送传真使用的连接ID |
| 枚举值: inbound, outbound | 传真方向 |
| uuid | 传真ID |
| string | 传真媒体源PDF的URL |
| string | 传真媒体使用的media_name |
| string | 接收方的E.164格式电话号码或SIP URI |
| string | 发送方的E.164格式电话号码 |
| uuid | 传真所属用户的ID |
| 枚举值: sending | 传真状态 |
| string | 从命令中获取的状态信息 |
| integer | 投递尝试次数 |
| uri | Webhook投递的目标URL |