Copperx Telegram Bot
  1. notifications
Copperx Telegram Bot
  • index
  • readme
  • setup
  • development
  • api-integration
  • troubleshooting
  • architechture
  • callbacks
    • index (all callbacks)
    • wallet
    • transfer-callback
    • send
  • commands
    • help
    • index(all commands)
    • login
    • logout
    • start
    • transfer
    • transfer
  • notifications
    • deposite-notification
  • Register Telegram Webhook to your url
    POST
  1. notifications

deposite-notification

Deposit Notifications#

This document details the real-time deposit notification system implemented in the CopperX Payout Bot. The notification system uses Pusher to provide instant alerts when funds are deposited to a user's wallet.

Notification System Overview#

The CopperX Payout Bot includes a real-time notification system that:
1.
Subscribes to private channels for each authenticated user
2.
Listens for deposit events on these channels
3.
Sends immediate Telegram notifications when deposits are received
4.
Automatically resubscribes users when the bot restarts
This provides users with timely information about their wallet activity without requiring them to manually check their balances.

Notification Implementation#

Notification Service#

The core of the notification system is the NotificationService in src/services/notification.service.ts. This service:
Manages connections to Pusher
Handles authentication with the CopperX API
Subscribes to private channels for users
Processes incoming events
Sends formatted notifications to users
The service is implemented as a singleton to ensure a single instance manages all connections:

Initializing Pusher for a User#

When a user successfully authenticates, the notification service initializes a Pusher connection for them:

Handling Deposit Events#

When a deposit event is received, the service processes it and sends a notification to the user:

Subscribing All Users on Startup#

When the bot starts up, it automatically subscribes all authenticated users to their notification channels:

Unsubscribing Users#

When a user logs out, the service unsubscribes them from their notification channel:

Deposit Event Data Structure#

The notification system handles deposit events with the following structure:

Notification Example#

When a user receives a deposit, they will see a message like this:
šŸ’° New Deposit Received

Amount: 100.25 USDT
Network: ethereum
Address: 0x1234...5678
Transaction: 0xabcd...efgh
Time: 3/15/2023, 2:30:45 PM

System Initialization#

The notification system is initialized when the Express application starts up:

Integrating with Authentication Flow#

The notification system is also integrated into the user authentication flow:

Security Considerations#

1.
Private Channels: Notifications use private channels, requiring server-side authentication
2.
Token-based Authentication: Each connection is authenticated with the user's access token
3.
Channel Naming: Channels follow the format private-org-{organizationId} for consistency and security
4.
Error Handling: Comprehensive error handling for reliable operation
5.
Logging: Detailed logging for troubleshooting and auditing

Testing Deposit Notifications#

Deposit notifications can be tested using the CopperX API's test mode:
1.
Set up the bot with test API credentials
2.
Use the CopperX dashboard to simulate a deposit
3.
Verify that the notification is received in Telegram

Troubleshooting Deposit Notifications#

If deposit notifications aren't working as expected, check the following:
1.
Authentication Issues: Ensure the user is properly authenticated with a valid access token
2.
Pusher Connection: Verify that the Pusher connection is established successfully
3.
Channel Subscription: Check logs for successful channel subscription messages
4.
API Errors: Look for authentication or API errors in the logs
5.
Network Connectivity: Ensure the bot can connect to both the Pusher and CopperX APIs
6.
Token Expiration: Check if the user's access token has expired
Common issues include:
Missing Notifications: Usually due to channel subscription failures or expired tokens
Authentication Errors: Often caused by invalid or expired access tokens
Connection Failures: May be due to network issues or incorrect Pusher credentials

Performance Considerations#

The notification system is designed to be efficient and scalable:
1.
Singleton Pattern: Single notification service instance manages all connections
2.
Connection Reuse: The Pusher client is reused across all users
3.
Selective Subscriptions: Only subscribes users with valid authentication
4.
Automatic Reconnection: Pusher client handles reconnection automatically
5.
Memory Management: Properly tracks and cleans up channel subscriptions

Related Files#

src/services/notification.service.ts - Main notification service implementation
src/utils/telegram/telegram.service.ts - Service for sending Telegram messages
src/services/auth.service.ts - Integrates authentication with notifications
src/app.ts - Initializes the notification system on startup
src/utils/session/session.service.ts - Provides session data for notification subscriptions
Modified atĀ 2025-03-23 18:17:02
Previous
transfer
Next
Register Telegram Webhook to your url
Built with