Skip to content

Commit befbbfc

Browse files
authored
πŸš€ release: v0.1.0-beta - Merge pull request #7 from wgtechlabs/dev
2 parents 488a7af + 5c25c24 commit befbbfc

29 files changed

+4446
-2053
lines changed

β€Ž.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ build/Release
4242
node_modules/
4343
jspm_packages/
4444

45+
# Prevent npm lock file (we use Yarn)
46+
package-lock.json
47+
4548
# TypeScript cache
4649
*.tsbuildinfo
4750

β€Ž.npmrc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Force using Yarn instead of npm
2+
# This file will cause npm commands to fail with an error
3+
engine-strict=true
4+
5+
# Prevent npm from creating package-lock.json
6+
package-lock=false
7+
8+
# Show a helpful error message
9+
save-exact=true

β€Ž.yarnrc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Yarn configuration
2+
# This ensures consistent behavior across environments
3+
4+
# Use exact versions (no semver ranges)
5+
save-exact true
6+
7+
# Disable emoji in output (better for logs)
8+
emoji false
9+
10+
# Use network timeout for slow connections
11+
network-timeout 300000

β€ŽREADME.md

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
The Unthread Telegram Bot seamlessly connects your Telegram community with Unthread's powerful ticket management system. This official integration transforms how you handle support requests by enabling users to create and manage tickets directly within Telegram.
88

9-
With simple commands and intuitive interactions, support tickets automatically sync between both platforms, streamlining your workflow and improving response times. Whether you're managing a community group, running a business chat, or supporting an open-source project, this bot provides the tools you need for efficient, organized customer support.
9+
With simple commands and intuitive interactions, support tickets automatically sync between both platforms, streamlining your workflow and improving response times. Users receive real-time notifications when ticket status changes, ensuring they stay informed throughout the support process. Whether you're managing a community group, running a business chat, or supporting an open-source project, this bot provides the tools you need for efficient, organized customer support.
1010

1111
## πŸ’Έ Sponsored Ads
1212

@@ -19,22 +19,27 @@ Open source development is resource-intensive. These **sponsored ads help keep L
1919
The Unthread Telegram Bot creates a seamless bridge between your Telegram group chats and Unthread's ticket management system. Here's how it works:
2020

2121
### **πŸ“₯ Ticket Creation**
22+
2223
- Users in group chats can create support tickets using the `/support` command
2324
- The bot guides them through a simple conversation to collect issue summary and email (optional)
2425
- Tickets are automatically created in Unthread with proper customer and user association
2526

