Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(sdk): type the webhook delivery-failure log

Yudhi Armyndharis3741e4363d21
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 733a73ba9..6faf50603 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- The Italian (`it`) dashboard translates the session proxy Save button, the webhook chat-kind filter label and the warning shown when a backup export leaves out media ([#1583](https://github.com/rmyndharis/OpenWA/pull/1583)). Thanks @albanobattistella.
+- `webhooks.deliveryFailures` returns a typed `WebhookDeliveryFailure` list in the JavaScript, Python, Go and Java SDKs; Go and Java callers that handled the old untyped value must update.
### Fixed
diff --git a/docs/18-sdk-design.md b/docs/18-sdk-design.md
index 0f9533aad..3c6952ae0 100644
--- a/docs/18-sdk-design.md
+++ b/docs/18-sdk-design.md
@@ -608,16 +608,16 @@ Resources are accessed as properties on the client (e.g. `client.messages`). All
#### `client.webhooks`
-| Method | Signature | Description |
-| ------------------- | --------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
-| `list_all` | `list_all(query=None) -> list[WebhookResponse]` | List webhooks across EVERY session the key can see, not one session's. **OPERATOR** |
-| `delivery_failures` | `delivery_failures(query=None) -> Any` | Deliveries that were attempted and failed — the diagnostic for a webhook that stopped arriving. A delivery a smart filter suppressed never reaches this log. **ADMIN** |
-| `list` | `list(session_id) -> list[WebhookResponse]` | List webhooks. **OPERATOR** |
-| `get` | `get(session_id, webhook_id) -> WebhookResponse` | Get one webhook. **OPERATOR** |
-| `create` | `create(session_id, body) -> WebhookResponse` | Create a webhook. **OPERATOR** |
-| `update` | `update(session_id, webhook_id, body) -> WebhookResponse` | Update a webhook. **OPERATOR** |
-| `delete` | `delete(session_id, webhook_id) -> None` | Delete a webhook. **OPERATOR** |
-| `test` | `test(session_id, webhook_id) -> WebhookTestResult` | Send a test delivery. **OPERATOR** |
+| Method | Signature | Description |
+| ------------------- | --------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
+| `list_all` | `list_all(query=None) -> list[WebhookResponse]` | List webhooks across EVERY session the key can see, not one session's. **OPERATOR** |
+| `delivery_failures` | `delivery_failures(query=None) -> list[WebhookDeliveryFailure]` | Deliveries that were attempted and failed — the diagnostic for a webhook that stopped arriving. A delivery a smart filter suppressed never reaches this log. **ADMIN** |
+| `list` | `list(session_id) -> list[WebhookResponse]` | List webhooks. **OPERATOR** |
+| `get` | `get(session_id, webhook_id) -> WebhookResponse` | Get one webhook. **OPERATOR** |
+| `create` | `create(session_id, body) -> WebhookResponse` | Create a webhook. **OPERATOR** |
+| `update` | `update(session_id, webhook_id, body) -> WebhookResponse` | Update a webhook. **OPERATOR** |
+| `delete` | `delete(session_id, webhook_id) -> None` | Delete a webhook. **OPERATOR** |
+| `test` | `test(session_id, webhook_id) -> WebhookTestResult` | Send a test delivery. **OPERATOR** |
#### `client.labels` _(WhatsApp Business)_
diff --git a/scripts/check-contract-shapes.mjs b/scripts/check-contract-shapes.mjs
index 454a11229..ec518a3d6 100644
--- a/scripts/check-contract-shapes.mjs
+++ b/scripts/check-contract-shapes.mjs
@@ -135,6 +135,7 @@ const MAPPINGS = {
UpsertContactRequest: 'UpsertContactDto',
UpsertLabelRequest: 'UpsertLabelDto',
VotePollRequest: 'VotePollDto',
+ WebhookDeliveryFailure: 'WebhookDeliveryFailureDto',
WebhookFilterCondition: 'WebhookFilterConditionDto',
WebhookResponse: 'WebhookResponseDto',
},
@@ -170,11 +171,11 @@ const MAPPINGS = {
* these floors as pairs are added makes the shrink loud.
*/
const MINIMUM_MAPPED = {
- 'sdk/javascript/src/types.ts': 82,
+ 'sdk/javascript/src/types.ts': 83,
'dashboard/src/services/api.ts': 21,
- 'sdk/python/openwa/types.py': 78,
- 'sdk/go': 78,
- 'sdk/java': 82,
+ 'sdk/python/openwa/types.py': 79,
+ 'sdk/go': 79,
+ 'sdk/java': 83,
};
/** Known drift, deliberately not gated yet — each line is a to-adjudicate follow-up. */
@@ -287,6 +288,7 @@ const PYTHON_MAPPING = {
UpsertContactRequest: 'UpsertContactDto',
UpsertLabelRequest: 'UpsertLabelDto',
VotePollRequest: 'VotePollDto',
+ WebhookDeliveryFailure: 'WebhookDeliveryFailureDto',
WebhookResponse: 'WebhookResponseDto',
};
@@ -369,6 +371,7 @@ const GO_MAPPING = {
UpsertContactRequest: 'UpsertContactDto',
UpsertLabelRequest: 'UpsertLabelDto',
VotePollRequest: 'VotePollDto',
+ WebhookDeliveryFailure: 'WebhookDeliveryFailureDto',
WebhookResponse: 'WebhookResponseDto',
};
@@ -455,6 +458,7 @@ const JAVA_MAPPING = {
UpsertContactRequest: 'UpsertContactDto',
UpsertLabelRequest: 'UpsertLabelDto',
VotePollRequest: 'VotePollDto',
+ WebhookDeliveryFailure: 'WebhookDeliveryFailureDto',
WebhookResponse: 'WebhookResponseDto',
};
diff --git a/sdk/go/types_webhook.go b/sdk/go/types_webhook.go
index b4f1df0dd..d109fcfdd 100644
--- a/sdk/go/types_webhook.go
+++ b/sdk/go/types_webhook.go
@@ -165,3 +165,24 @@ type WebhookTestResult struct {
StatusCode int `json:"statusCode,omitempty"`
Error string `json:"error,omitempty"`
}
+
+// WebhookDeliveryFailure is a webhook delivery abandoned after every retry,
+// as listed by the delivery-failure log.
+type WebhookDeliveryFailure struct {
+ ID string `json:"id"`
+ WebhookID string `json:"webhookId"`
+ SessionID string `json:"sessionId"`
+ Event string `json:"event"`
+ URL string `json:"url"`
+ // IdempotencyKey is the key the receiver would have deduped on.
+ IdempotencyKey *string `json:"idempotencyKey,omitempty"`
+ DeliveryID *string `json:"deliveryId,omitempty"`
+ // Attempts is the total number of attempts made before giving up.
+ Attempts int `json:"attempts"`
+ // LastStatusCode is the last HTTP status when the failure was a non-2xx
+ // response; nil for a network or timeout error.
+ LastStatusCode *int `json:"lastStatusCode,omitempty"`
+ LastError string `json:"lastError"`
+ // CreatedAt is the ISO timestamp of when the delivery was finally abandoned.
+ CreatedAt string `json:"createdAt"`
+}
diff --git a/sdk/go/webhooks.go b/sdk/go/webhooks.go
index ded51674e..dfe52b83b 100644
--- a/sdk/go/webhooks.go
+++ b/sdk/go/webhooks.go
@@ -21,10 +21,9 @@ func (s *WebhooksService) ListAll(ctx context.Context, query *DeliveryFailureQue
// DeliveryFailures returns deliveries that were ATTEMPTED and failed — the diagnostic for a webhook
// that stopped arriving. Requires an ADMIN-level key.
//
-// A delivery a smart filter suppressed never reaches this log. The response has no published schema,
-// so it decodes into a generic value.
-func (s *WebhooksService) DeliveryFailures(ctx context.Context, query *DeliveryFailureQuery) (any, error) {
- var out any
+// A delivery a smart filter suppressed never reaches this log. Most recent first.
+func (s *WebhooksService) DeliveryFailures(ctx context.Context, query *DeliveryFailureQuery) ([]WebhookDeliveryFailure, error) {
+ var out []WebhookDeliveryFailure
err := s.client.do(ctx, "GET", "/api/webhooks/delivery-failures", query.values(), nil, &out)
return out, err
}
diff --git a/sdk/java/src/main/java/com/rmyndharis/openwa/model/WebhookDeliveryFailure.java b/sdk/java/src/main/java/com/rmyndharis/openwa/model/WebhookDeliveryFailure.java
new file mode 100644
index 000000000..00fb8a6b5
--- /dev/null
+++ b/sdk/java/src/main/java/com/rmyndharis/openwa/model/WebhookDeliveryFailure.java
@@ -0,0 +1,22 @@
+package com.rmyndharis.openwa.model;
+
+/**
+ * A webhook delivery abandoned after every retry, as listed by the delivery-failure log. Optional
+ * fields are {@code null} when absent.
+ */
+public record WebhookDeliveryFailure(
+ String id,
+ String webhookId,
+ String sessionId,
+ String event,
+ String url,
+ /** The idempotency key the receiver would have deduped on. */
+ String idempotencyKey,
+ String deliveryId,
+ /** Total attempts made before giving up. */
+ int attempts,
+ /** Last HTTP status when the failure was a non-2xx response; {@code null} for a network or timeout error. */
+ Integer lastStatusCode,
+ String lastError,
+ /** ISO timestamp of when the delivery was finally abandoned. */
+ String createdAt) {}
diff --git a/sdk/java/src/main/java/com/rmyndharis/openwa/resources/WebhooksResource.java b/sdk/java/src/main/java/com/rmyndharis/openwa/resources/WebhooksResource.java
index b491864d4..c214e5ef9 100644
--- a/sdk/java/src/main/java/com/rmyndharis/openwa/resources/WebhooksResource.java
+++ b/sdk/java/src/main/java/com/rmyndharis/openwa/resources/WebhooksResource.java
@@ -7,6 +7,7 @@ import com.rmyndharis.openwa.http.HttpMethod;
import com.rmyndharis.openwa.model.DeliveryFailureQuery;
import com.rmyndharis.openwa.model.CreateWebhookRequest;
import com.rmyndharis.openwa.model.UpdateWebhookRequest;
+import com.rmyndharis.openwa.model.WebhookDeliveryFailure;
import com.rmyndharis.openwa.model.WebhookResponse;
import com.rmyndharis.openwa.model.WebhookTestResult;
import java.util.List;
@@ -31,11 +32,11 @@ public final class WebhooksResource {
* Deliveries that were ATTEMPTED and failed — the diagnostic for a webhook that stopped arriving.
* Requires an ADMIN-level key.
*
- * <p>A delivery a smart filter suppressed never reaches this log. The response has no published
- * schema, so it is returned as a raw JSON tree.
+ * <p>A delivery a smart filter suppressed never reaches this log. Most recent first.
*/
- public Object deliveryFailures(DeliveryFailureQuery query) {
- return client.request(HttpMethod.GET, "/api/webhooks/delivery-failures", query, null, Object.class);
+ public List<WebhookDeliveryFailure> deliveryFailures(DeliveryFailureQuery query) {
+ return client.requestList(
+ HttpMethod.GET, "/api/webhooks/delivery-failures", query, null, WebhookDeliveryFailure.class);
}
/** List all webhooks for a session. */
diff --git a/sdk/javascript/src/resources/webhooks.ts b/sdk/javascript/src/resources/webhooks.ts
index 22802f662..98a444d03 100644
--- a/sdk/javascript/src/resources/webhooks.ts
+++ b/sdk/javascript/src/resources/webhooks.ts
@@ -7,7 +7,13 @@
import { encodeSegment } from '../http.js';
import type { OpenWAClient } from '../client.js';
-import type { CreateWebhookRequest, UpdateWebhookRequest, WebhookResponse, WebhookTestResult } from '../types.js';
+import type {
+ CreateWebhookRequest,
+ UpdateWebhookRequest,
+ WebhookDeliveryFailure,
+ WebhookResponse,
+ WebhookTestResult,
+} from '../types.js';
/** Pagination for the cross-session webhook list and the delivery-failure log. */
export interface WebhookListQuery {
@@ -36,10 +42,14 @@ export class WebhooksResource {
* arriving. Requires an ADMIN-level key.
*
* Note it records deliveries that were ATTEMPTED: a delivery a smart filter suppressed never reaches
- * this log. The response has no published schema, so it is returned unshaped.
+ * this log. Most recent first.
*/
- deliveryFailures(query?: DeliveryFailureQuery): Promise<unknown> {
- return this.client.request<unknown>({ method: 'GET', path: '/api/webhooks/delivery-failures', query });
+ deliveryFailures(query?: DeliveryFailureQuery): Promise<WebhookDeliveryFailure[]> {
+ return this.client.request<WebhookDeliveryFailure[]>({
+ method: 'GET',
+ path: '/api/webhooks/delivery-failures',
+ query,
+ });
}
/** List all webhooks for a session. */
diff --git a/sdk/javascript/src/types.ts b/sdk/javascript/src/types.ts
index ebabff0d7..2b527755e 100644
--- a/sdk/javascript/src/types.ts
+++ b/sdk/javascript/src/types.ts
@@ -960,6 +960,25 @@ export interface WebhookTestResult {
error?: string;
}
+/** A webhook delivery abandoned after every retry, as listed by the delivery-failure log. */
+export interface WebhookDeliveryFailure {
+ id: string;
+ webhookId: string;
+ sessionId: string;
+ event: string;
+ url: string;
+ /** The idempotency key the receiver would have deduped on. */
+ idempotencyKey?: string | null;
+ deliveryId?: string | null;
+ /** Total attempts made before giving up. */
+ attempts: number;
+ /** Last HTTP status when the failure was a non-2xx response; null for a network or timeout error. */
+ lastStatusCode?: number | null;
+ lastError: string;
+ /** ISO timestamp of when the delivery was finally abandoned. */
+ createdAt: string;
+}
+
// ── Chat (session-scoped chat operations) ─────────────────────────
export interface ChatSummary {
diff --git a/sdk/php/src/Resources/WebhooksResource.php b/sdk/php/src/Resources/WebhooksResource.php
index e68a5abdb..bff8fdd2d 100644
--- a/sdk/php/src/Resources/WebhooksResource.php
+++ b/sdk/php/src/Resources/WebhooksResource.php
@@ -39,7 +39,10 @@ class WebhooksResource
*
* @param array<string,mixed> $query Optional filter: `sessionId`, `limit`, `offset`.
*
- * @return mixed the response has no published schema, so it is returned unshaped
+ * @return array<int,array<string,mixed>> most recent first; each entry carries `id`, `webhookId`,
+ * `sessionId`, `event`, `url`, `attempts`, `lastError` and
+ * `createdAt`, plus nullable `idempotencyKey`, `deliveryId`
+ * and `lastStatusCode`
*/
public function deliveryFailures(array $query = [])
{
diff --git a/sdk/python/openwa/resources/webhooks.py b/sdk/python/openwa/resources/webhooks.py
index 53ad91e39..3d4907177 100644
--- a/sdk/python/openwa/resources/webhooks.py
+++ b/sdk/python/openwa/resources/webhooks.py
@@ -5,10 +5,16 @@ Backed by ``src/modules/webhook/webhook.controller.ts``.
from __future__ import annotations
-from typing import Any, TYPE_CHECKING, TypedDict
+from typing import TYPE_CHECKING, TypedDict
from .._http import quote_segment
-from ..types import CreateWebhookRequest, UpdateWebhookRequest, WebhookResponse, WebhookTestResult
+from ..types import (
+ CreateWebhookRequest,
+ UpdateWebhookRequest,
+ WebhookDeliveryFailure,
+ WebhookResponse,
+ WebhookTestResult,
+)
if TYPE_CHECKING:
from .._http import HttpExecutor
@@ -38,11 +44,11 @@ class WebhooksResource:
"""
return self._http.request("GET", "/api/webhooks", query=query)
- def delivery_failures(self, query: DeliveryFailureQuery | None = None) -> Any:
+ def delivery_failures(self, query: DeliveryFailureQuery | None = None) -> list[WebhookDeliveryFailure]:
"""Deliveries that were ATTEMPTED and failed -- the diagnostic for a webhook that stopped arriving.
- Requires an ADMIN-level key. A delivery a smart filter suppressed never reaches this log. The
- response has no published schema, so it is returned unshaped.
+ Requires an ADMIN-level key. A delivery a smart filter suppressed never reaches this log. Most
+ recent first.
"""
return self._http.request("GET", "/api/webhooks/delivery-failures", query=query)
diff --git a/sdk/python/openwa/types.py b/sdk/python/openwa/types.py
index 2edb29d41..08ffcefa2 100644
--- a/sdk/python/openwa/types.py
+++ b/sdk/python/openwa/types.py
@@ -933,6 +933,26 @@ class WebhookTestResult(TypedDict, total=False):
error: str
+class WebhookDeliveryFailure(TypedDict):
+ """A webhook delivery abandoned after every retry, as listed by the delivery-failure log."""
+
+ id: str
+ webhookId: str
+ sessionId: str
+ event: str
+ url: str
+ # The idempotency key the receiver would have deduped on.
+ idempotencyKey: NotRequired[str | None]
+ deliveryId: NotRequired[str | None]
+ # Total attempts made before giving up.
+ attempts: int
+ # Last HTTP status when the failure was a non-2xx response; None for a network or timeout error.
+ lastStatusCode: NotRequired[int | None]
+ lastError: str
+ # ISO timestamp of when the delivery was finally abandoned.
+ createdAt: str
+
+
# ── Chat ──────────────────────────────────────────────────────────