Skip to content

🚀 release: v0.1.0-alpha #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 24 commits into from
Jun 6, 2025
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
67862ca
📦 new: add support command
warengonzaga Apr 10, 2025
dd26d21
✨ tweak: add email handling
warengonzaga Apr 11, 2025
cd5d9c1
📦 new: add unthread service
warengonzaga Apr 24, 2025
d69e53b
✨ tweak: update channel id handling
warengonzaga Apr 24, 2025
15f4246
☕ chore: ignore ai context folder
warengonzaga Jun 1, 2025
4b2ccae
✨ tweak: update logging and use yarn as manager
warengonzaga Jun 1, 2025
db318ce
✨ tweak: update yarn and quick refactor to the code
warengonzaga Jun 1, 2025
955891e
📦 new: bidirectional comms from telegram to unthread
warengonzaga Jun 2, 2025
b24259a
☕ chore: downgrade yarn version to 1.22.22
warengonzaga Jun 3, 2025
b8e6d53
✨ tweak: add customer cache management
warengonzaga Jun 4, 2025
8f65a9b
✨ tweak: refactor logging system with log-engine
warengonzaga Jun 4, 2025
54b4463
✨ tweak: validate conversationId and text
warengonzaga Jun 4, 2025
2ed7dee
✨ tweak: update logging messages and remove unused files
warengonzaga Jun 5, 2025
be0969a
✨ tweak: update user state handling
warengonzaga Jun 5, 2025
3a25cab
Merge branch 'dev' of https://github.com/wgtechlabs/unthread-telegram…
warengonzaga Jun 5, 2025
bbb4629
✨ tweak: refactor code structure for improved readability and maintai…
warengonzaga Jun 6, 2025
adde5c3
✨ tweak: update logging for events
warengonzaga Jun 6, 2025
e5c708f
✨ tweak: improve logging messages
warengonzaga Jun 6, 2025
f606a13
Initial plan for issue
Copilot Jun 6, 2025
89c1c10
Initial analysis of Redis blPop implementation
Copilot Jun 6, 2025
654daf2
Fix blPop method signature for Node Redis v4/v5 compatibility
Copilot Jun 6, 2025
485e465
Merge pull request #3 from wgtechlabs/copilot/fix-db202c8c-aeb0-4a10-…
warengonzaga Jun 6, 2025
c6d53b1
✨ tweak: update logging to LogEngine
warengonzaga Jun 6, 2025
ddac58f
✨ tweak: update redis client handling
warengonzaga Jun 6, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
TELEGRAM_BOT_TOKEN=your_telegram_bot_token_here
UNTHREAD_API_KEY=your_unthread_api_key_here
UNTHREAD_CHANNEL_ID=your_unthread_channel_id_here
UNTHREAD_WEBHOOK_SECRET=your_unthread_webhook_secret_here

# Redis Configuration
# Two separate Redis instances for different purposes:
# PLATFORM_REDIS_URL - Used by Bot's Brain for caching ticket data and user states
# WEBHOOK_REDIS_URL - Used by Webhook SDK for processing real-time agent messages
PLATFORM_REDIS_URL=your_platform_redis_url_here
WEBHOOK_REDIS_URL=your_webhook_redis_url_here

# Database Configuration for Phase 1
POSTGRES_URL=postgresql://username:password@localhost:5432/unthread_bot

# Webhook Configuration for Phase 5
WEBHOOK_QUEUE_NAME=unthread-events
WEBHOOK_POLL_INTERVAL=1000

# Additional Configuration
NODE_ENV=development
LOG_LEVEL=info
14 changes: 13 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,16 @@ dist
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
.pnp.*

# HTTP files
*.http

# Test and validation scripts
final-validation.js
phase6-integration-test.js
*-test.js
*-validation.js

# AI context
ai_docs/
2 changes: 2 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
nodeLinker: node-modules
enableTelemetry: false
4 changes: 2 additions & 2 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ representative at an online or offline event.
## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported to the community leaders responsible for enforcement at [email protected].
reported to the community leaders responsible for enforcement at <[email protected]>.
All complaints will be reviewed and investigated promptly and fairly.

All community leaders are obligated to respect the privacy and security of the
Expand Down Expand Up @@ -128,4 +128,4 @@ For answers to common questions about this code of conduct, see the FAQ at
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
[Mozilla CoC]: https://github.com/mozilla/diversity
[FAQ]: https://www.contributor-covenant.org/faq
[translations]: https://www.contributor-covenant.org/translations
[translations]: https://www.contributor-covenant.org/translations
17 changes: 12 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
{
"name": "telegram-bot",
"name": "unthread-telegram-bot",
"version": "0.1.0-alpha",
"description": "A Telegram bot integrated with Unthread API",
"description": "A Telegram bot integrated with Unthread API featuring enhanced logging with @wgtechlabs/log-engine",
"main": "src/index.js",
"type": "module",
"private": true,
"engines": {
"node": ">=20.0.0"
"node": ">=20.0.0",
"yarn": ">=1.22.22"
},
"scripts": {
"start": "node src/index.js",
"dev": "nodemon src/index.js"
"dev": "nodemon src/index.js",
"db:verify": "node src/sdk/bots-brain/verify.js"
},
"dependencies": {
"@wgtechlabs/log-engine": "^1.2.0",
"dotenv": "^16.4.7",
"node-fetch": "^3.3.2",
"pg": "^8.16.0",
"redis": "^5.1.1",
"telegraf": "^4.0.0"
},
"devDependencies": {
Expand All @@ -24,5 +30,6 @@
"bot"
],
"author": "Waren Gonzaga <[email protected]> (https://warengonzaga.com)",
"license": "AGPL-3.0-only"
"license": "AGPL-3.0-only",
"packageManager": "[email protected]"
}
29 changes: 2 additions & 27 deletions src/bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* This module provides utility functions for creating and configuring a Telegram bot
* using the Telegraf framework. It includes functions for bot initialization, command
* configuration, message handling, and bot startup.
* configuration, and bot startup.
*
* Potential Improvements:
* - Add error handling for bot operations
Expand All @@ -12,7 +12,7 @@
* - Add graceful shutdown mechanism
* - Add webhook support as an alternative to polling
*/
import { Telegraf } from 'telegraf';
import { Telegraf, Markup } from 'telegraf';

/**
* Creates a new Telegram bot instance
Expand Down Expand Up @@ -55,31 +55,6 @@ export function configureCommands(bot, commands) {
});
}

/**
* Adds a text message handler with pattern matching
*
* @param {Telegraf} bot - The Telegraf bot instance
* @param {RegExp} pattern - Regular expression pattern to match against message text
* @param {Function} handler - Handler function to execute when pattern matches
*
* Possible Bugs:
* - If multiple patterns are registered, all matching patterns will execute their handlers
* - No error handling if pattern is invalid or if handler throws an exception
*
* Enhancement Opportunities:
* - Add priority mechanism for overlapping patterns
* - Support for more sophisticated pattern matching beyond RegExp
* - Add context data to handlers
* - Add middleware for text handlers
*/
export function onText(bot, pattern, handler) {
bot.on('text', (ctx) => {
if (ctx.message.text.match(pattern)) {
handler(ctx);
}
});
}

/**
* Starts the bot polling for updates
*
Expand Down
Loading