26-
### **πŸ”„ Bidirectional Communication**
27+
### **πŸ”„ Bidirectional Communication**
28+
2729
- **Agent β†’ User**: When agents respond via the Unthread dashboard, messages are delivered to Telegram in real-time through webhook processing
2830
- **User β†’ Agent**: Users can simply reply to agent messages naturally - no special commands needed
31+
- **Status Notifications**: Receive real-time notifications when ticket status changes (Open/Closed) with clear messaging and emoji indicators
2932
- **Conversation Flow**: Maintains complete conversation history across both platforms using message reply chains
3033
- **Webhook Server**: Powered by [`wgtechlabs/unthread-webhook-server`](https://github.com/wgtechlabs/unthread-webhook-server) which processes Unthread webhooks and queues events in Redis for real-time delivery
3134

3235
### **🏒 Smart Customer Management**
36+
3337
- Automatically extracts customer company names from group chat titles (e.g., "Company X Relay" β†’ "Company X")
3438
- Creates customers in Unthread with `[Telegram]` prefix for platform identification
3539
- Maps Telegram users to Unthread user profiles with fallback email generation
3640

3741
### **πŸ’Ύ Multi-Layer Storage**
42+
3843
- **Memory Layer** (24h): Fast access for active conversations
3944
- **Redis Layer** (3 days): Intermediate caching for recent activity
4045
- **PostgreSQL** (permanent): Long-term storage with full conversation history
@@ -44,7 +49,8 @@ The Unthread Telegram Bot creates a seamless bridge between your Telegram group
4449
This bot works in conjunction with the [`wgtechlabs/unthread-webhook-server`](https://github.com/wgtechlabs/unthread-webhook-server) to enable real-time bidirectional communication. Here's how the complete system works:
4550

4651
### **πŸ—οΈ System Architecture**
47-
```
52+
53+
```text
4854
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
4955
β”‚ Unthread β”‚ β”‚ Webhook β”‚ β”‚ Redis β”‚ β”‚ Telegram β”‚
5056
β”‚ Dashboard │───▢│ Server │───▢│ Queue │───▢│ Bot β”‚
@@ -55,13 +61,16 @@ This bot works in conjunction with the [`wgtechlabs/unthread-webhook-server`](ht
5561
```
5662

5763
### **πŸ”„ Event Flow**
64+
5865
1. **Agent responds** in Unthread dashboard to a ticket
5966
2. **Unthread webhook** fires and sends event to the webhook server
6067
3. **Webhook server** processes the event and queues it in Redis with proper formatting
6168
4. **Telegram bot** polls the Redis queue and delivers the message to the appropriate group chat
6269
5. **User replies** in Telegram, and the bot sends it back to Unthread API
70+
6. **Status changes** (ticket closed/reopened) trigger real-time notifications to users
6371

6472
### **βš™οΈ Configuration Requirements**
73+
6574
- **Webhook Server**: Must be deployed separately to receive Unthread webhooks
6675
- **Shared Redis**: Both webhook server and bot must use the same Redis instance
6776
- **Queue Names**: Both webhook server and bot use the standard queue name `unthread-events`
@@ -71,37 +80,45 @@ For webhook server setup instructions, see the [`wgtechlabs/unthread-webhook-ser
7180
## ✨ Key Features
7281

7382
### **🎫 Seamless Ticket Management**
83+
7484
- Create support tickets directly from Telegram group chats with `/support` command
7585
- Interactive ticket creation with guided prompts for summary and email
7686
- Automatic ticket numbering and confirmation messages
7787
- Smart customer extraction from group chat names
7888

7989
### **πŸ’¬ Real-Time Bidirectional Communication**
90+
8091
- Agent responses from Unthread dashboard delivered instantly to Telegram
8192
- Users reply naturally to agent messages without special commands
8293
- Complete conversation history maintained across both platforms
8394
- Message reply chains preserve conversation context
95+
- **Status Notifications**: Real-time alerts when tickets are opened or closed with emoji-rich formatting
96+
- **Reaction-Based Feedback**: User messages are reacted to with ⏳ (sending) β†’ βœ… (sent) or ❌ (error) for clean, non-intrusive status updates
8497

8598
### **🏒 Enterprise-Ready Customer Management**
99+
86100
- Automatic customer creation with `[Telegram]` platform identification
87101
- Smart company name extraction from group chat titles (e.g., "Acme Corp x Support" β†’ "Acme Corp")
88102
- User profile mapping with automatic fallback email generation
89103
- Duplicate prevention for customers and users
90104

91105
### **πŸš€ Production-Grade Architecture**
106+
92107
- Multi-layer storage: Memory (24h) β†’ Redis (3d) β†’ PostgreSQL (permanent)
93108
- Webhook-based real-time event processing from Unthread via [`wgtechlabs/unthread-webhook-server`](https://github.com/wgtechlabs/unthread-webhook-server)
94109
- Redis queue system for reliable webhook event processing and delivery
95110
- Graceful degradation when services are unavailable
96111
- Comprehensive error handling and recovery mechanisms
97112

98113
### **⚑ Developer Experience**
114+
99115
- Built with modern ES6+ modules and async/await patterns
100116
- Structured logging with `@wgtechlabs/log-engine` integration
101117
- Auto-setup database schema on first run
102118
- Clean separation of concerns with SDK architecture
103119

104120
### **πŸ”§ Flexible Configuration**
121+
105122
- Environment variable based configuration
106123
- Support for both basic mode (ticket creation only) and full mode (with webhooks)
107124
- Configurable webhook polling intervals and queue names
@@ -162,6 +179,7 @@ That's it! The database schema will be created automatically on first run.
162179
[![Deploy on Railway](https://railway.app/button.svg)](https://railway.com/u/warengonzaga)
163180

164181
#### **🐳 Docker Support**
182+
165183
```bash
166184
# Coming soon - Docker deployment support
167185
docker-compose up -d
@@ -181,6 +199,7 @@ docker-compose up -d
181199
The bot provides several commands for users and administrators:
182200

183201
#### **User Commands**
202+
184203
- `/start` - Welcome message and bot introduction
185204
- `/help` - Display available commands and usage instructions
186205
- `/support` - Create a new support ticket (group chats only)
@@ -193,7 +212,7 @@ The bot provides several commands for users and administrators:
193212
3. **Email (Optional)**: Provide email or skip for auto-generated one
194213
4. **Confirmation**: Receive ticket number and confirmation message
195214

196-
```
215+
```text
197216
User: /support
198217
Bot: Let's create a support ticket. Please provide your issue summary:
199218
@@ -209,40 +228,50 @@ Bot: 🎫 Support Ticket Created Successfully!
209228
### **Agent Workflow**
210229

211230
#### **Receiving Tickets**
231+
212232
- New tickets appear in your Unthread dashboard
213233
- Customer name shows as `[Telegram] GroupChatName`
214234
- User information includes Telegram username and ID
215235

216236
#### **Responding to Users**
237+
217238
- Reply to tickets in Unthread dashboard as normal
218239
- Messages are automatically delivered to the original Telegram group
219240
- Users receive agent responses in real-time
220241

221242
#### **Ongoing Conversations**
243+
222244
- Users can reply directly to agent messages in Telegram
223245
- No special commands needed - natural conversation flow
224246
- All replies are automatically sent back to Unthread
247+
- **Status Updates**: Users receive real-time notifications when tickets are closed (πŸ”’) or reopened (πŸ“‚)
248+
- **Reply Status**: Message reactions show reply status (⏳ sending β†’ βœ… sent successfully / ❌ error)
249+
- Status notifications include clear messaging about next steps and reply to original ticket messages
225250

226251
### **Group Chat Setup**
227252

228253
#### **Adding the Bot**
254+
229255
1. Add your bot to the desired Telegram group chat
230256
2. Ensure the bot has permission to read and send messages
231257
3. Group chat title should ideally include customer company name
232258

233259
#### **Best Practices**
260+
234261
- Use descriptive group chat names (e.g., "Acme Corp Support", "ClientName x YourCompany")
235262
- The bot automatically extracts customer names from chat titles
236263
- Only group members can create support tickets (private chats are blocked)
237264

238265
### **Admin Features**
239266

240267
#### **Customer Management**
268+
241269
- Customers are automatically created from group chat names
242270
- Duplicate prevention ensures one customer per chat
243271
- Customer names are prefixed with `[Telegram]` for easy identification
244272

245273
#### **Conversation Tracking**
274+
246275
- Each ticket maintains complete conversation history
247276
- Reply chains preserve context across platforms
248277
- Message metadata includes user information and timestamps
@@ -256,32 +285,39 @@ Bot: 🎫 Support Ticket Created Successfully!
256285
- **PostgreSQL 12+** (primary database)
257286
- **Redis 6+** (optional, for enhanced performance)
258287

288+
> **⚠️ Package Manager Notice:** This project enforces the use of Yarn and will prevent npm installation attempts. If you try to use `npm install`, you'll receive an error message with instructions to use Yarn instead.
289+
259290
### **Step-by-Step Installation**
260291

261292
#### **1. Clone Repository**
293+
262294
```bash
263295
git clone https://github.com/wgtechlabs/unthread-telegram-bot.git
264296
cd unthread-telegram-bot
265297
```
266298

267299
#### **2. Install Dependencies**
300+
268301
```bash
269302
# Use Yarn only (npm not supported)
270303
yarn install
271304
```
272305

273306
#### **3. Create Telegram Bot**
307+
274308
1. Message [@BotFather](https://t.me/botfather) on Telegram
275309
2. Create new bot with `/newbot` command
276310
3. Save the bot token for environment configuration
277311

278312
#### **4. Setup Unthread Integration**
313+
279314
1. Log into your Unthread dashboard
280315
2. Navigate to Settings β†’ API Keys
281316
3. Generate a new API key
282317
4. Find your channel ID in the dashboard URL
283318

284319
#### **5. Database Setup**
320+
285321
```bash
286322
# PostgreSQL (required)
287323
createdb unthread_telegram_bot
@@ -291,6 +327,7 @@ createdb unthread_telegram_bot
291327
```
292328

293329
#### **6. Environment Configuration**
330+
294331
```bash
295332
# Copy example environment file
296333
cp .env.example .env
@@ -300,6 +337,7 @@ nano .env
300337
```
301338

302339
Required environment variables:
340+
303341
```bash
304342
TELEGRAM_BOT_TOKEN=your_bot_token_from_botfather
305343
POSTGRES_URL=postgresql://user:password@localhost:5432/unthread_telegram_bot
@@ -308,6 +346,7 @@ UNTHREAD_CHANNEL_ID=your_unthread_channel_id
308346
```
309347

310348
Optional environment variables:
349+
311350
```bash
312351
WEBHOOK_REDIS_URL=redis://localhost:6379
313352
PLATFORM_REDIS_URL=redis://localhost:6379
@@ -316,6 +355,7 @@ WEBHOOK_POLL_INTERVAL=1000
316355
```
317356

318357
#### **7. Start the Bot**
358+
319359
```bash
320360
# Development mode (with auto-restart)
321361
yarn dev
@@ -327,8 +367,10 @@ yarn start
327367
### **Verification**
328368

329369
#### **Check Bot Status**
370+
330371
1. Look for successful startup logs:
331-
```
372+
373+
```text
332374
[INFO] Database initialized successfully
333375
[INFO] BotsStore initialized successfully
334376
[INFO] Bot initialized successfully
@@ -343,12 +385,14 @@ yarn start
343385
#### **Troubleshooting**
344386

345387
**Common Issues:**
388+
346389
- **Import errors**: Ensure you're using Yarn, not npm
347390
- **Database connection**: Verify PostgreSQL is running and connection string is correct
348391
- **Bot not responding**: Check bot token and ensure bot is added to group with proper permissions
349392
- **Webhook issues**: Verify Redis connection if using webhook features
350393

351394
**Debug Mode:**
395+
352396
```bash
353397
# Enable detailed logging
354398
NODE_ENV=development yarn start
@@ -359,7 +403,7 @@ NODE_ENV=development yarn start
359403
Join our community discussions to get help, share ideas, and connect with other users:
360404

361405
- πŸ“£ **[Announcements](https://github.com/wgtechlabs/unthread-telegram-bot/discussions/categories/announcements)**: Official updates from the maintainer
362-
- πŸ“Έ **[Showcase](https://github.com/wgtechlabs/unthread-telegram-bot/discussions/categories/showcase)**: Show and tell your implementation
406+
- πŸ“Έ **[Showcase](https://github.com/wgtechlabs/unthread-telegram-bot/discussions/categories/showcase)**: Show and tell your implementation
363407
- πŸ’– **[Wall of Love](https://github.com/wgtechlabs/unthread-telegram-bot/discussions/categories/wall-of-love)**: Share your experience with the bot
364408
- πŸ›Ÿ **[Help & Support](https://github.com/wgtechlabs/unthread-telegram-bot/discussions/categories/help-support)**: Get assistance from the community
365409
- 🧠 **[Ideas](https://github.com/wgtechlabs/unthread-telegram-bot/discussions/categories/ideas)**: Suggest new features and improvements

β€Žpackage.json

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,45 @@
11
{
22
"name": "unthread-telegram-bot",
3-
"version": "0.1.0-alpha",
3+
"version": "0.1.0-beta",
44
"description": "A Telegram bot integrated with Unthread API featuring enhanced logging with @wgtechlabs/log-engine",
5-
"main": "src/index.js",
5+
"main": "dist/index.js",
66
"type": "module",
77
"private": true,
88
"engines": {
99
"node": ">=20.0.0",
1010
"yarn": ">=1.22.22"
1111
},
12+
"packageManager": "[email protected]",
1213
"scripts": {
13-
"start": "node src/index.js",
14-
"dev": "nodemon src/index.js"
14+
"preinstall": "npx only-allow yarn",
15+
"build": "tsc",
16+
"start": "node dist/index.js",
17+
"dev": "nodemon --exec 'npm run build && npm start' src/index.ts",
18+
"dev:watch": "concurrently \"tsc --watch\" \"nodemon dist/index.js\"",
19+
"clean": "rm -rf dist"
1520
},
1621
"dependencies": {
17-
"@wgtechlabs/log-engine": "^1.2.1",
22+
"@wgtechlabs/log-engine": "^1.3.0",
1823
"dotenv": "^16.4.7",
1924
"node-fetch": "^3.3.2",
2025
"pg": "^8.16.0",
2126
"redis": "^5.1.1",
2227
"telegraf": "^4.0.0"
2328
},
2429
"devDependencies": {
25-
"nodemon": "^3.1.9"
30+
"@types/node": "24.0.3",
31+
"@types/pg": "8.15.4",
32+
"concurrently": "9.1.2",
33+
"nodemon": "^3.1.9",
34+
"typescript": "5.8.3"
2635
},
2736
"keywords": [
2837
"telegram",
2938
"bot"
3039
],
3140
"author": "Waren Gonzaga <[email protected]> (https://warengonzaga.com)",
32-
"license": "AGPL-3.0-only",
33-
"packageManager": "[email protected]"
41+
"contributors": [
42+
"WG Tech Labs <[email protected]> (https://wgtechlabs.com)"
43+
],
44+
"license": "AGPL-3.0-only"
3445
}

0 commit comments

Comments
Β (0)