[GH-ISSUE #5453] [Bug]: telegram bot send mass spam messages regarding a user's account expiration date #3815

Closed
opened 2026-10-31 20:35:09 +07:00 by bsakaguchi · 2 comments
Owner

Originally created by @vrcher on GitHub (Jun 20, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5453

Describe the bug

When the Telegram bot sends me a notification with a report on the server and the dashboard, duplicate messages appear.
Clients whose subscriptions are about to expire receive a message as many times as the number of linked incoming connections they have.
For example, if client “user1” has 15 incoming connections, that means at midnight I’ll receive 15 messages—one for each user—stating that their subscription is about to expire. This is extremely inconvenient; I don’t need multiple identical messages for a single user, regardless of how many nodes or connections they have.

How to reproduce the problem

Create a user
Add 5 connections to the user
Set the expiration period to 1 day
Check the Telegram message based on your notification settings in the dashboard
Receive 5 messages notifying you that the expiration period is ending

Expected behavior

1 message and 1 button for the user

Image

Actual behavior

mass spam messages regarding a user's account expiration date

Relevant logs


Screenshots

Image Image

3x-ui version

3.3.1

Xray-core version

26.6.1

How did you install 3x-ui?

install.sh script

Operating system

Ubuntu 22.04

Which parts of the panel are affected?

Telegram bot

Browser (only if it is a UI bug)

No response

Is the panel behind a reverse proxy or CDN?

None

Before submitting

  • I searched existing issues and this bug has not been reported.
  • I am running the latest released version of 3x-ui (or have verified the bug still exists on it).
  • This bug report is written in English.
  • I have redacted any sensitive data (tokens, real domains, client UUIDs).
Originally created by @vrcher on GitHub (Jun 20, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5453 ### Describe the bug When the Telegram bot sends me a notification with a report on the server and the dashboard, duplicate messages appear. Clients whose subscriptions are about to expire receive a message as many times as the number of linked incoming connections they have. For example, if client “user1” has 15 incoming connections, that means at midnight I’ll receive 15 messages—one for each user—stating that their subscription is about to expire. This is extremely inconvenient; I don’t need multiple identical messages for a single user, regardless of how many nodes or connections they have. ### How to reproduce the problem Create a user Add 5 connections to the user Set the expiration period to 1 day Check the Telegram message based on your notification settings in the dashboard Receive 5 messages notifying you that the expiration period is ending ### Expected behavior 1 message and 1 button for the user <img width="398" height="506" alt="Image" src="https://github.com/user-attachments/assets/ff1cc8c6-0e77-473c-bd3a-65fc25a9b5a0" /> ### Actual behavior mass spam messages regarding a user's account expiration date ### Relevant logs ```shell ``` ### Screenshots <img width="397" height="845" alt="Image" src="https://github.com/user-attachments/assets/2964182f-0160-4b5f-a58a-5b7f70d9efc6" /> <img width="423" height="721" alt="Image" src="https://github.com/user-attachments/assets/f3b07f01-a2d3-4b8a-a28b-9cd0382cfebe" /> ### 3x-ui version 3.3.1 ### Xray-core version 26.6.1 ### How did you install 3x-ui? install.sh script ### Operating system Ubuntu 22.04 ### Which parts of the panel are affected? Telegram bot ### Browser (only if it is a UI bug) _No response_ ### Is the panel behind a reverse proxy or CDN? None ### Before submitting - [x] I searched [existing issues](../issues?q=is%3Aissue) and this bug has not been reported. - [x] I am running the latest released version of 3x-ui (or have verified the bug still exists on it). - [x] This bug report is written in English. - [x] I have redacted any sensitive data (tokens, real domains, client UUIDs).
bsakaguchi 2026-10-31 20:35:09 +07:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@github-actions[bot] commented on GitHub (Jun 20, 2026):

The duplicate notifications are a confirmed bug in internal/web/service/tgbot/tgbot_report.go.

Root cause

ClientTraffic rows in the database have a UNIQUE constraint on email (client_traffic.go line 9), so there is only one traffic row per client email regardless of how many inbounds the client belongs to. GORM loads this row on the inbound that "owns" it (by InboundId). To make the UI reflect multi-inbound membership correctly, GetAllInbounds() calls enrichClientStats() → backfillClientStats(), which appends that same row to the ClientStats slice of every inbound the client is listed in.

In getExhausted() (the periodic admin report, lines 186–281), the code then walks all inbounds returned by GetAllInbounds() and accumulates every entry it finds in inbound.ClientStats into a flat exhaustedClients slice — with no email-based deduplication. A client in N inbounds therefore appears N times in that slice, and N entries are written into the output string.

SendMsgToTgbot() (line 95 in tgbot_send.go) splits any message longer than 2 000 characters on \r\n\r\n boundaries and sends each chunk as a separate Telegram message. Because clientInfoMsg appends \r\n after every field and the outer loop adds another \r\n after each entry, consecutive entries are separated by \r\n\r\n — exactly the split delimiter. Once the total output exceeds 2 000 characters the repeated entries become separate Telegram messages, one per inbound the client belongs to.

Which function is affected

getExhausted() — the admin notification. The client-facing path (notifyExhausted()) is not affected because it deduplicates by Telegram chat ID using the chatIDsDone slice (line 302), ensuring each Telegram account receives at most one message per report cycle regardless of how many inbounds its email appears in.

Workaround until a fix is released

There is no safe runtime workaround. To reduce the immediate noise you can lower the "Expire Diff" threshold in Telegram bot settings so fewer clients qualify, but this only reduces the volume of duplicates, not the duplication itself.

Suggested fix

Add email-based deduplication when building exhaustedClients in getExhausted():

// in getExhausted(), before the inbounds loop builds exhaustedClients:
seenEmails := make(map[string]struct{})
// then inside the ClientStats loop, replace the append with:
if _, already := seenEmails[client.Email]; \!already {
    exhaustedClients = append(exhaustedClients, client)
    seenEmails[client.Email] = struct{}{}
}

The same guard should be applied to disabledClients to prevent duplicate entries there as well.

Versions confirmed affected: v3.3.1 (latest as of this triage).

This response was generated automatically; a maintainer may follow up.

<!-- gh-comment-id:4759681663 --> @github-actions[bot] commented on GitHub (Jun 20, 2026): The duplicate notifications are a confirmed bug in `internal/web/service/tgbot/tgbot_report.go`. **Root cause** `ClientTraffic` rows in the database have a `UNIQUE` constraint on `email` (`client_traffic.go` line 9), so there is only one traffic row per client email regardless of how many inbounds the client belongs to. GORM loads this row on the inbound that "owns" it (by `InboundId`). To make the UI reflect multi-inbound membership correctly, `GetAllInbounds()` calls `enrichClientStats()` → `backfillClientStats()`, which appends that same row to the `ClientStats` slice of *every* inbound the client is listed in. In `getExhausted()` (the periodic admin report, lines 186–281), the code then walks all inbounds returned by `GetAllInbounds()` and accumulates every entry it finds in `inbound.ClientStats` into a flat `exhaustedClients` slice — with no email-based deduplication. A client in N inbounds therefore appears N times in that slice, and N entries are written into the output string. `SendMsgToTgbot()` (line 95 in `tgbot_send.go`) splits any message longer than 2 000 characters on `\r\n\r\n` boundaries and sends each chunk as a separate Telegram message. Because `clientInfoMsg` appends `\r\n` after every field and the outer loop adds another `\r\n` after each entry, consecutive entries are separated by `\r\n\r\n` — exactly the split delimiter. Once the total output exceeds 2 000 characters the repeated entries become separate Telegram messages, one per inbound the client belongs to. **Which function is affected** `getExhausted()` — the admin notification. The client-facing path (`notifyExhausted()`) is not affected because it deduplicates by Telegram chat ID using the `chatIDsDone` slice (line 302), ensuring each Telegram account receives at most one message per report cycle regardless of how many inbounds its email appears in. **Workaround until a fix is released** There is no safe runtime workaround. To reduce the immediate noise you can lower the "Expire Diff" threshold in Telegram bot settings so fewer clients qualify, but this only reduces the volume of duplicates, not the duplication itself. **Suggested fix** Add email-based deduplication when building `exhaustedClients` in `getExhausted()`: ```go // in getExhausted(), before the inbounds loop builds exhaustedClients: seenEmails := make(map[string]struct{}) // then inside the ClientStats loop, replace the append with: if _, already := seenEmails[client.Email]; \!already { exhaustedClients = append(exhaustedClients, client) seenEmails[client.Email] = struct{}{} } ``` The same guard should be applied to `disabledClients` to prevent duplicate entries there as well. **Versions confirmed affected:** v3.3.1 (latest as of this triage). *This response was generated automatically; a maintainer may follow up.*
Author
Owner

@MHSanaei commented on GitHub (Jun 20, 2026):

Fixed in 1259c20e.

Root cause: a client linked to multiple inbounds has one ClientStats row per inbound, all sharing the same email. The admin's exhausted/expiration report (getExhausted) appended every row, so a user on 15 inbounds was listed 15 times — 15 info blocks and 15 buttons — which Telegram split into multiple messages, appearing as spam.

The report now deduplicates by email, so each client is reported exactly once regardless of how many inbounds carry them. (The per-client notification path already deduped by email, so only the admin report was affected.)

<!-- gh-comment-id:4759788579 --> @MHSanaei commented on GitHub (Jun 20, 2026): Fixed in 1259c20e. Root cause: a client linked to multiple inbounds has one `ClientStats` row per inbound, all sharing the same email. The admin's exhausted/expiration report (`getExhausted`) appended every row, so a user on 15 inbounds was listed 15 times — 15 info blocks and 15 buttons — which Telegram split into multiple messages, appearing as spam. The report now deduplicates by email, so each client is reported exactly once regardless of how many inbounds carry them. (The per-client notification path already deduped by email, so only the admin report was affected.)
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#3815
No description provided.