Telegram Bot script Shop Shop Bot
30-07-2024, 01:53
The bot has 3 ready-made payment systems (CRYSTAL PAY (crypta), CRYPTOBOT (P2P crypta), PAYOK (cards, e-wallets, SIM cards, crypta)), the addition of new ones is negotiated separately.
User functionality
Buying TRX
TRX Calculator
Administrator functionality
Access to the admin panel
Transaction confirmation
Cancellation of the transaction
Admin panel functionality
2 types of mailings
Changing the balance
Course change
Downloading the database
Downloading logs
Change min. and max. transaction amounts
Addendum/Deleting an Administrator
Statistics
The final script of the Telegram bot that provides the TRX exchange service could look like this:
import telegram
from telegram import InlineKeyboardButton, InlineKeyboardMarkup
from telegram.ext import Updater, CommandHandler, CallbackQueryHandler
import requests
from decimal import Decimal
def start(update, context):
"""Handler for the /start."""
update.message.reply_text('Hi! I am a bot of the TRX exchanger. Type /help to get a list of available commands.')
def help(update, context):
"""Handler for the /help."""
update.message.reply_text('/exchange - start the TRX exchange process.')
def exchange(update, context):
"""Handler for the /exchange command."""
update.message.reply_text('Enter the amount of TRX you want to exchange.')
def trx_to_usd(trx_value):
"""Convert TRX to USD using the CoinMarketCap API."""
response = requests.get('https://pro-api.coinmarketcap.com/v1/cryptocurrency/quotes/latest ',
headers={'X-CMC_PRO_API_KEY': 'YOUR_API_KEY'},
params={'symbol': 'TRX'})
response_data = response.json()
trx_price_usd = response_data['data']['TRX']['quote']['USD']['price']
return trx_value * trx_price_usd
def handle_inline_callback(update, context):
"""Handler for inline currency selection buttons."""
query = update.callback_query
data = query.data
amount_trx = Decimal(data.split('_')[0])
target_currency = data.split('_')[1]
if target_currency == 'USD':
result = trx_to_usd(amount_trx)
query.answer(text=f'{amount_trx} TRX = ${result:.2f}')
else:
query.answer(text=f'The exchange of {amount_trx} TRX in {target_currency} is currently unavailable.')
def check_input(update, context):
"""Checking user input and creating inline buttons for currency selection."""
trx_amount = Decimal(update.message.text)
usd_amount = trx_to_usd(trx_amount)
message =f'{trx_amount} TRX equals {usd_amount:.2f} USD. Choose which currency you want to exchange your TRX into.'
keyboard = [[InlineKeyboardButton("USD", callback_data=f'{trx_amount}_USD')],
[InlineKeyboardButton("EUR", callback_data=f'{trx_amount}_EUR')],
[InlineKeyboardButton("RUB", callback_data=f'{trx_amount}_RUB')],
[InlineKeyboardButton("BTC", callback_data=f'{trx_amount}_BTC')],
[InlineKeyboardButton("ETH", callback_data=f'{trx_amount}_ETH')]]
reply_markup = InlineKeyboardMarkup(keyboard)
update.message.reply_text(message, reply_markup=reply_markup)
def main():
"""Initializing the bot and launching."""
# Initializing the bot with a token.
updater = Updater(token='YOUR_TOKEN', use_context=True)
# Initializing the dispatcher.
dispatcher = updater.dispatcher
# Team handlers.
dispatcher.add_handler(CommandHandler('start', start))
dispatcher.add_handler(CommandHandler('help', help))
dispatcher.add_handler(CommandHandler('exchange', exchange))
# User input handlers.
dispatcher.add_handler(CallbackQueryHandler(handle_inline_callback))
dispatcher.add_handler(MessageHandler(Filters.text & ~Filters.command, check_input))
# Launch the bot.
updater.start_polling()
updater.idle()
if __name__ == '__main__':
main()
This script is responsible for the operation of the TRX exchanger bot. When receiving the /start command, the bot greets the user and informs about the available commands. When receiving the /exchange command, the bot requests the number of TRX to exchange. After receiving the user input, the bot checks it and provides the user with inline buttons to select the exchange currency. When the user selects a currency, the bot converts the amount of TRX into the selected currency and sends the result to the user. To convert TRX to USD, the CoinMarketCap API is used. However, you must register your API key and use it in the code replacing YOUR_API_KEY. Also, you must register the bot in Telegram and replace YOUR_TOKEN in the corresponding line of code.
30-07-2024, 01:53
30-07-2024, 00:36
31-07-2024, 03:18
There are no comments
Information
Users of Visitor are not allowed to comment this publication.