Copperx Telegram Bot
    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

    api-integration

    CopperX API Integration#

    This document provides details on how the CopperX Payout Bot integrates with the CopperX API for authentication, wallet management, transfers, and notifications.

    API Overview#

    The CopperX Payout Bot integrates with the following APIs:
    1.
    CopperX API: For authentication, wallet management, and transfers
    2.
    Telegram Bot API: For user interactions
    3.
    Pusher API: For real-time notifications

    CopperX API Integration#

    Base Configuration#

    The bot communicates with the CopperX API through a set of specialized service classes. The base API client is configured in src/utils/copperxApi/copperxApi.ts:

    Authentication API#

    The bot authenticates users with the CopperX platform using email OTP verification. This is implemented in src/utils/copperxApi/copperxApi.auth.ts:

    Wallet API#

    The wallet operations are handled by src/utils/copperxApi/copperxApi.wallet.ts:

    Transfer API#

    Transfer operations are managed by src/utils/copperxApi/copperxApi.transfers.ts:

    Telegram API Integration#

    The bot communicates with the Telegram Bot API through the TelegramService in src/utils/telegram/telegram.service.ts:

    Pusher Integration for Real-time Notifications#

    The bot uses Pusher for real-time notifications. This is implemented in src/services/notification.service.ts:

    Authentication Flow#

    1.
    User sends /login command or clicks login button
    2.
    Bot asks for email address
    3.
    User provides email
    4.
    Bot calls requestEmailOtp to obtain a session ID (sid)
    5.
    CopperX sends OTP to user's email
    6.
    User provides OTP to bot
    7.
    Bot calls authenticateWithEmailOtp to verify OTP and obtain access token
    8.
    Access token is stored in user's session for subsequent API calls

    API Security Considerations#

    1.
    Token Management: Access tokens are stored securely in the Redis database
    2.
    Token Refresh: Tokens have an expiration time and are refreshed as needed
    3.
    Rate Limiting: API calls are rate-limited to prevent abuse
    4.
    Error Handling: API errors are properly logged and handled gracefully
    5.
    Authorization: All API calls requiring authentication include the access token in the Authorization header

    Error Handling#

    Each API call includes proper error handling and logging:

    Best Practices#

    1.
    Abstraction: API calls are abstracted behind service classes
    2.
    Modularity: Each API area (auth, wallet, transfers) has its own service
    3.
    Error Handling: All API calls include proper error handling
    4.
    Logging: Comprehensive logging for debugging and auditing
    5.
    Rate Limiting: Prevents abuse of the API
    6.
    Security: Proper token management and authorization
    Modified at 2025-03-23 17:05:40
    Previous
    development
    Next
    troubleshooting
    Built with