telegram-badge 1.1.2 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -11,13 +11,19 @@
11
11
 
12
12
  [![GitHub stars](https://img.shields.io/github/stars/chatman-media/telegram-badge?style=social)](https://github.com/chatman-media/telegram-badge)
13
13
  [![dev.to](https://img.shields.io/badge/dev.to-Article-0A0A0A.svg?style=flat&logo=dev.to)](https://dev.to/chatman-media/show-your-telegram-group-member-count-in-github-readme-46pl)
14
- [![X (Twitter)](https://img.shields.io/badge/Tweet-1DA1F2.svg?style=flat&logo=x&logoColor=white)](https://x.com/chatman_media/status/1947399700795244694)
14
+ [![X (Twitter)](https://img.shields.io/badge/Tweet-1DA1F2.svg?style=flat&logo=x&logoColor=white)](https://x.com/status/1947399700795244694)
15
15
 
16
16
  This project generates SVG badges with the current member count of your Telegram group. Perfect for displaying community activity in GitHub README files or on websites.
17
17
 
18
- ## 🚀 Demo
18
+ ## 🚀 Quick Start
19
19
 
20
- ![Telegram Group Members](https://telegram-badge.vercel.app/api/telegram-badge)
20
+ Just use URL parameters to generate badges for any Telegram channel or group:
21
+
22
+ ```
23
+ https://telegram-badge.vercel.app/api/telegram-badge?channelId=@your_channel
24
+ ```
25
+
26
+ ![Telegram Group Members](https://telegram-badge.vercel.app/api/telegram-badge?channelId=@timelinestudiochat)
21
27
 
22
28
  ---
23
29
 
@@ -30,63 +36,56 @@ This project generates SVG badges with the current member count of your Telegram
30
36
 
31
37
  ---
32
38
 
33
- ## 🛠 Installation
39
+ ## 🧩 Usage
34
40
 
35
- 1. Clone the repository:
41
+ ### Primary Method: URL Parameters (No Setup Required!)
36
42
 
37
- ```bash
38
- git clone https://github.com/chatman-media/telegram-badge.git
39
- cd telegram-badge
40
- ```
41
-
42
- 2. Install dependencies:
43
+ Simply add your Telegram channel/group ID to the URL:
43
44
 
44
- ```bash
45
- npm install
46
- # or
47
- bun install
45
+ ```markdown
46
+ ![Telegram Badge](https://telegram-badge.vercel.app/api/telegram-badge?channelId=@your_channel)
48
47
  ```
49
48
 
50
- 3. Create a .env file and add:
49
+ That's it! No deployment, no bot token needed.
51
50
 
52
- ```bash
53
- BOT_TOKEN=your_telegram_bot_token
54
- CHAT_ID=@your_group_username_or_chat_id
55
- ```
51
+ ### Alternative Method: Self-Hosted Deployment
56
52
 
57
- **Note:** For public groups/channels, the bot doesn't need to be added as a member. For private groups, the bot must be added to the group.
53
+ For advanced users who want to host their own instance:
58
54
 
59
- ## 🧪 Local Development
55
+ #### 1. Prerequisites
56
+ - Telegram Bot Token (create via [@BotFather](https://t.me/botfather))
57
+ - Vercel account (or any Node.js hosting)
60
58
 
61
- ```bash
62
- npm run dev
63
- # or
64
- bun dev
65
- ```
59
+ #### 2. Deploy to Vercel
66
60
 
67
- Open in browser: http://localhost:3000/api/telegram-badge
61
+ [![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fchatman-media%2Ftelegram-badge)
68
62
 
69
- ## ☁️ Deploy to Vercel
63
+ Set environment variables:
64
+ - `BOT_TOKEN`: Your Telegram bot token
65
+ - `CHAT_ID`: Default chat ID (optional if using URL parameters)
70
66
 
71
- 1. Deploy the repository to vercel.com
72
- 2. Add environment variables in project settings:
73
- - BOT_TOKEN
74
- - CHAT_ID
67
+ #### 3. Local Development
75
68
 
76
- ## 🧩 Usage in GitHub README
69
+ ```bash
70
+ git clone https://github.com/chatman-media/telegram-badge.git
71
+ cd telegram-badge
72
+ npm install
77
73
 
78
- Add the following line to your README.md:
74
+ # Create .env file
75
+ echo "BOT_TOKEN=your_bot_token" > .env
76
+ echo "CHAT_ID=@your_channel" >> .env
79
77
 
80
- ```markdown
81
- ![Telegram Group Badge](https://telegram-badge.vercel.app/api/telegram-badge)
78
+ npm run dev
82
79
  ```
83
80
 
81
+
84
82
  ### 🎨 Styling Parameters
85
83
 
86
84
  You can customize the badge appearance using the following parameters:
87
85
 
88
86
  | Parameter | Description | Default Value |
89
87
  |-----------|-------------|---------------|
88
+ | `channelId` | Telegram chat ID or username (e.g., ``) | From environment |
90
89
  | `style` | Badge style | `flat` |
91
90
  | `label` | Label text | `Telegram` |
92
91
  | `color` | Main badge color | `2AABEE` (Telegram color) |
@@ -105,60 +104,71 @@ You can customize the badge appearance using the following parameters:
105
104
 
106
105
  Standard badge (flat style):
107
106
  ```
108
- https://telegram-badge.vercel.app/api/telegram-badge
107
+ https://telegram-badge.vercel.app/api/telegram-badge?channelId=@your_channel
109
108
  ```
110
- ![Flat](https://telegram-badge.vercel.app/api/telegram-badge)
109
+ ![Flat](https://telegram-badge.vercel.app/api/telegram-badge?channelId=@timelinestudiochat)
111
110
 
112
111
  Badge with plastic style:
113
112
  ```
114
- https://telegram-badge.vercel.app/api/telegram-badge?style=plastic
113
+ https://telegram-badge.vercel.app/api/telegram-badge?channelId=@your_channel&style=plastic
115
114
  ```
116
- ![Plastic](https://telegram-badge.vercel.app/api/telegram-badge?style=plastic)
115
+ ![Plastic](https://telegram-badge.vercel.app/api/telegram-badge?channelId=@timelinestudiochat&style=plastic)
117
116
 
118
117
  Badge with flat-square style:
119
118
  ```
120
- https://telegram-badge.vercel.app/api/telegram-badge?style=flat-square
119
+ https://telegram-badge.vercel.app/api/telegram-badge?channelId=@your_channel&style=flat-square
121
120
  ```
122
- ![Flat-Square](https://telegram-badge.vercel.app/api/telegram-badge?style=flat-square)
121
+ ![Flat-Square](https://telegram-badge.vercel.app/api/telegram-badge?channelId=@timelinestudiochat&style=flat-square)
123
122
 
124
123
  Badge with for-the-badge style:
125
124
  ```
126
- https://telegram-badge.vercel.app/api/telegram-badge?style=for-the-badge
125
+ https://telegram-badge.vercel.app/api/telegram-badge?channelId=@your_channel&style=for-the-badge
127
126
  ```
128
- ![For-The-Badge](https://telegram-badge.vercel.app/api/telegram-badge?style=for-the-badge)
127
+ ![For-The-Badge](https://telegram-badge.vercel.app/api/telegram-badge?channelId=@timelinestudiochat&style=for-the-badge)
129
128
 
130
129
  Badge with social style:
131
130
  ```
132
- https://telegram-badge.vercel.app/api/telegram-badge?style=social
131
+ https://telegram-badge.vercel.app/api/telegram-badge?channelId=@your_channel&style=social
133
132
  ```
134
- ![Social](https://telegram-badge.vercel.app/api/telegram-badge?style=social)
133
+ ![Social](https://telegram-badge.vercel.app/api/telegram-badge?channelId=@timelinestudiochat&style=social)
135
134
 
136
135
  Badge with custom label and color:
137
136
  ```
138
- https://telegram-badge.vercel.app/api/telegram-badge?label=Join%20Chat&color=00FF00
137
+ https://telegram-badge.vercel.app/api/telegram-badge?channelId=@your_channel&label=Join%20Chat&color=00FF00
139
138
  ```
140
- ![Custom](https://telegram-badge.vercel.app/api/telegram-badge?label=Join%20Chat&color=00FF00)
139
+ ![Custom](https://telegram-badge.vercel.app/api/telegram-badge?channelId=@timelinestudiochat&label=Join%20Chat&color=00FF00)
141
140
 
142
141
  Fully customized badge:
143
142
  ```
144
- https://telegram-badge.vercel.app/api/telegram-badge?style=for-the-badge&label=Community&color=FF5733&labelColor=1A1A1A
143
+ https://telegram-badge.vercel.app/api/telegram-badge?channelId=@your_channel&style=for-the-badge&label=Community&color=FF5733&labelColor=1A1A1A
145
144
  ```
146
- ![Full Custom](https://telegram-badge.vercel.app/api/telegram-badge?style=for-the-badge&label=Community&color=FF5733&labelColor=1A1A1A)
145
+ ![Full Custom](https://telegram-badge.vercel.app/api/telegram-badge?channelId=@timelinestudiochat&style=for-the-badge&label=Community&color=FF5733&labelColor=1A1A1A)
147
146
 
148
147
  Badge without logo:
149
148
  ```
150
- https://telegram-badge.vercel.app/api/telegram-badge?logo=false
149
+ https://telegram-badge.vercel.app/api/telegram-badge?channelId=@your_channel&logo=false
150
+ ```
151
+ ![No Logo](https://telegram-badge.vercel.app/api/telegram-badge?channelId=@timelinestudiochat&logo=false)
152
+
153
+ Badge for specific channel:
154
+ ```
155
+ https://telegram-badge.vercel.app/api/telegram-badge?channelId=@your_channel
156
+ ```
157
+
158
+ Badge with custom styling:
159
+ ```
160
+ https://telegram-badge.vercel.app/api/telegram-badge?channelId=@your_channel&style=for-the-badge&color=FF5733
151
161
  ```
152
- ![No Logo](https://telegram-badge.vercel.app/api/telegram-badge?logo=false)
153
162
 
154
163
  ## ✨ Features
155
164
 
156
165
  - 👥 Real-time member count display
166
+ - 🔗 Direct URL parameters - no setup required!
157
167
  - 🎨 Full badge appearance customization
158
- - 🔒 Support for .env and Vercel environment variables for secure token storage
168
+ - 🔒 Optional self-hosting with secure token storage
159
169
  - ⚡ Optimized caching for fast loading
160
170
  - 🛡️ Error handling with informative messages
161
- - 🆓 Free on Vercel with normal usage
171
+ - 🆓 Free to use
162
172
  - 📡 Can be extended to show activity/message count
163
173
  - 🧪 Comprehensive test suite with TypeScript
164
174
 
@@ -203,14 +213,6 @@ Build the project:
203
213
  npm run build
204
214
  ```
205
215
 
206
- ## Subscribe
207
-
208
- [![TikTok](https://img.shields.io/badge/TikTok-000000?style=for-the-badge&logo=tiktok&logoColor=white&labelColor=1c1917)](https://www.tiktok.com/@chatman.media)
209
- [![twitch](https://img.shields.io/badge/Twitch-9146FF?style=for-the-badge&logo=twitch&logoColor=white&labelColor=1c1917)](https://www.twitch.tv/chatman1984)
210
- [![YouTube](https://img.shields.io/badge/YouTube-FF0000?style=for-the-badge&logo=youtube&logoColor=white&labelColor=1c1917)](https://www.youtube.com/@chatman-media)
211
- [![Telegram](https://img.shields.io/badge/Telegram-2CA5E0?style=for-the-badge&logo=telegram&logoColor=white&labelColor=1c1917)](https://t.me/alexanderkireyev)
212
- [![X](https://img.shields.io/badge/Twitter-000000?style=for-the-badge&logo=x&logoColor=white&labelColor=1c1917)](https://x.com/chatman_media)
213
-
214
216
  ## Star History
215
217
 
216
218
  <a href="https://www.star-history.com/#chatman-media/telegram-badge&Date">
@@ -229,6 +231,30 @@ npm run build
229
231
  4. Push to the branch (`git push origin feature/amazing-feature`)
230
232
  5. Open a Pull Request
231
233
 
234
+ ## Subscribe
235
+
236
+ [![TikTok](https://img.shields.io/badge/TikTok-000000?style=for-the-badge&logo=tiktok&logoColor=white&labelColor=1c1917)](https://www.tiktok.com/@chatman.media)
237
+ [![twitch](https://img.shields.io/badge/Twitch-9146FF?style=for-the-badge&logo=twitch&logoColor=white&labelColor=1c1917)](https://www.twitch.tv/chatman1984)
238
+ [![YouTube](https://img.shields.io/badge/YouTube-FF0000?style=for-the-badge&logo=youtube&logoColor=white&labelColor=1c1917)](https://www.youtube.com/@chatman-media)
239
+ [![Telegram](https://img.shields.io/badge/Telegram-2CA5E0?style=for-the-badge&logo=telegram&logoColor=white&labelColor=1c1917)](https://t.me/alexanderkireyev)
240
+ [![X](https://img.shields.io/badge/Twitter-000000?style=for-the-badge&logo=x&logoColor=white&labelColor=1c1917)](https://x.com)
241
+
242
+ ## Support 💝🚀
243
+
244
+ - **BTC:** 14s9Y9Rb2CUWHSAatiQMhfkpx1MWXofUzw
245
+ - **TON:** UQD1M80nPyzph5ZW1vfp_r19XI5MaerNhDq4dWXbXCo96WFj
246
+ - **NOT:** UQD1M80nPyzph5ZW1vfp_r19XI5MaerNhDq4dWXbXCo96WFj
247
+ - **ETH:** 0x286D65151b622dCC16624cEd8463FDa45585fd60
248
+
249
+ <div align="center">
250
+
251
+ <img src="public/btc.png" alt="BTC" style="height: 185px" />
252
+ <img src="public/ton.png" alt="TON" style="height: 185px" />
253
+ <img src="public/not.png" alt="NOT" style="height: 185px" />
254
+ <img src="public/eth.png" alt="ETH" style="height: 185px" />
255
+
256
+ </div>
257
+
232
258
  ## 📜 License
233
259
 
234
260
  This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
package/README.ru.md CHANGED
@@ -15,68 +15,67 @@
15
15
 
16
16
  Этот проект генерирует SVG-бейдж с текущим количеством участников вашей Telegram-группы. Идеально подходит для отображения активности сообщества в README на GitHub или на сайте.
17
17
 
18
- ## 🚀 Демо
18
+ ## 🚀 Быстрый старт
19
19
 
20
- ![Telegram Group Members](https://telegram-badge.vercel.app/api/telegram-badge)
20
+ Просто используйте параметры URL для генерации бейджей для любого Telegram-канала или группы:
21
+
22
+ ```
23
+ https://telegram-badge.vercel.app/api/telegram-badge?channelId=@your_channel
24
+ ```
25
+
26
+ ![Telegram Group Members](https://telegram-badge.vercel.app/api/telegram-badge?channelId=@timelinestudiochat)
21
27
 
22
28
  ---
23
29
 
24
30
  ## 📦 Стек
25
31
 
26
- - Node.js / Bun
32
+ - Node.js / TypeScript
27
33
  - Telegram Bot API
28
34
  - Vercel (Serverless API)
35
+ - Jest для тестирования
29
36
 
30
37
  ---
31
38
 
32
- ## 🛠 Установка
39
+ ## 🧩 Использование
33
40
 
34
- 1. Клонируйте репозиторий:
41
+ ### Основной метод: параметры URL (настройка не требуется!)
35
42
 
36
- ```bash
37
- git clone https://github.com/chatman-media/telegram-badge.git
38
- cd telegram-badge
39
- ```
40
-
41
- 2. Установите зависимости:
43
+ Просто добавьте ID вашего Telegram-канала/группы к URL:
42
44
 
43
- ```bash
44
- npm install
45
- # или
46
- bun install
45
+ ```markdown
46
+ ![Telegram Badge](https://telegram-badge.vercel.app/api/telegram-badge?channelId=@your_channel)
47
47
  ```
48
48
 
49
- 3. Создайте .env файл и добавьте:
49
+ Вот и всё! Не нужно разворачивать проект, не нужен токен бота.
50
50
 
51
- ```bash
52
- BOT_TOKEN=your_telegram_bot_token
53
- CHAT_ID=@your_group_username_or_chat_id
54
- ```
51
+ ### Альтернативный метод: самостоятельный хостинг
55
52
 
56
- **Примечание:** Для публичных групп/каналов бота не нужно добавлять в группу. Для приватных групп бот должен быть участником.
53
+ Для продвинутых пользователей, которые хотят развернуть собственный экземпляр:
57
54
 
58
- ## 🧪 Локальный запуск
55
+ #### 1. Предварительные требования
56
+ - Токен Telegram-бота (создайте через [@BotFather](https://t.me/botfather))
57
+ - Аккаунт Vercel (или любой хостинг Node.js)
59
58
 
60
- ```bash
61
- npm run dev
62
- # или
63
- bun dev
64
- ```
59
+ #### 2. Деплой на Vercel
60
+
61
+ [![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fchatman-media%2Ftelegram-badge)
65
62
 
66
- Открой в браузере: http://localhost:3000/api/telegram-badge
63
+ Установите переменные окружения:
64
+ - `BOT_TOKEN`: Токен вашего Telegram-бота
65
+ - `CHAT_ID`: ID чата по умолчанию (необязательно при использовании параметров URL)
67
66
 
68
- ## ☁️ Деплой на Vercel
69
- 1. Задеплойте репозиторий на vercel.com
70
- 2. В настройках проекта добавьте переменные окружения:
71
- • BOT_TOKEN
72
- • CHAT_ID
67
+ #### 3. Локальная разработка
73
68
 
74
- ## 🧩 Использование в GitHub README
69
+ ```bash
70
+ git clone https://github.com/chatman-media/telegram-badge.git
71
+ cd telegram-badge
72
+ npm install
75
73
 
76
- Добавьте следующую строку в ваш README.md:
74
+ # Создайте .env файл
75
+ echo "BOT_TOKEN=your_bot_token" > .env
76
+ echo "CHAT_ID=@your_channel" >> .env
77
77
 
78
- ```markdown
79
- ![Telegram Group Badge](https://telegram-badge.vercel.app/api/telegram-badge)
78
+ npm run dev
80
79
  ```
81
80
 
82
81
  ### 🎨 Параметры стилизации
@@ -85,6 +84,7 @@ bun dev
85
84
 
86
85
  | Параметр | Описание | Значение по умолчанию |
87
86
  |----------|----------|------------------------|
87
+ | `channelId` | ID или имя пользователя Telegram-чата (например, `@timelinestudiochat`) | Из окружения |
88
88
  | `style` | Стиль бейджа | `flat` |
89
89
  | `label` | Текст метки | `Telegram` |
90
90
  | `color` | Цвет основной части бейджа | `2AABEE` (цвет Telegram) |
@@ -103,61 +103,73 @@ bun dev
103
103
 
104
104
  Стандартный бейдж (стиль flat):
105
105
  ```
106
- https://telegram-badge.vercel.app/api/telegram-badge
106
+ https://telegram-badge.vercel.app/api/telegram-badge?channelId=@your_channel
107
107
  ```
108
- ![Flat](https://telegram-badge.vercel.app/api/telegram-badge)
108
+ ![Flat](https://telegram-badge.vercel.app/api/telegram-badge?channelId=@timelinestudiochat)
109
109
 
110
110
  Бейдж со стилем plastic:
111
111
  ```
112
- https://telegram-badge.vercel.app/api/telegram-badge?style=plastic
112
+ https://telegram-badge.vercel.app/api/telegram-badge?channelId=@your_channel&style=plastic
113
113
  ```
114
- ![Plastic](https://telegram-badge.vercel.app/api/telegram-badge?style=plastic)
114
+ ![Plastic](https://telegram-badge.vercel.app/api/telegram-badge?channelId=@timelinestudiochat&style=plastic)
115
115
 
116
116
  Бейдж со стилем flat-square:
117
117
  ```
118
- https://telegram-badge.vercel.app/api/telegram-badge?style=flat-square
118
+ https://telegram-badge.vercel.app/api/telegram-badge?channelId=@your_channel&style=flat-square
119
119
  ```
120
- ![Flat-Square](https://telegram-badge.vercel.app/api/telegram-badge?style=flat-square)
120
+ ![Flat-Square](https://telegram-badge.vercel.app/api/telegram-badge?channelId=@timelinestudiochat&style=flat-square)
121
121
 
122
122
  Бейдж со стилем for-the-badge:
123
123
  ```
124
- https://telegram-badge.vercel.app/api/telegram-badge?style=for-the-badge
124
+ https://telegram-badge.vercel.app/api/telegram-badge?channelId=@your_channel&style=for-the-badge
125
125
  ```
126
- ![For-The-Badge](https://telegram-badge.vercel.app/api/telegram-badge?style=for-the-badge)
126
+ ![For-The-Badge](https://telegram-badge.vercel.app/api/telegram-badge?channelId=@timelinestudiochat&style=for-the-badge)
127
127
 
128
128
  Бейдж со стилем social:
129
129
  ```
130
- https://telegram-badge.vercel.app/api/telegram-badge?style=social
130
+ https://telegram-badge.vercel.app/api/telegram-badge?channelId=@your_channel&style=social
131
131
  ```
132
- ![Social](https://telegram-badge.vercel.app/api/telegram-badge?style=social)
132
+ ![Social](https://telegram-badge.vercel.app/api/telegram-badge?channelId=@timelinestudiochat&style=social)
133
133
 
134
134
  Бейдж с кастомной меткой и цветом:
135
135
  ```
136
- https://telegram-badge.vercel.app/api/telegram-badge?label=Наш%20Чат&color=00FF00
136
+ https://telegram-badge.vercel.app/api/telegram-badge?channelId=@your_channel&label=Наш%20Чат&color=00FF00
137
137
  ```
138
- ![Custom](https://telegram-badge.vercel.app/api/telegram-badge?label=Наш%20Чат&color=00FF00)
138
+ ![Custom](https://telegram-badge.vercel.app/api/telegram-badge?channelId=@timelinestudiochat&label=Наш%20Чат&color=00FF00)
139
139
 
140
140
  Полностью кастомизированный бейдж:
141
141
  ```
142
- https://telegram-badge.vercel.app/api/telegram-badge?style=for-the-badge&label=Сообщество&color=FF5733&labelColor=1A1A1A
142
+ https://telegram-badge.vercel.app/api/telegram-badge?channelId=@your_channel&style=for-the-badge&label=Сообщество&color=FF5733&labelColor=1A1A1A
143
143
  ```
144
- ![Full Custom](https://telegram-badge.vercel.app/api/telegram-badge?style=for-the-badge&label=Сообщество&color=FF5733&labelColor=1A1A1A)
144
+ ![Full Custom](https://telegram-badge.vercel.app/api/telegram-badge?channelId=@timelinestudiochat&style=for-the-badge&label=Сообщество&color=FF5733&labelColor=1A1A1A)
145
145
 
146
146
  Бейдж без логотипа:
147
147
  ```
148
- https://telegram-badge.vercel.app/api/telegram-badge?logo=false
148
+ https://telegram-badge.vercel.app/api/telegram-badge?channelId=@your_channel&logo=false
149
149
  ```
150
- ![No Logo](https://telegram-badge.vercel.app/api/telegram-badge?logo=false)
150
+ ![No Logo](https://telegram-badge.vercel.app/api/telegram-badge?channelId=@timelinestudiochat&logo=false)
151
151
 
152
- ## 🧠 Возможности
152
+ Бейдж для конкретного канала:
153
+ ```
154
+ https://telegram-badge.vercel.app/api/telegram-badge?channelId=@your_channel
155
+ ```
156
+
157
+ Бейдж с пользовательским стилем:
158
+ ```
159
+ https://telegram-badge.vercel.app/api/telegram-badge?channelId=@your_channel&style=for-the-badge&color=FF5733
160
+ ```
161
+
162
+ ## ✨ Возможности
153
163
 
154
164
  - 👥 Отображение количества участников в реальном времени
165
+ - 🔗 Прямые параметры URL - настройка не требуется!
155
166
  - 🎨 Полная кастомизация внешнего вида бейджа
156
- - 🔒 Поддержка .env и переменных Vercel для безопасного хранения токенов
167
+ - 🔒 Опциональный самостоятельный хостинг с безопасным хранением токенов
157
168
  - ⚡ Оптимизированное кэширование для быстрой загрузки
158
169
  - 🛡️ Обработка ошибок с информативными сообщениями
159
- - 🆓 Бесплатно на Vercel при обычной нагрузке
170
+ - 🆓 Бесплатное использование
160
171
  - 📡 Можно расширить до отображения активности / количества сообщений
172
+ - 🧪 Полный набор тестов с TypeScript
161
173
 
162
174
  ## 🔧 Использование API
163
175
 
@@ -200,14 +212,6 @@ npm run type-check
200
212
  npm run build
201
213
  ```
202
214
 
203
- ## Подписывайтесь
204
-
205
- [![TikTok](https://img.shields.io/badge/TikTok-000000?style=for-the-badge&logo=tiktok&logoColor=white&labelColor=1c1917)](https://www.tiktok.com/@chatman.media)
206
- [![twitch](https://img.shields.io/badge/Twitch-9146FF?style=for-the-badge&logo=twitch&logoColor=white&labelColor=1c1917)](https://www.twitch.tv/chatman1984)
207
- [![YouTube](https://img.shields.io/badge/YouTube-FF0000?style=for-the-badge&logo=youtube&logoColor=white&labelColor=1c1917)](https://www.youtube.com/@chatman-media)
208
- [![Telegram](https://img.shields.io/badge/Telegram-2CA5E0?style=for-the-badge&logo=telegram&logoColor=white&labelColor=1c1917)](https://t.me/alexanderkireyev)
209
- [![X](https://img.shields.io/badge/Twitter-000000?style=for-the-badge&logo=x&logoColor=white&labelColor=1c1917)](https://x.com/chatman_media)
210
-
211
215
  ## История звёзд
212
216
 
213
217
  <a href="https://www.star-history.com/#chatman-media/telegram-badge&Date">
@@ -226,6 +230,30 @@ npm run build
226
230
  4. Отправьте ветку (`git push origin feature/amazing-feature`)
227
231
  5. Откройте Pull Request
228
232
 
233
+ ## Подписывайтесь
234
+
235
+ [![TikTok](https://img.shields.io/badge/TikTok-000000?style=for-the-badge&logo=tiktok&logoColor=white&labelColor=1c1917)](https://www.tiktok.com/@chatman.media)
236
+ [![twitch](https://img.shields.io/badge/Twitch-9146FF?style=for-the-badge&logo=twitch&logoColor=white&labelColor=1c1917)](https://www.twitch.tv/chatman1984)
237
+ [![YouTube](https://img.shields.io/badge/YouTube-FF0000?style=for-the-badge&logo=youtube&logoColor=white&labelColor=1c1917)](https://www.youtube.com/@chatman-media)
238
+ [![Telegram](https://img.shields.io/badge/Telegram-2CA5E0?style=for-the-badge&logo=telegram&logoColor=white&labelColor=1c1917)](https://t.me/alexanderkireyev)
239
+ [![X](https://img.shields.io/badge/Twitter-000000?style=for-the-badge&logo=x&logoColor=white&labelColor=1c1917)](https://x.com/timelinestudiochat)
240
+
241
+ ## Поддержка 💝🚀
242
+
243
+ - **BTC:** 14s9Y9Rb2CUWHSAatiQMhfkpx1MWXofUzw
244
+ - **TON:** UQD1M80nPyzph5ZW1vfp_r19XI5MaerNhDq4dWXbXCo96WFj
245
+ - **NOT:** UQD1M80nPyzph5ZW1vfp_r19XI5MaerNhDq4dWXbXCo96WFj
246
+ - **ETH:** 0x286D65151b622dCC16624cEd8463FDa45585fd60
247
+
248
+ <div align="center">
249
+
250
+ <img src="public/btc.png" alt="BTC" style="height: 185px" />
251
+ <img src="public/ton.png" alt="TON" style="height: 185px" />
252
+ <img src="public/not.png" alt="NOT" style="height: 185px" />
253
+ <img src="public/eth.png" alt="ETH" style="height: 185px" />
254
+
255
+ </div>
256
+
229
257
  ## 📜 Лицензия
230
258
 
231
259
  Этот проект лицензирован под лицензией MIT - подробности в файле [LICENSE](LICENSE).
package/README.zh.md CHANGED
@@ -15,9 +15,15 @@
15
15
 
16
16
  本项目生成显示 Telegram 群组当前成员数量的 SVG 徽章。非常适合在 GitHub README 文件或网站上展示社区活跃度。
17
17
 
18
- ## 🚀 演示
18
+ ## 🚀 快速开始
19
19
 
20
- ![Telegram 群组成员](https://telegram-badge.vercel.app/api/telegram-badge)
20
+ 只需使用 URL 参数即可为任何 Telegram 频道或群组生成徽章:
21
+
22
+ ```
23
+ https://telegram-badge.vercel.app/api/telegram-badge?channelId=@your_channel
24
+ ```
25
+
26
+ ![Telegram 群组成员](https://telegram-badge.vercel.app/api/telegram-badge?channelId=@timelinestudiochat)
21
27
 
22
28
  ---
23
29
 
@@ -30,63 +36,56 @@
30
36
 
31
37
  ---
32
38
 
33
- ## 🛠 安装
39
+ ## 🧩 使用方法
34
40
 
35
- 1. 克隆仓库:
41
+ ### 主要方法:URL 参数(无需任何设置!)
36
42
 
37
- ```bash
38
- git clone https://github.com/chatman-media/telegram-badge.git
39
- cd telegram-badge
40
- ```
41
-
42
- 2. 安装依赖:
43
+ 只需将您的 Telegram 频道/群组 ID 添加到 URL:
43
44
 
44
- ```bash
45
- npm install
46
- # 或
47
- bun install
45
+ ```markdown
46
+ ![Telegram Badge](https://telegram-badge.vercel.app/api/telegram-badge?channelId=@your_channel)
48
47
  ```
49
48
 
50
- 3. 创建 .env 文件并添加:
49
+ 就这样!无需部署,无需机器人令牌。
51
50
 
52
- ```bash
53
- BOT_TOKEN=your_telegram_bot_token
54
- CHAT_ID=@your_group_username_or_chat_id
55
- ```
51
+ ### 替代方法:自托管部署
56
52
 
57
- **注意:** 对于公开群组/频道,机器人无需添加为成员。对于私有群组,机器人必须是群组成员。
53
+ 对于想要托管自己实例的高级用户:
58
54
 
59
- ## 🧪 本地开发
55
+ #### 1. 先决条件
56
+ - Telegram 机器人令牌(通过 [@BotFather](https://t.me/botfather) 创建)
57
+ - Vercel 账户(或任何 Node.js 托管)
60
58
 
61
- ```bash
62
- npm run dev
63
- # 或
64
- bun dev
65
- ```
59
+ #### 2. 部署到 Vercel
66
60
 
67
- 在浏览器中打开:http://localhost:3000/api/telegram-badge
61
+ [![使用 Vercel 部署](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fchatman-media%2Ftelegram-badge)
68
62
 
69
- ## ☁️ 部署到 Vercel
63
+ 设置环境变量:
64
+ - `BOT_TOKEN`:您的 Telegram 机器人令牌
65
+ - `CHAT_ID`:默认聊天 ID(如果使用 URL 参数则可选)
70
66
 
71
- 1. 将仓库部署到 vercel.com
72
- 2. 在项目设置中添加环境变量:
73
- - BOT_TOKEN
74
- - CHAT_ID
67
+ #### 3. 本地开发
75
68
 
76
- ## 🧩 在 GitHub README 中使用
69
+ ```bash
70
+ git clone https://github.com/chatman-media/telegram-badge.git
71
+ cd telegram-badge
72
+ npm install
77
73
 
78
- 在您的 README.md 中添加以下代码:
74
+ # 创建 .env 文件
75
+ echo "BOT_TOKEN=your_bot_token" > .env
76
+ echo "CHAT_ID=@your_channel" >> .env
79
77
 
80
- ```markdown
81
- ![Telegram 群组徽章](https://telegram-badge.vercel.app/api/telegram-badge)
78
+ npm run dev
82
79
  ```
83
80
 
81
+
84
82
  ### 🎨 样式参数
85
83
 
86
84
  您可以使用以下参数自定义徽章外观:
87
85
 
88
86
  | 参数 | 描述 | 默认值 |
89
87
  |------|------|--------|
88
+ | `channelId` | Telegram 聊天 ID 或用户名(例如 `@timelinestudiochat`) | 从环境变量 |
90
89
  | `style` | 徽章样式 | `flat` |
91
90
  | `label` | 标签文本 | `Telegram` |
92
91
  | `color` | 主徽章颜色 | `2AABEE`(Telegram 颜色) |
@@ -105,60 +104,71 @@ bun dev
105
104
 
106
105
  标准徽章(扁平样式):
107
106
  ```
108
- https://telegram-badge.vercel.app/api/telegram-badge
107
+ https://telegram-badge.vercel.app/api/telegram-badge?channelId=@your_channel
109
108
  ```
110
- ![Flat](https://telegram-badge.vercel.app/api/telegram-badge)
109
+ ![Flat](https://telegram-badge.vercel.app/api/telegram-badge?channelId=@timelinestudiochat)
111
110
 
112
111
  立体样式徽章:
113
112
  ```
114
- https://telegram-badge.vercel.app/api/telegram-badge?style=plastic
113
+ https://telegram-badge.vercel.app/api/telegram-badge?channelId=@your_channel&style=plastic
115
114
  ```
116
- ![Plastic](https://telegram-badge.vercel.app/api/telegram-badge?style=plastic)
115
+ ![Plastic](https://telegram-badge.vercel.app/api/telegram-badge?channelId=@timelinestudiochat&style=plastic)
117
116
 
118
117
  方形扁平样式徽章:
119
118
  ```
120
- https://telegram-badge.vercel.app/api/telegram-badge?style=flat-square
119
+ https://telegram-badge.vercel.app/api/telegram-badge?channelId=@your_channel&style=flat-square
121
120
  ```
122
- ![Flat-Square](https://telegram-badge.vercel.app/api/telegram-badge?style=flat-square)
121
+ ![Flat-Square](https://telegram-badge.vercel.app/api/telegram-badge?channelId=@timelinestudiochat&style=flat-square)
123
122
 
124
123
  for-the-badge 样式徽章:
125
124
  ```
126
- https://telegram-badge.vercel.app/api/telegram-badge?style=for-the-badge
125
+ https://telegram-badge.vercel.app/api/telegram-badge?channelId=@your_channel&style=for-the-badge
127
126
  ```
128
- ![For-The-Badge](https://telegram-badge.vercel.app/api/telegram-badge?style=for-the-badge)
127
+ ![For-The-Badge](https://telegram-badge.vercel.app/api/telegram-badge?channelId=@timelinestudiochat&style=for-the-badge)
129
128
 
130
129
  社交样式徽章:
131
130
  ```
132
- https://telegram-badge.vercel.app/api/telegram-badge?style=social
131
+ https://telegram-badge.vercel.app/api/telegram-badge?channelId=@your_channel&style=social
133
132
  ```
134
- ![Social](https://telegram-badge.vercel.app/api/telegram-badge?style=social)
133
+ ![Social](https://telegram-badge.vercel.app/api/telegram-badge?channelId=@timelinestudiochat&style=social)
135
134
 
136
135
  自定义标签和颜色的徽章:
137
136
  ```
138
- https://telegram-badge.vercel.app/api/telegram-badge?label=加入聊天&color=00FF00
137
+ https://telegram-badge.vercel.app/api/telegram-badge?channelId=@your_channel&label=加入聊天&color=00FF00
139
138
  ```
140
- ![Custom](https://telegram-badge.vercel.app/api/telegram-badge?label=加入聊天&color=00FF00)
139
+ ![Custom](https://telegram-badge.vercel.app/api/telegram-badge?channelId=@timelinestudiochat&label=加入聊天&color=00FF00)
141
140
 
142
141
  完全自定义徽章:
143
142
  ```
144
- https://telegram-badge.vercel.app/api/telegram-badge?style=for-the-badge&label=社区&color=FF5733&labelColor=1A1A1A
143
+ https://telegram-badge.vercel.app/api/telegram-badge?channelId=@your_channel&style=for-the-badge&label=社区&color=FF5733&labelColor=1A1A1A
145
144
  ```
146
- ![Full Custom](https://telegram-badge.vercel.app/api/telegram-badge?style=for-the-badge&label=社区&color=FF5733&labelColor=1A1A1A)
145
+ ![Full Custom](https://telegram-badge.vercel.app/api/telegram-badge?channelId=@timelinestudiochat&style=for-the-badge&label=社区&color=FF5733&labelColor=1A1A1A)
147
146
 
148
147
  无标志徽章:
149
148
  ```
150
- https://telegram-badge.vercel.app/api/telegram-badge?logo=false
149
+ https://telegram-badge.vercel.app/api/telegram-badge?channelId=@your_channel&logo=false
150
+ ```
151
+ ![No Logo](https://telegram-badge.vercel.app/api/telegram-badge?channelId=@timelinestudiochat&logo=false)
152
+
153
+ 特定频道的徽章:
154
+ ```
155
+ https://telegram-badge.vercel.app/api/telegram-badge?channelId=@your_channel
156
+ ```
157
+
158
+ 带自定义样式的徽章:
159
+ ```
160
+ https://telegram-badge.vercel.app/api/telegram-badge?channelId=@your_channel&style=for-the-badge&color=FF5733
151
161
  ```
152
- ![No Logo](https://telegram-badge.vercel.app/api/telegram-badge?logo=false)
153
162
 
154
163
  ## ✨ 功能特性
155
164
 
156
165
  - 👥 实时显示成员数量
166
+ - 🔗 直接 URL 参数 - 无需任何设置!
157
167
  - 🎨 完全自定义徽章外观
158
- - 🔒 支持 .env 和 Vercel 环境变量以安全存储令牌
168
+ - 🔒 可选的自托管与安全令牌存储
159
169
  - ⚡ 优化缓存以实现快速加载
160
170
  - 🛡️ 错误处理和信息提示
161
- - 🆓 在 Vercel 上正常使用免费
171
+ - 🆓 免费使用
162
172
  - 📡 可扩展显示活动/消息计数
163
173
  - 🧪 使用 TypeScript 的完整测试套件
164
174
 
@@ -203,14 +213,6 @@ npm run type-check
203
213
  npm run build
204
214
  ```
205
215
 
206
- ## 订阅
207
-
208
- [![TikTok](https://img.shields.io/badge/TikTok-000000?style=for-the-badge&logo=tiktok&logoColor=white&labelColor=1c1917)](https://www.tiktok.com/@chatman.media)
209
- [![twitch](https://img.shields.io/badge/Twitch-9146FF?style=for-the-badge&logo=twitch&logoColor=white&labelColor=1c1917)](https://www.twitch.tv/chatman1984)
210
- [![YouTube](https://img.shields.io/badge/YouTube-FF0000?style=for-the-badge&logo=youtube&logoColor=white&labelColor=1c1917)](https://www.youtube.com/@chatman-media)
211
- [![Telegram](https://img.shields.io/badge/Telegram-2CA5E0?style=for-the-badge&logo=telegram&logoColor=white&labelColor=1c1917)](https://t.me/alexanderkireyev)
212
- [![X](https://img.shields.io/badge/Twitter-000000?style=for-the-badge&logo=x&logoColor=white&labelColor=1c1917)](https://x.com/chatman_media)
213
-
214
216
  ## 星标历史
215
217
 
216
218
  <a href="https://www.star-history.com/#chatman-media/telegram-badge&Date">
@@ -229,6 +231,30 @@ npm run build
229
231
  4. 推送到分支(`git push origin feature/amazing-feature`)
230
232
  5. 打开一个 Pull Request
231
233
 
234
+ ## 订阅
235
+
236
+ [![TikTok](https://img.shields.io/badge/TikTok-000000?style=for-the-badge&logo=tiktok&logoColor=white&labelColor=1c1917)](https://www.tiktok.com/@chatman.media)
237
+ [![twitch](https://img.shields.io/badge/Twitch-9146FF?style=for-the-badge&logo=twitch&logoColor=white&labelColor=1c1917)](https://www.twitch.tv/chatman1984)
238
+ [![YouTube](https://img.shields.io/badge/YouTube-FF0000?style=for-the-badge&logo=youtube&logoColor=white&labelColor=1c1917)](https://www.youtube.com/@chatman-media)
239
+ [![Telegram](https://img.shields.io/badge/Telegram-2CA5E0?style=for-the-badge&logo=telegram&logoColor=white&labelColor=1c1917)](https://t.me/alexanderkireyev)
240
+ [![X](https://img.shields.io/badge/Twitter-000000?style=for-the-badge&logo=x&logoColor=white&labelColor=1c1917)](https://x.com/chatman_media)
241
+
242
+ ## 支持 💝🚀
243
+
244
+ - **BTC:** 14s9Y9Rb2CUWHSAatiQMhfkpx1MWXofUzw
245
+ - **TON:** UQD1M80nPyzph5ZW1vfp_r19XI5MaerNhDq4dWXbXCo96WFj
246
+ - **NOT:** UQD1M80nPyzph5ZW1vfp_r19XI5MaerNhDq4dWXbXCo96WFj
247
+ - **ETH:** 0x286D65151b622dCC16624cEd8463FDa45585fd60
248
+
249
+ <div align="center">
250
+
251
+ <img src="public/btc.png" alt="BTC" style="height: 185px" />
252
+ <img src="public/ton.png" alt="TON" style="height: 185px" />
253
+ <img src="public/not.png" alt="NOT" style="height: 185px" />
254
+ <img src="public/eth.png" alt="ETH" style="height: 185px" />
255
+
256
+ </div>
257
+
232
258
  ## 📜 许可证
233
259
 
234
260
  本项目根据 MIT 许可证获得许可 - 有关详细信息,请参阅 [LICENSE](LICENSE) 文件。
@@ -52,20 +52,24 @@ const logger = {
52
52
  }
53
53
  }
54
54
  };
55
- const validateEnvironment = () => {
55
+ const validateEnvironment = (query) => {
56
56
  const token = process.env.BOT_TOKEN;
57
- const chatId = process.env.CHAT_ID;
57
+ let channelId = process.env.CHAT_ID;
58
+ // Check if channelId is provided via URL parameter
59
+ if (query?.channelId) {
60
+ channelId = Array.isArray(query.channelId) ? query.channelId[0] : query.channelId;
61
+ }
58
62
  if (!token) {
59
63
  throw new Error("Missing BOT_TOKEN environment variable");
60
64
  }
61
- if (!chatId) {
62
- throw new Error("Missing CHAT_ID environment variable");
65
+ if (!channelId) {
66
+ throw new Error("Missing CHAT_ID environment variable or channelId parameter");
63
67
  }
64
- return { token, chatId };
68
+ return { token, channelId };
65
69
  };
66
- const getMemberCount = async (token, chatId) => {
67
- const apiUrl = `https://api.telegram.org/bot${token}/getChatMemberCount?chat_id=${encodeURIComponent(chatId)}`;
68
- logger.debug('Fetching member count', { chatId });
70
+ const getMemberCount = async (token, channelId) => {
71
+ const apiUrl = `https://api.telegram.org/bot${token}/getChatMemberCount?chat_id=${encodeURIComponent(channelId)}`;
72
+ logger.debug('Fetching member count', { channelId });
69
73
  const controller = new AbortController();
70
74
  const timeoutId = setTimeout(() => controller.abort(), 5000);
71
75
  try {
@@ -175,10 +179,12 @@ async function handler(req, res) {
175
179
  }
176
180
  });
177
181
  // Early check for environment variables
178
- if (!process.env.BOT_TOKEN || !process.env.CHAT_ID) {
182
+ const chatIdFromQuery = req.query?.channelId;
183
+ if (!process.env.BOT_TOKEN || (!process.env.CHAT_ID && !chatIdFromQuery)) {
179
184
  logger.error('Missing environment variables', {
180
185
  BOT_TOKEN: !!process.env.BOT_TOKEN,
181
- CHAT_ID: !!process.env.CHAT_ID
186
+ CHAT_ID: !!process.env.CHAT_ID,
187
+ chatIdFromQuery: !!chatIdFromQuery
182
188
  });
183
189
  const errorBadge = createErrorBadge('Missing Config');
184
190
  res.setHeader("Content-Type", "image/svg+xml");
@@ -186,19 +192,19 @@ async function handler(req, res) {
186
192
  res.status(500).send(errorBadge);
187
193
  return;
188
194
  }
189
- const { token, chatId } = validateEnvironment();
190
- logger.debug('Environment validated', { chatId });
195
+ const { token, channelId } = validateEnvironment(req.query);
196
+ logger.debug('Environment validated', { channelId });
191
197
  const ifNoneMatch = req.headers['if-none-match'];
192
198
  const requestEtag = `"${crypto
193
199
  .createHash('md5')
194
- .update(JSON.stringify({ token, chatId, query: req.query, time: Math.floor(Date.now() / 300000) }))
200
+ .update(JSON.stringify({ token, channelId, query: req.query, time: Math.floor(Date.now() / 300000) }))
195
201
  .digest('hex')}"`;
196
202
  if (ifNoneMatch && ifNoneMatch === requestEtag) {
197
203
  logger.info('Returning 304 Not Modified');
198
204
  res.status(304).end();
199
205
  return;
200
206
  }
201
- const members = await getMemberCount(token, chatId);
207
+ const members = await getMemberCount(token, channelId);
202
208
  logger.info('Member count fetched', { members });
203
209
  const badgeOptions = {
204
210
  style: req.query.style,
@@ -145,7 +145,7 @@ describe('Telegram Badge API', () => {
145
145
  .createHash('md5')
146
146
  .update(JSON.stringify({
147
147
  token: 'test_token_for_etag',
148
- chatId: '@test_chat_for_etag',
148
+ channelId: '@test_chat_for_etag',
149
149
  query: {},
150
150
  time: Math.floor(fixedTime / 300000)
151
151
  }))
@@ -45,5 +45,5 @@ export interface Response {
45
45
  }
46
46
  export interface Environment {
47
47
  token: string;
48
- chatId: string;
48
+ channelId: string;
49
49
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "telegram-badge",
3
- "version": "1.1.2",
3
+ "version": "1.2.0",
4
4
  "description": "Generate Telegram group member count badges for GitHub README",
5
5
  "keywords": [
6
6
  "telegram",
package/types/index.ts CHANGED
@@ -53,5 +53,5 @@ export interface Response {
53
53
 
54
54
  export interface Environment {
55
55
  token: string;
56
- chatId: string;
56
+ channelId: string;
57
57
  }