[GH-ISSUE #6354] [Feature]: Add webhook event for successful client Auto Renew #4309

Open
opened 2026-10-31 20:38:44 +07:00 by bsakaguchi · 2 comments
Owner

Originally created by @Lemirda on GitHub (Aug 28, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6354

3X-UI currently supports automatic client renewal, but there is no way to receive an external notification when an auto-renewal is successfully performed.

This makes it difficult to synchronize 3X-UI with external systems such as billing systems, subscription management services, statistics dashboards, CRM systems, or custom APIs.

For example, when a client's subscription is automatically renewed, an external service may need to know that:
the renewal was successfully completed;
the client's expiration date has changed;
the traffic quota has been reset;
the client is active again.

At the moment, this requires periodically polling the 3X-UI API or implementing custom scripts that independently monitor client expiration dates.

Describe the solution you'd like

Add a configurable third-party webhook that can be triggered when a client's Auto Renew operation is successfully completed.

The panel should send an HTTP POST request to the configured webhook URL after the renewal has actually been completed successfully.

For example:

{
"event": "client_auto_renew",
"timestamp": 1756422000,
"client": {
"email": "user@example.com",
"uuid": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"inbound_id": 1,
"inbound_tag": "inbound-443"
},
"renewal": {
"auto_renew_days": 30,
"previous_expiry_time": 1756422000000,
"new_expiry_time": 1759014000000
}
}

The exact payload structure can be discussed, but it would be useful to provide at least:

event type;
timestamp;
client email/identifier;
inbound identifier;
previous expiration time;
new expiration time;
Auto Renew period;
optionally, whether traffic was reset and the client was re-enabled.

Ideally, the webhook system should support:

configurable webhook URL;
HTTP POST;
JSON payload;
optional secret/token for authentication;
configurable events;
retry on temporary delivery failures;
logging of webhook delivery status.

The webhook should only be triggered after a successful Auto Renew operation, not merely when the renewal process is attempted.

Alternatives you've considered

The current alternatives are:

Periodically polling the 3X-UI API and comparing client expiration dates.
Running an external cron job that monitors clients and tries to determine when Auto Renew occurred.
Modifying or wrapping the existing Auto Renew logic with a custom script.

All of these approaches are less reliable than having 3X-UI emit an event directly when the renewal actually happens.

A native webhook would also avoid unnecessary API polling and make integration with external billing and subscription systems much easier.

Concrete use case

No response

Mockups, screenshots, or examples

This feature would complement the existing Auto Renew functionality and the broader request for third-party webhooks.

It could also be implemented as part of a general event-based webhook system, for example:

client_created
client_deleted
client_updated
client_auto_renew
client_expired
client_disabled
client_enabled
traffic_limit_reached

For this feature request, however, the main requirement is the client_auto_renew event.

The most important requirement is that the webhook is sent only after the Auto Renew operation has been successfully applied to the client.

Which parts of the panel would this affect?

Backend (API endpoints, login, settings)

Are you willing to help?

  • I'd like to implement this feature myself and open a PR.
  • I can help test once a PR is open.

Before submitting

  • I searched existing issues and this feature has not been requested.
  • This feature request is written in English.
Originally created by @Lemirda on GitHub (Aug 28, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6354 ### Is your feature request related to a problem? 3X-UI currently supports automatic client renewal, but there is no way to receive an external notification when an auto-renewal is successfully performed. This makes it difficult to synchronize 3X-UI with external systems such as billing systems, subscription management services, statistics dashboards, CRM systems, or custom APIs. For example, when a client's subscription is automatically renewed, an external service may need to know that: the renewal was successfully completed; the client's expiration date has changed; the traffic quota has been reset; the client is active again. At the moment, this requires periodically polling the 3X-UI API or implementing custom scripts that independently monitor client expiration dates. ### Describe the solution you'd like Add a configurable third-party webhook that can be triggered when a client's Auto Renew operation is successfully completed. The panel should send an HTTP POST request to the configured webhook URL after the renewal has actually been completed successfully. For example: { "event": "client_auto_renew", "timestamp": 1756422000, "client": { "email": "user@example.com", "uuid": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "inbound_id": 1, "inbound_tag": "inbound-443" }, "renewal": { "auto_renew_days": 30, "previous_expiry_time": 1756422000000, "new_expiry_time": 1759014000000 } } The exact payload structure can be discussed, but it would be useful to provide at least: event type; timestamp; client email/identifier; inbound identifier; previous expiration time; new expiration time; Auto Renew period; optionally, whether traffic was reset and the client was re-enabled. Ideally, the webhook system should support: configurable webhook URL; HTTP POST; JSON payload; optional secret/token for authentication; configurable events; retry on temporary delivery failures; logging of webhook delivery status. The webhook should only be triggered after a successful Auto Renew operation, not merely when the renewal process is attempted. ### Alternatives you've considered The current alternatives are: Periodically polling the 3X-UI API and comparing client expiration dates. Running an external cron job that monitors clients and tries to determine when Auto Renew occurred. Modifying or wrapping the existing Auto Renew logic with a custom script. All of these approaches are less reliable than having 3X-UI emit an event directly when the renewal actually happens. A native webhook would also avoid unnecessary API polling and make integration with external billing and subscription systems much easier. ### Concrete use case _No response_ ### Mockups, screenshots, or examples This feature would complement the existing Auto Renew functionality and the broader request for third-party webhooks. It could also be implemented as part of a general event-based webhook system, for example: client_created client_deleted client_updated client_auto_renew client_expired client_disabled client_enabled traffic_limit_reached For this feature request, however, the main requirement is the client_auto_renew event. The most important requirement is that the webhook is sent only after the Auto Renew operation has been successfully applied to the client. ### Which parts of the panel would this affect? Backend (API endpoints, login, settings) ### Are you willing to help? - [ ] I'd like to implement this feature myself and open a PR. - [x] I can help test once a PR is open. ### Before submitting - [x] I searched [existing issues](../issues?q=is%3Aissue) and this feature has not been requested. - [x] This feature request is written in English.
Author
Owner

@github-actions[bot] commented on GitHub (Aug 28, 2026):

Valid feature request — nothing in the panel covers it today. There is no webhook or HTTP-callback mechanism for any client lifecycle event, and auto-renew in particular emits nothing outside the panel: not to the event bus, not to Telegram, not to e-mail. A case-insensitive webhook search over the Go tree returns zero hits (the webhook in frontend/src/schemas/routing.ts:8 is RuleWebhookSchema, Xray-core's routing failover webhook, unrelated to panel notifications).

What exists today, and why none of it substitutes

1. The event bus has a fixed set of eight types, all infrastructure-level — internal/eventbus/events.go:8-26:

EventOutboundDown / EventOutboundUp / EventXrayCrash /
EventNodeDown / EventNodeUp / EventCPUHigh / EventMemoryHigh / EventLoginAttempt

No client lifecycle event exists at all, so client_auto_renew — and the rest of the list in your last section — would be new event types, not just a new sink.

2. Its only two sinks are Telegram and e-mail. internal/web/service/tgbot/tgbot_event.go and internal/web/service/email/subscriber.go:33, each filtered by a comma-separated setting (tgEnabledEvents / smtpEnabledEvents, defaults at internal/web/service/setting.go:159-160). There is no HTTP sink.

3. The one outbound POST the panel already makes cannot express a renewal. That is the traffic-inform hook — externalTrafficInformEnable + externalTrafficInformURI (internal/web/service/setting.go:933-947), fired from internal/web/job/xray_traffic_job.go:103-104. Its body is built at xray_traffic_job.go:241:

requestBody, err := json.Marshal(map[string]any{"clientTraffics": clientTraffics, "inboundTraffics": inboundTraffics})

and those clientTraffics are the raw Xray gRPC deltas, constructed in internal/xray/api.go:881 as traffic = &ClientTraffic{Email: email} with only Up/Down filled in afterwards. expiryTime, reset and resetCount are always zero in that payload, so it cannot be used to detect an auto-renew either.

Where the event would have to come from

InboundService.autoRenewClients (internal/web/service/inbound_traffic.go:330) already computes every field you asked for, and already separates the renewals that succeeded from the candidates that were merely considered:

  • previous expiry: traffic.ExpiryTime as read at :434, before the new value is computed
  • new expiry and the number of periods applied: :459-461 (c["expiryTime"] = newExpiryTime, traffic.ResetCount += renewals)
  • re-enabled flag: :471-472 (if !traffic.Enable { traffic.Enable = true)
  • the successful set: renewedEmails = append(renewedEmails, email) at :470 — reached only after the quota reset at :468, and deliberately skipped for a client whose prepaid cap ran out mid-catch-up (:462-467)

Two constraints for whoever implements it, both visible in the same file:

  • Emitting from inside autoRenewClients would not satisfy your "only after a successful renew" requirement: it runs inside a transaction (:62) that can still roll back afterwards — :94-97 logs traffic lifecycle maintenance failed after traffic commit and swallows the whole batch. The established pattern for post-commit side effects here is trafficMutationBatch → applyTrafficMutationBatch (:98, internal/web/service/inbound_traffic_apply.go:60).
  • Multi-node: the selection query filters Where("i.node_id IS NULL") (:350), so a master panel renews only its own local clients. A node's clients are renewed by that node's panel, which is where its webhook would fire.

A configurable URL should reuse the existing SSRF guard service.SanitizePublicHTTPURL (internal/web/service/url_safety.go:44), the way the traffic-inform URI does at xray_traffic_job.go:236.

Relationship to #5727

#5727 ("Supports third-party webhooks") is the open umbrella request for the generic HTTP sink, still unimplemented. I am not closing this as a duplicate: #5727 asks for new subscriptions / online alerts / traffic usage, none of which is client_auto_renew, and that event does not exist on the bus at all — so this request adds a piece #5727 does not cover. A maintainer may still choose to fold the two together.

A more reliable poll than comparing expiry dates, until then

resetCount is a monotonic counter incremented by exactly the number of renewal periods applied (inbound_traffic.go:461). It therefore distinguishes an auto-renew from a manual expiry edit, and it survives a missed poll — an expiry-date comparison does neither.

  • one client: GET /panel/api/clients/traffic/{email} returns the full traffic row (internal/web/controller/client.go:597-605), with resetCount, expiryTime, up, down, uuid and subId
  • all clients: GET /panel/api/clients/list/paged embeds that same row per client under traffic (internal/web/service/client_paging.go:34 and :466)

Treat "resetCount increased" as the renewal signal, and read the new expiryTime from the same response.

Verdict: Feature request

This reply was generated automatically by an AI agent. A maintainer may follow up.

<!-- gh-comment-id:5458350059 --> @github-actions[bot] commented on GitHub (Aug 28, 2026): Valid feature request — nothing in the panel covers it today. There is no webhook or HTTP-callback mechanism for any client lifecycle event, and auto-renew in particular emits nothing outside the panel: not to the event bus, not to Telegram, not to e-mail. A case-insensitive `webhook` search over the Go tree returns zero hits (the `webhook` in `frontend/src/schemas/routing.ts:8` is `RuleWebhookSchema`, Xray-core's routing failover webhook, unrelated to panel notifications). ## What exists today, and why none of it substitutes **1. The event bus has a fixed set of eight types, all infrastructure-level** — `internal/eventbus/events.go:8-26`: ```go EventOutboundDown / EventOutboundUp / EventXrayCrash / EventNodeDown / EventNodeUp / EventCPUHigh / EventMemoryHigh / EventLoginAttempt ``` No client lifecycle event exists at all, so `client_auto_renew` — and the rest of the list in your last section — would be new event types, not just a new sink. **2. Its only two sinks are Telegram and e-mail.** `internal/web/service/tgbot/tgbot_event.go` and `internal/web/service/email/subscriber.go:33`, each filtered by a comma-separated setting (`tgEnabledEvents` / `smtpEnabledEvents`, defaults at `internal/web/service/setting.go:159-160`). There is no HTTP sink. **3. The one outbound POST the panel already makes cannot express a renewal.** That is the traffic-inform hook — `externalTrafficInformEnable` + `externalTrafficInformURI` (`internal/web/service/setting.go:933-947`), fired from `internal/web/job/xray_traffic_job.go:103-104`. Its body is built at `xray_traffic_job.go:241`: ```go requestBody, err := json.Marshal(map[string]any{"clientTraffics": clientTraffics, "inboundTraffics": inboundTraffics}) ``` and those `clientTraffics` are the raw Xray gRPC deltas, constructed in `internal/xray/api.go:881` as `traffic = &ClientTraffic{Email: email}` with only `Up`/`Down` filled in afterwards. `expiryTime`, `reset` and `resetCount` are always zero in that payload, so it cannot be used to detect an auto-renew either. ## Where the event would have to come from `InboundService.autoRenewClients` (`internal/web/service/inbound_traffic.go:330`) already computes every field you asked for, and already separates the renewals that succeeded from the candidates that were merely considered: - previous expiry: `traffic.ExpiryTime` as read at `:434`, before the new value is computed - new expiry and the number of periods applied: `:459-461` (`c["expiryTime"] = newExpiryTime`, `traffic.ResetCount += renewals`) - re-enabled flag: `:471-472` (`if !traffic.Enable { traffic.Enable = true`) - the successful set: `renewedEmails = append(renewedEmails, email)` at `:470` — reached only after the quota reset at `:468`, and deliberately skipped for a client whose prepaid cap ran out mid-catch-up (`:462-467`) Two constraints for whoever implements it, both visible in the same file: - Emitting from inside `autoRenewClients` would *not* satisfy your "only after a successful renew" requirement: it runs inside a transaction (`:62`) that can still roll back afterwards — `:94-97` logs `traffic lifecycle maintenance failed after traffic commit` and swallows the whole batch. The established pattern for post-commit side effects here is `trafficMutationBatch` → `applyTrafficMutationBatch` (`:98`, `internal/web/service/inbound_traffic_apply.go:60`). - Multi-node: the selection query filters `Where("i.node_id IS NULL")` (`:350`), so a master panel renews only its own local clients. A node's clients are renewed by that node's panel, which is where its webhook would fire. A configurable URL should reuse the existing SSRF guard `service.SanitizePublicHTTPURL` (`internal/web/service/url_safety.go:44`), the way the traffic-inform URI does at `xray_traffic_job.go:236`. ## Relationship to #5727 #5727 ("Supports third-party webhooks") is the open umbrella request for the generic HTTP sink, still unimplemented. I am not closing this as a duplicate: #5727 asks for new subscriptions / online alerts / traffic usage, none of which is `client_auto_renew`, and that event does not exist on the bus at all — so this request adds a piece #5727 does not cover. A maintainer may still choose to fold the two together. ## A more reliable poll than comparing expiry dates, until then `resetCount` is a monotonic counter incremented by exactly the number of renewal periods applied (`inbound_traffic.go:461`). It therefore distinguishes an auto-renew from a manual expiry edit, and it survives a missed poll — an expiry-date comparison does neither. - one client: `GET /panel/api/clients/traffic/{email}` returns the full traffic row (`internal/web/controller/client.go:597-605`), with `resetCount`, `expiryTime`, `up`, `down`, `uuid` and `subId` - all clients: `GET /panel/api/clients/list/paged` embeds that same row per client under `traffic` (`internal/web/service/client_paging.go:34` and `:466`) Treat "`resetCount` increased" as the renewal signal, and read the new `expiryTime` from the same response. Verdict: Feature request *This reply was generated automatically by an AI agent. A maintainer may follow up.* <!-- claude-issue:analyst -->
Author
Owner

@Lemirda commented on GitHub (Aug 28, 2026):

I would also like to propose an additional option for this feature: a pre-renewal webhook that allows an external service to approve or reject the Auto Renew operation before it is actually performed.

The flow could be:

  1. 3X-UI determines that a client should be automatically renewed.
  2. Before modifying the client, 3X-UI sends a webhook such as client_auto_renew_before.
  3. The external service responds with something like:
{
  "allow": true
}
  1. If allow: true, 3X-UI proceeds with the Auto Renew operation.
  2. If allow: false, the Auto Renew operation is cancelled.
  3. After a successful renewal, 3X-UI can optionally send the existing proposed client_auto_renew webhook with the result of the operation.

For example:

3X-UI
  │
  │ POST client_auto_renew_before
  ▼
External API
  │
  │ { "allow": true }
  ▼
3X-UI → performs Auto Renew
  │
  │ POST client_auto_renew
  ▼
External API

This would be particularly useful for external billing/subscription systems. The external service could verify whether the user is actually eligible for renewal before 3X-UI extends the client's expiration time.

For security/reliability, the pre-renewal webhook could have a configurable timeout. If the external service does not respond within the timeout, the renewal could be denied by default.

The authorization response could initially be kept very simple (allow: true/false), without allowing the external service to modify the renewal parameters.

This would make the webhook system useful not only for notifications, but also for external authorization of Auto Renew.

<!-- gh-comment-id:5458417331 --> @Lemirda commented on GitHub (Aug 28, 2026): I would also like to propose an additional option for this feature: a **pre-renewal webhook** that allows an external service to approve or reject the Auto Renew operation before it is actually performed. The flow could be: 1. 3X-UI determines that a client should be automatically renewed. 2. Before modifying the client, 3X-UI sends a webhook such as `client_auto_renew_before`. 3. The external service responds with something like: ```json { "allow": true } ``` 4. If `allow: true`, 3X-UI proceeds with the Auto Renew operation. 5. If `allow: false`, the Auto Renew operation is cancelled. 6. After a successful renewal, 3X-UI can optionally send the existing proposed `client_auto_renew` webhook with the result of the operation. For example: ```text 3X-UI │ │ POST client_auto_renew_before ▼ External API │ │ { "allow": true } ▼ 3X-UI → performs Auto Renew │ │ POST client_auto_renew ▼ External API ``` This would be particularly useful for external billing/subscription systems. The external service could verify whether the user is actually eligible for renewal before 3X-UI extends the client's expiration time. For security/reliability, the pre-renewal webhook could have a configurable timeout. If the external service does not respond within the timeout, the renewal could be denied by default. The authorization response could initially be kept very simple (`allow: true/false`), without allowing the external service to modify the renewal parameters. This would make the webhook system useful not only for notifications, but also for **external authorization of Auto Renew**.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#4309
No description provided.