This bot enables users to deposit, withdraw, and transfer USDC directly through Telegram without visiting web app
Step 1- Install Yarn, Visit Yarn Website for details, Yarn version 1.22.22 is used for development.
Step 2 - Git Pull
git clone https://github.com/username/copperx_payout_bot.git
cd copperx_payout_bot
Step 3 - Create a .env file firstly, some variables are already initialized with default values
cp .env.example .env
Step 4 - To install dependencies run yarn
yarn
Step 5 - Build the bot with following command
yarn build
Step 6 - To start the bot run yarn start, bot will start on port 3000
yarn start
This project organizes API calls into a structured format, ensuring maintainability and ease of use. All API calls are defined in the src/bot/api_calls folder, and they are categorized based on their functionality.
This file serves as the core service for making API requests. It includes additional functionalities such as:
- Setting the access token for authentication.
- Managing request options.
- Handling API responses efficiently.
This file contains all the API endpoints grouped by their respective functionalities. The APIs are categorized into different sections for clarity.
Handles authentication-related requests, such as:
await api.auth.sendOtp(email);
await api.auth.verifyOtp(data);
await api.auth.userDetails();Manages KYC verification status.
await api.kyc.userStatus();Handles wallet-related functionalities, including:
await api.wallet.getWallets();
await api.wallet.getBalances();
await api.wallet.setDefaultWallet(walletId);
await api.wallet.getDefaultWallet();Manages notification-related requests.
await api.notification.pusherAuth(data);Handles money transfers and transactions, including:
await api.transfer.transferListing();
await api.transfer.emailTransfer(data);
await api.transfer.walletTransfer(data);
await api.transfer.bankWithdrawal(data);
await api.transfer.bulkTransfers(data);The Telegram bot uses the Telegraf library to handle commands. Each command corresponds to a specific functionality and is defined in the src/bot/commands folder. These commands interact with APIs to fetch data, perform transactions, and manage user authentication.
- Initializes the bot and provides a welcome message.
- Defined in
StartCommand.
- Authenticates the user and retrieves access tokens.
- Defined in
LoginCommand.
- Retrieves and displays user information.
- Defined in
UserDetailsCommand.
- Fetches the user’s KYC verification status.
- Defined in
UserKycCommand.
- Allows users to set a preferred wallet for transactions.
- Defined in
SetDefaultWalletCommand.
- Displays the balance of the user's wallets.
- Defined in
GetBalancesCommand.
- Fetches and displays the user’s default wallet.
- Defined in
GetDefaultWalletCommand.
- Retrieves and displays all available wallets.
- Defined in
GetWalletCommand.
- Displays the history of money transfers.
- Defined in
TransferListCommand.
- Sends money to a recipient using an email transfer.
- Defined in
EmailTransferCommand.
- Transfers funds between the user’s wallets.
- Defined in
WalletTransferCommand.
- Processes multiple transfers in one command.
- Defined in
BulkTransfersCommand.
- Initiates a bank withdrawal.
- Defined in
BankWithdrawalCommand.
- Provides an overview of available commands and their usage.
- Defined in
HelpCommand.
The bot uses middleware for logging and authentication:
LoggerMiddleware: Logs incoming requests and responses.AuthMiddleware: Ensures users are authenticated before executing commands.
The bot uses Pusher to listen for real-time events, and the Pusher client is initialized within the bot.
For debugging purposes, the project uses the winston logging library. Logs are recorded both in the console and in a file specified in the configuration.
The logger is defined in src/lib/logger.ts:
import winston from 'winston';
import { CONFIG } from '../../config';
function createLogger(logFileName: string): winston.Logger {
return winston.createLogger({
level: 'info',
format: winston.format.combine(
winston.format.timestamp(),
winston.format.printf(({ timestamp, level, message }) => {
return `[${timestamp}] ${level}: ${message}`;
}),
),
transports: [
new winston.transports.Console(),
new winston.transports.File({ filename: logFileName }),
],
});
}
export const logger = createLogger(CONFIG.log.output);Logs follow the structure:
[timestamp] level: message
Example log entries:
[2025-03-21 18:42:26] info: User [@telegram_username] (telegram_user_id): Command received: /start
[2025-03-21 18:42:27] info: User [@telegram_username] (telegram_user_id): Command received: /kyc