telegram-bot.mdx 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. ---
  2. title: Telegram Bot
  3. description: Connect a Telegram bot to 3x-ui for commands, periodic reports, event alerts (login, CPU, node up/down), backups, and client self-service.
  4. icon: Send
  5. ---
  6. 3x-ui can drive a Telegram bot for monitoring, alerts, backups, and remote
  7. management. Admins get full control; regular users (linked by Telegram ID) can
  8. check their own usage and links.
  9. <Callout type="info">
  10. Looking for news and community support? Join the official Telegram channel
  11. [@XrayUI](https://t.me/XrayUI). That's separate from the bot below, which you
  12. run yourself to manage your own panel.
  13. </Callout>
  14. ## Set it up
  15. <Steps>
  16. <Step>
  17. ### Create a bot
  18. Message [@BotFather](https://t.me/BotFather), send `/newbot`, and copy the **bot
  19. token**.
  20. </Step>
  21. <Step>
  22. ### Find your Telegram ID
  23. Get your numeric Telegram user ID (the bot's own `/id` command reports it once
  24. connected). This is your **admin** ID.
  25. </Step>
  26. <Step>
  27. ### Configure the panel
  28. In Panel Settings, enable the Telegram bot and set the **token** and **admin chat
  29. ID(s)** (comma-separated). Save, then message your bot.
  30. </Step>
  31. </Steps>
  32. Validate your token, admin IDs, and report schedule before pasting them into the
  33. panel:
  34. <TelegramSetupHelper />
  35. ## Commands
  36. These appear in the Telegram command menu: `/start`, `/help`, `/status`, `/id`.
  37. Additional commands:
  38. | Command | Who | Action |
  39. | ------------------ | ------ | ------------------------------------------------------------ |
  40. | `/start` | anyone | Greeting and the menu of inline buttons; an unlinked account gets only its Telegram ID |
  41. | `/help` | both | The menu of inline buttons |
  42. | `/status` | both | Confirm the bot is alive |
  43. | `/id` | anyone | Show your Telegram numeric ID |
  44. | `/usage <arg>` | both | Admins search clients; users look up their own usage |
  45. | `/inbound <remark>`| admin | Show an inbound's details |
  46. | `/restart` | admin | Restart Xray |
  47. A user is a Telegram account linked to at least one client. Any other account
  48. can run only `/start` and `/id`; the bot ignores its other commands and
  49. button taps. To link a customer, tap **Invite Link** on the client's card in the bot and
  50. send them the `t.me` link: the first account to open it is linked to every
  51. client that shares that Subscription ID. The Subscription ID is the invite code,
  52. so keep it long and random. Each account gets five claim attempts an hour, and
  53. admins are notified when one runs out.
  54. Admins also get inline-button flows for server usage, sorted traffic reports,
  55. resetting traffic, DB backups, ban logs, listing inbounds/clients, online
  56. clients, "depleting soon", and a full **add-client** wizard. Regular users get
  57. buttons for their own usage, subscription links, individual links, and QR codes.
  58. ## Reports & alerts
  59. - **Periodic report** — on the `tgRunTime` schedule (default `@daily`), the bot
  60. sends admins server usage (host, versions, uptime, load, memory, online
  61. clients, traffic), a list of exhausted/expiring clients, and — if
  62. `tgBotBackup` is on — a database + Xray config backup. Clients linked by
  63. Telegram ID get their own expiry/quota warnings.
  64. - **Event alerts** — selected by `tgEnabledEvents` (default `login.attempt,cpu.high`):
  65. | Event | When |
  66. | --------------- | ------------------------------------------------------- |
  67. | `login.attempt` | A panel login succeeds or fails (with IP and username) |
  68. | `cpu.high` | CPU exceeds `tgCpu` percent (default 80) |
  69. | `memory.high` | Memory exceeds `tgMemory` percent (default 80) |
  70. | `xray.crash` | Xray-core crashes |
  71. | `outbound.down` / `outbound.up` | An outbound goes down / recovers |
  72. | `node.down` / `node.up` | A node goes offline / comes back |
  73. The warning lead times come from `expireDiff` (days before expiry) and
  74. `trafficDiff` (GB of quota remaining); both default to `0` (off).
  75. ## Settings
  76. | Setting | Default | Meaning |
  77. | -------------- | -------------------------- | ---------------------------------------------- |
  78. | `tgBotEnable` | `false` | Master on/off. |
  79. | `tgBotToken` | _(secret)_ | Bot API token. |
  80. | `tgBotChatId` | _(none)_ | Comma-separated **admin** Telegram IDs. |
  81. | `tgBotProxy` | _(none)_ | `socks5://`, `http://`, or `https://` proxy. |
  82. | `tgBotAPIServer` | _(default)_ | Custom Telegram Bot API server. |
  83. | `tgRunTime` | `@daily` | Report schedule (cron / `@daily` / `@every …`).|
  84. | `tgBotBackup` | `false` | Attach a DB backup to the periodic report. |
  85. | `tgCpu` / `tgMemory` | `80` / `80` | CPU / memory alert thresholds (percent). |
  86. | `tgLang` | `en-US` | Bot language. |
  87. | `tgEnabledEvents` | `login.attempt,cpu.high`| Which events to deliver. |
  88. <Callout type="warn">
  89. The bot token controls your bot — keep it secret and only add **trusted** admin
  90. chat IDs. Login alerts never include passwords.
  91. </Callout>
  92. <Callout type="info">
  93. Email (SMTP) notifications mirror the same events (`smtpEnabledEvents`) if you'd
  94. rather receive alerts by email — configure SMTP in Panel Settings.
  95. </Callout>