import requests from telegram.ext import Updater, CommandHandler, MessageHandler, Filters # Replace with your actual Telegram bot token TELEGRAM_BOT_TOKEN = "YOUR_TELEGRAM_BOT_TOKEN" def get_balance(wallet_address): try: # Send a request to the Nimble API to fetch the balance response = requests.post('https://nimble-api.urlrevealer.com/check_balance', json={'address': wallet_address}) if response.status_code == 200: data = response.json() return data['msg'] else: return f"Error: Unable to fetch balance (status code: {response.status_code})" except Exception as e: return f"An error occurred: {str(e)}" def start(update, context): update.message.reply_text('Welcome to the Nimble Wallet Balance Checker Bot! Please send me your Nimble address to check the balance.') # Store the chat ID for later use (optional) context.user_data['chat_id'] = update.message.chat_id def handle_address(update, context): wallet_address = update.message.text.strip() if wallet_address: balance = get_balance(wallet_address) chat_id = context.user_data.get('chat_id') # Retrieve stored chat ID (optional) if chat_id: # Send balance information to the saved chat ID context.bot.send_message(chat_id, f"Balance for address {wallet_address}: {balance}") else: # Send balance information to the current chat (if chat ID not stored) update.message.reply_text(f"Balance for address {wallet_address}: {balance}") else: update.message.reply_text("Invalid wallet address. Please try again.") def main(): updater = Updater(TELEGRAM_BOT_TOKEN) dispatcher = updater.dispatcher # Register handlers dispatcher.add_handler(CommandHandler("start", start)) dispatcher.add_handler(MessageHandler(Filters.text & ~Filters.command, handle_address)) updater.start_polling() updater.idle() if __name__ == '__main__': main()